/** * 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()); }
/** * Create a new object wrapper for a stored procedure. * @param ds the DataSource to use throughout the lifetime * of this object to obtain connections * @param name name of the stored procedure in the database */ protected StoredProcedure(DataSource ds, String name) { setDataSource(ds); setSql(name); }
/** * Create a new object wrapper for a stored procedure. * @param jdbcTemplate the JdbcTemplate which wraps DataSource * @param name name of the stored procedure in the database */ protected StoredProcedure(JdbcTemplate jdbcTemplate, String name) { setJdbcTemplate(jdbcTemplate); setSql(name); }
/** * 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()); }
@Test public void testAddInvoices() throws Exception { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions( new ClassPathResource("org/springframework/jdbc/object/GenericStoredProcedureTests-context.xml")); Connection connection = mock(Connection.class); DataSource dataSource = mock(DataSource.class); given(dataSource.getConnection()).willReturn(connection); CallableStatement callableStatement = mock(CallableStatement.class); TestDataSourceWrapper testDataSource = (TestDataSourceWrapper) bf.getBean("dataSource"); testDataSource.setTarget(dataSource); given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getObject(3)).willReturn(4); given(connection.prepareCall("{call " + "add_invoice" + "(?, ?, ?)}")).willReturn(callableStatement); StoredProcedure adder = (StoredProcedure) bf.getBean("genericProcedure"); Map<String, Object> in = new HashMap<>(2); in.put("amount", 1106); in.put("custid", 3); Map<String, Object> out = adder.execute(in); Integer id = (Integer) out.get("newid"); assertEquals(4, id.intValue()); verify(callableStatement).setObject(1, 1106, Types.INTEGER); verify(callableStatement).setObject(2, 3, Types.INTEGER); verify(callableStatement).registerOutParameter(3, Types.INTEGER); verify(callableStatement).close(); }
/** * 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()); }
public String executeQuery(int orderId){ Map<String,Object> results = super.execute(orderId); return (String) results.get(PARAM_DESCRIPTION); } }
/** * 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()); }
/** * 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()); }
/** * Create a new object wrapper for a stored procedure. * @param ds DataSource to use throughout the lifetime * of this object to obtain connections * @param name name of the stored procedure in the database */ protected StoredProcedure(DataSource ds, String name) { setDataSource(ds); setSql(name); }
/** * Create a new object wrapper for a stored procedure. * @param jdbcTemplate JdbcTemplate which wraps DataSource * @param name name of the stored procedure in the database */ protected StoredProcedure(JdbcTemplate jdbcTemplate, String name) { setJdbcTemplate(jdbcTemplate); setSql(name); }
public Map execute(Exchange exchange, Object rowData) { Map<String, Object> params = new HashMap<>(); for (InParameter inParameter : inParameterList) { params.put(inParameter.getName(), inParameter.getValueExtractor().eval(exchange, rowData)); } for (InOutParameter inOutParameter : inOutParameterList) { params.put(inOutParameter.getOutValueMapKey(), inOutParameter.getValueExtractor().eval(exchange, rowData)); } LOG.debug("Invoking stored procedure: {}", template.getProcedureName()); return super.execute(params); }
/** * 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()); }
/** * 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()); }
/** * Create a new object wrapper for a stored procedure. * @param ds the DataSource to use throughout the lifetime * of this object to obtain connections * @param name name of the stored procedure in the database */ protected StoredProcedure(DataSource ds, String name) { setDataSource(ds); setSql(name); }
/** * Create a new object wrapper for a stored procedure. * @param jdbcTemplate the JdbcTemplate which wraps DataSource * @param name name of the stored procedure in the database */ protected StoredProcedure(JdbcTemplate jdbcTemplate, String name) { setJdbcTemplate(jdbcTemplate); setSql(name); }
/** * 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()); }