private void callInsert(String tokenKey, List<SqlParameter> paramList, byte[] compressedBytes, String procedureSecurestoreInsert) { jdbcTemplate.call(new CallableStatementCreator() { @Override public CallableStatement createCallableStatement(Connection connection) throws SQLException { CallableStatement callableStatement = connection.prepareCall(procedureSecurestoreInsert); callableStatement.setString(1, OAUTH_ACCESS_TOKEN_STORE); callableStatement.setBoolean(2, FOR_XS_APPLICATIONUSER); callableStatement.setString(3, tokenKey); callableStatement.setBytes(4, compressedBytes); return callableStatement; } }, paramList); }
private Map<String, Object> callRetrieve(String tokenKey, List<SqlParameter> paramList, final String procedureSecurestoreRetrieve) { Map<String, Object> result = jdbcTemplate.call(new CallableStatementCreator() { @Override public CallableStatement createCallableStatement(Connection connection) throws SQLException { CallableStatement callableStatement = connection.prepareCall(procedureSecurestoreRetrieve); callableStatement.setString(1, OAUTH_ACCESS_TOKEN_STORE); callableStatement.setBoolean(2, FOR_XS_APPLICATIONUSER); callableStatement.setString(3, tokenKey); callableStatement.registerOutParameter(4, Types.VARBINARY); return callableStatement; } }, paramList); return result; }
@Override public int[] executeBatch() throws SQLException { if (this.batchItems == null) { throw new IllegalArgumentException("Batch must have at least one item"); } final Iterator<Map<String, ?>> params = batchItems.iterator(); return factory.getJdbcTemplate().execute(new CallableStatementCreator() { @Override public CallableStatement createCallableStatement(Connection connection) throws SQLException { return batchFactory.newCallableStatementCreator(params.next()).createCallableStatement(connection); } }, new CallableStatementCallback<int[]>() { @Override public int[] doInCallableStatement(CallableStatement callableStatement) throws SQLException, DataAccessException { //add first item to batch callableStatement.addBatch(); while (params.hasNext()) { batchFactory.addParameter(callableStatement, params.next()); callableStatement.addBatch(); } return callableStatement.executeBatch(); } }); }
/** * Method to perform the actual call processing */ private Map<String, Object> executeCallInternal(Map<String, ?> params) { CallableStatementCreator csc = getCallableStatementFactory().newCallableStatementCreator(params); if (logger.isDebugEnabled()) { logger.debug("The following parameters are used for call " + getCallString() + " with: " + params); int i = 1; for (SqlParameter p : getCallParameters()) { logger.debug(i++ + ": " + p.getName() + " SQL Type "+ p.getSqlType() + " Type Name " + p.getTypeName() + " " + p.getClass().getName()); } } return getJdbcTemplate().call(csc, getCallParameters()); }
/** * Confirm no connection was used to get metadata. Does not use superclass replay * mechanism. * * @throws Exception */ @Test public void testStoredProcedureConfiguredViaJdbcTemplateWithCustomExceptionTranslator() throws Exception { given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getObject(2)).willReturn(5); given(connection.prepareCall("{call " + StoredProcedureConfiguredViaJdbcTemplate.SQL + "(?, ?)}") ).willReturn(callableStatement); class TestJdbcTemplate extends JdbcTemplate { int calls; @Override public Map<String, Object> call(CallableStatementCreator csc, List<SqlParameter> declaredParameters) throws DataAccessException { calls++; return super.call(csc, declaredParameters); } } TestJdbcTemplate t = new TestJdbcTemplate(); t.setDataSource(dataSource); // Will fail without the following, because we're not able to get a connection // from the DataSource here if we need to to create an ExceptionTranslator t.setExceptionTranslator(new SQLStateSQLExceptionTranslator()); StoredProcedureConfiguredViaJdbcTemplate sp = new StoredProcedureConfiguredViaJdbcTemplate(t); assertEquals(sp.execute(11), 5); assertEquals(1, t.calls); verify(callableStatement).setObject(1, 11, Types.INTEGER); verify(callableStatement).registerOutParameter(2, Types.INTEGER); }
public <T> T execute(CallableStatementCreator csc, CallableStatementCallback<T> action) throws DataAccessException { return delegate.execute(csc, action); }
public Map<String, Object> call(CallableStatementCreator csc, List<SqlParameter> declaredParameters) throws DataAccessException { return delegate.call(csc, declaredParameters); }
private void callRemove(String tokenKey, List<SqlParameter> paramList, String procedureSecurestoreDelete) { jdbcTemplate.call(new CallableStatementCreator() { @Override public CallableStatement createCallableStatement(Connection connection) throws SQLException { CallableStatement callableStatement = connection.prepareCall(procedureSecurestoreDelete); callableStatement.setString(1, OAUTH_ACCESS_TOKEN_STORE); callableStatement.setBoolean(2, FOR_XS_APPLICATIONUSER); callableStatement.setString(3, tokenKey); return callableStatement; } }, paramList); }
/** * Delegate method to perform the actual call processing. */ private Map<String, Object> executeCallInternal(Map<String, ?> args) { CallableStatementCreator csc = getCallableStatementFactory().newCallableStatementCreator(args); if (logger.isDebugEnabled()) { logger.debug("The following parameters are used for call " + getCallString() + " with " + args); int i = 1; for (SqlParameter param : getCallParameters()) { logger.debug(i + ": " + param.getName() + ", SQL type "+ param.getSqlType() + ", type name " + param.getTypeName() + ", parameter class [" + param.getClass().getName() + "]"); i++; } } return getJdbcTemplate().call(csc, getCallParameters()); }
public CallableStatementCreator newCallableStatementCreator(Map<String, ?> params) { return this.callableStatementCreatorFactory.newCallableStatementCreator(params); }
@Override public <T> T execute(CallableStatementCreator csc, CallableStatementCallback<T> action) throws DataAccessException { return super.execute(csc, action); }
@Override public Map<String, Object> call(CallableStatementCreator csc, List<SqlParameter> declaredParameters) throws DataAccessException { return super.call(csc, declaredParameters); }
/** * Return a CallableStatementCreator to perform an operation * with this parameters. * @param inParams parameters. May be {@code null}. */ protected CallableStatementCreator newCallableStatementCreator(Map<String, ?> inParams) { return this.callableStatementFactory.newCallableStatementCreator(inParams); }
/** * Return a CallableStatementCreator to perform an operation * with the parameters returned from this ParameterMapper. * @param inParamMapper parametermapper. May not be {@code null}. */ protected CallableStatementCreator newCallableStatementCreator(ParameterMapper inParamMapper) { return this.callableStatementFactory.newCallableStatementCreator(inParamMapper); }