@Test public void testAddInvoiceProcWithoutMetaDataUsingArrayParams() throws Exception { initializeAddInvoiceWithoutMetaData(false); SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withProcedureName("add_invoice"); adder.declareParameters( new SqlParameter("amount", Types.INTEGER), new SqlParameter("custid", Types.INTEGER), new SqlOutParameter("newid", Types.INTEGER)); Number newId = adder.executeObject(Number.class, 1103, 3); assertEquals(4, newId.intValue()); verifyAddInvoiceWithoutMetaData(false); verify(connection, atLeastOnce()).close(); }
@Test public void testAddInvoiceFuncWithoutMetaDataUsingArrayParams() throws Exception { initializeAddInvoiceWithoutMetaData(true); SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withFunctionName("add_invoice"); adder.declareParameters( new SqlOutParameter("return", Types.INTEGER), new SqlParameter("amount", Types.INTEGER), new SqlParameter("custid", Types.INTEGER)); Number newId = adder.executeFunction(Number.class, 1103, 3); assertEquals(4, newId.intValue()); verifyAddInvoiceWithoutMetaData(true); verify(connection, atLeastOnce()).close(); }
@Test public void testAddInvoiceProcWithoutMetaDataUsingMapParamSource() throws Exception { initializeAddInvoiceWithoutMetaData(false); SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withProcedureName("add_invoice"); adder.declareParameters( new SqlParameter("amount", Types.INTEGER), new SqlParameter("custid", Types.INTEGER), new SqlOutParameter("newid", Types.INTEGER)); Number newId = adder.executeObject(Number.class, new MapSqlParameterSource(). addValue("amount", 1103). addValue("custid", 3)); assertEquals(4, newId.intValue()); verifyAddInvoiceWithoutMetaData(false); verify(connection, atLeastOnce()).close(); }
@Test public void testAddInvoiceFuncWithoutMetaDataUsingMapParamSource() throws Exception { initializeAddInvoiceWithoutMetaData(true); SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withFunctionName("add_invoice"); adder.declareParameters( new SqlOutParameter("return", Types.INTEGER), new SqlParameter("amount", Types.INTEGER), new SqlParameter("custid", Types.INTEGER)); Number newId = adder.executeFunction(Number.class, new MapSqlParameterSource() .addValue("amount", 1103) .addValue("custid", 3)); assertEquals(4, newId.intValue()); verifyAddInvoiceWithoutMetaData(true); verify(connection, atLeastOnce()).close(); }
private SimpleJdbcCall createSimpleJdbcCall(String storedProcedureName) { final SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(this.dataSource); if (this.isFunction) { simpleJdbcCall.withFunctionName(storedProcedureName); } else { simpleJdbcCall.withProcedureName(storedProcedureName); } if (this.ignoreColumnMetaData) { simpleJdbcCall.withoutProcedureColumnMetaDataAccess(); } simpleJdbcCall.declareParameters(this.sqlParameters.toArray(new SqlParameter[this.sqlParameters.size()])); if (!this.returningResultSetRowMappers.isEmpty()) { for (Entry<String, RowMapper<?>> mapEntry : this.returningResultSetRowMappers.entrySet()) { simpleJdbcCall.returningResultSet(mapEntry.getKey(), mapEntry.getValue()); } } if (this.returnValueRequired) { simpleJdbcCall.withReturnValue(); } simpleJdbcCall.getJdbcTemplate().setSkipUndeclaredResults(this.skipUndeclaredResults); return simpleJdbcCall; }
SimpleJdbcCall call = Util.getSimpleJdbcCallInstance(); call.setProcedureName("PROCED_CONDOMINIAL"); call.declareParameters( new SqlParameter("CONDOMINIO", Types.VARCHAR), new SqlParameter("BLOCO", Types.VARCHAR),, new SqlOutParameter("P_NUMERO", Types.NUMERIC), new SqlOutParameter("P_LOG", Types.VARCHAR)); Map<String, Object> parametros = new HashMap<String, Object>(); parametros.put("CONDOMINIO_IC", descricaoCondominio); parametros.put("BLOCO_IC", imovelCondominial.getBloco()); Map<String, Object> out = call.execute(parametros); BigDecimal chave = (BigDecimal) out.get("P_NUMERO"); imovelCondominial.setId(chave.longValue());
SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(dataSource); simpleJdbcCall.withCatalogName("dbo"); simpleJdbcCall.withProcedureName("procedureA "); simpleJdbcCall.setAccessCallParameterMetaData(false); simpleJdbcCall.declareParameters(new new SqlOutParameter("a",Types.NUMERIC)); simpleJdbcCall.execute();
private SimpleJdbcCall createSimpleJdbcCall(String storedProcedureName) { final SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(this.dataSource); if (this.isFunction) { simpleJdbcCall.withFunctionName(storedProcedureName); } else { simpleJdbcCall.withProcedureName(storedProcedureName); } if (this.ignoreColumnMetaData) { simpleJdbcCall.withoutProcedureColumnMetaDataAccess(); } simpleJdbcCall.declareParameters(this.sqlParameters.toArray(new SqlParameter[this.sqlParameters.size()])); if (!this.returningResultSetRowMappers.isEmpty()) { for (Entry<String, RowMapper<?>> mapEntry : this.returningResultSetRowMappers.entrySet()) { simpleJdbcCall.returningResultSet(mapEntry.getKey(), mapEntry.getValue()); } } if (this.returnValueRequired) { simpleJdbcCall.withReturnValue(); } simpleJdbcCall.getJdbcTemplate().setSkipUndeclaredResults(this.skipUndeclaredResults); return simpleJdbcCall; }