/** * Execute the stored procedure. Subclasses should define a strongly typed * execute method (with a meaningful name) that invokes this method, populating * the input map and extracting typed values from the output map. Subclass * execute methods will often take domain objects as arguments and return values. * Alternatively, they can return void. * @param inParams map of input parameters, keyed by name as in parameter * declarations. Output parameters need not (but can) be included in this map. * It is legal for map entries to be {@code null}, and this will produce the * correct behavior using a NULL argument to the stored procedure. * @return map of output params, keyed by name as in parameter declarations. * Output parameters will appear here, with their values after the * stored procedure has been called. */ public Map<String, Object> execute(Map<String, ?> inParams) throws DataAccessException { validateParameters(inParams.values().toArray()); return getJdbcTemplate().call(newCallableStatementCreator(inParams), getDeclaredParameters()); }
/** * 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()); }
/** * Execute the stored procedure. Subclasses should define a strongly typed * execute method (with a meaningful name) that invokes this method, passing in * a ParameterMapper that will populate the input map. This allows mapping database * specific features since the ParameterMapper has access to the Connection object. * The execute method is also responsible for extracting typed values from the output map. * Subclass execute methods will often take domain objects as arguments and return values. * Alternatively, they can return void. * @param inParamMapper map of input parameters, keyed by name as in parameter * declarations. Output parameters need not (but can) be included in this map. * It is legal for map entries to be {@code null}, and this will produce the correct * behavior using a NULL argument to the stored procedure. * @return map of output params, keyed by name as in parameter declarations. * Output parameters will appear here, with their values after the * stored procedure has been called. */ public Map<String, Object> execute(ParameterMapper inParamMapper) throws DataAccessException { checkCompiled(); return getJdbcTemplate().call(newCallableStatementCreator(inParamMapper), getDeclaredParameters()); }
/** * Execute the stored procedure with the provided parameter values. This is * a convenience method where the order of the passed in parameter values * must match the order that the parameters where declared in. * @param inParams variable number of input parameters. Output parameters should * not be included in this map. It is legal for values to be {@code null}, and this * will produce the correct behavior using a NULL argument to the stored procedure. * @return map of output params, keyed by name as in parameter declarations. * Output parameters will appear here, with their values after the stored procedure * has been called. */ public Map<String, Object> execute(Object... inParams) { Map<String, Object> paramsToUse = new HashMap<>(); validateParameters(inParams); int i = 0; for (SqlParameter sqlParameter : getDeclaredParameters()) { if (sqlParameter.isInputValueProvided() && i < inParams.length) { paramsToUse.put(sqlParameter.getName(), inParams[i++]); } } return getJdbcTemplate().call(newCallableStatementCreator(paramsToUse), getDeclaredParameters()); }
@Test public void testCaseInsensitiveResultsMap() throws Exception { given(this.callableStatement.execute()).willReturn(false); given(this.callableStatement.getUpdateCount()).willReturn(-1); given(this.callableStatement.getObject(1)).willReturn("X"); assertTrue("default should have been NOT case insensitive", !this.template.isResultsMapCaseInsensitive()); this.template.setResultsMapCaseInsensitive(true); assertTrue("now it should have been set to case insensitive", this.template.isResultsMapCaseInsensitive()); Map<String, Object> out = this.template.call( conn -> conn.prepareCall("my query"), Collections.singletonList(new SqlOutParameter("a", 12))); assertThat(out, instanceOf(LinkedCaseInsensitiveMap.class)); assertNotNull("we should have gotten the result with upper case", out.get("A")); assertNotNull("we should have gotten the result with lower case", out.get("a")); verify(this.callableStatement).close(); verify(this.connection).close(); }
@Test public void testExecuteClosed() throws Exception { given(this.resultSet.next()).willReturn(true); given(this.callableStatement.execute()).willReturn(true); given(this.callableStatement.getUpdateCount()).willReturn(-1); SqlParameter param = new SqlReturnResultSet("", (RowCallbackHandler) rs -> { throw new InvalidDataAccessApiUsageException(""); }); this.thrown.expect(InvalidDataAccessApiUsageException.class); try { this.template.call(conn -> conn.prepareCall("my query"), Collections.singletonList(param)); } finally { verify(this.resultSet).close(); verify(this.callableStatement).close(); verify(this.connection).close(); } }
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); }
public Map<String, Object> call(CallableStatementCreator csc, List<SqlParameter> declaredParameters) throws DataAccessException { return delegate.call(csc, declaredParameters); }
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) { return 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); }
/** * Performs post-change database updates. */ public void complete() { dbCtx.getJdbcTemplate().call( new CallableStatementCreator() { @Override public CallableStatement createCallableStatement(Connection con) throws SQLException { return con.prepareCall("{call osmosisUpdate()}"); } }, new ArrayList<SqlParameter>()); // Clear all action records. actionDao.truncate(); }
/** * Execute the stored procedure. Subclasses should define a strongly typed * execute method (with a meaningful name) that invokes this method, populating * the input map and extracting typed values from the output map. Subclass * execute methods will often take domain objects as arguments and return values. * Alternatively, they can return void. * @param inParams map of input parameters, keyed by name as in parameter * declarations. Output parameters need not (but can) be included in this map. * It is legal for map entries to be {@code null}, and this will produce the * correct behavior using a NULL argument to the stored procedure. * @return map of output params, keyed by name as in parameter declarations. * Output parameters will appear here, with their values after the * stored procedure has been called. */ public Map<String, Object> execute(Map<String, ?> inParams) throws DataAccessException { validateParameters(inParams.values().toArray()); return getJdbcTemplate().call(newCallableStatementCreator(inParams), getDeclaredParameters()); }
/** * 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()); }
/** * Execute the stored procedure. Subclasses should define a strongly typed * execute method (with a meaningful name) that invokes this method, populating * the input map and extracting typed values from the output map. Subclass * execute methods will often take domain objects as arguments and return values. * Alternatively, they can return void. * @param inParams map of input parameters, keyed by name as in parameter * declarations. Output parameters need not (but can) be included in this map. * It is legal for map entries to be {@code null}, and this will produce the * correct behavior using a NULL argument to the stored procedure. * @return map of output params, keyed by name as in parameter declarations. * Output parameters will appear here, with their values after the * stored procedure has been called. */ public Map<String, Object> execute(Map<String, ?> inParams) throws DataAccessException { validateParameters(inParams.values().toArray()); return getJdbcTemplate().call(newCallableStatementCreator(inParams), getDeclaredParameters()); }
/** * 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()); }
/** * Execute the stored procedure. Subclasses should define a strongly typed * execute method (with a meaningful name) that invokes this method, passing in * a ParameterMapper that will populate the input map. This allows mapping database * specific features since the ParameterMapper has access to the Connection object. * The execute method is also responsible for extracting typed values from the output map. * Subclass execute methods will often take domain objects as arguments and return values. * Alternatively, they can return void. * @param inParamMapper map of input parameters, keyed by name as in parameter * declarations. Output parameters need not (but can) be included in this map. * It is legal for map entries to be {@code null}, and this will produce the correct * behavior using a NULL argument to the stored procedure. * @return map of output params, keyed by name as in parameter declarations. * Output parameters will appear here, with their values after the * stored procedure has been called. */ public Map<String, Object> execute(ParameterMapper inParamMapper) throws DataAccessException { checkCompiled(); return getJdbcTemplate().call(newCallableStatementCreator(inParamMapper), getDeclaredParameters()); }
/** * Execute the stored procedure with the provided parameter values. This is * a convenience method where the order of the passed in parameter values * must match the order that the parameters where declared in. * @param inParams variable number of input parameters. Output parameters should * not be included in this map. It is legal for values to be {@code null}, and this * will produce the correct behavior using a NULL argument to the stored procedure. * @return map of output params, keyed by name as in parameter declarations. * Output parameters will appear here, with their values after the stored procedure * has been called. */ public Map<String, Object> execute(Object... inParams) { Map<String, Object> paramsToUse = new HashMap<>(); validateParameters(inParams); int i = 0; for (SqlParameter sqlParameter : getDeclaredParameters()) { if (sqlParameter.isInputValueProvided() && i < inParams.length) { paramsToUse.put(sqlParameter.getName(), inParams[i++]); } } return getJdbcTemplate().call(newCallableStatementCreator(paramsToUse), getDeclaredParameters()); }
/** * Execute the stored procedure with the provided parameter values. This is * a convenience method where the order of the passed in parameter values * must match the order that the parameters where declared in. * @param inParams variable number of input parameters. Output parameters should * not be included in this map. * It is legal for values to be {@code null}, and this will produce the * correct behavior using a NULL argument to the stored procedure. * @return map of output params, keyed by name as in parameter declarations. * Output parameters will appear here, with their values after the * stored procedure has been called. */ public Map<String, Object> execute(Object... inParams) { Map<String, Object> paramsToUse = new HashMap<String, Object>(); validateParameters(inParams); int i = 0; for (SqlParameter sqlParameter : getDeclaredParameters()) { if (sqlParameter.isInputValueProvided()) { if (i < inParams.length) { paramsToUse.put(sqlParameter.getName(), inParams[i++]); } } } return getJdbcTemplate().call(newCallableStatementCreator(paramsToUse), getDeclaredParameters()); }
/** * Execute the stored procedure. Subclasses should define a strongly typed * execute method (with a meaningful name) that invokes this method, passing in * a ParameterMapper that will populate the input map. This allows mapping database * specific features since the ParameterMapper has access to the Connection object. * The execute method is also responsible for extracting typed values from the output map. * Subclass execute methods will often take domain objects as arguments and return values. * Alternatively, they can return void. * @param inParamMapper map of input parameters, keyed by name as in parameter * declarations. Output parameters need not (but can) be included in this map. * It is legal for map entries to be {@code null}, and this will produce the correct * behavior using a NULL argument to the stored procedure. * @return map of output params, keyed by name as in parameter declarations. * Output parameters will appear here, with their values after the * stored procedure has been called. */ public Map<String, Object> execute(ParameterMapper inParamMapper) throws DataAccessException { checkCompiled(); return getJdbcTemplate().call(newCallableStatementCreator(inParamMapper), getDeclaredParameters()); }