@Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { st.setObject( name, value, jdbcTypeCode ); } };
@Override public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException { try { stmt.setObject(parameterName, x, targetSqlType, scale); } catch (Throwable t) { throw checkException(t); } }
@Override public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException { try { stmt.setObject(parameterName, x, targetSqlType); } catch (Throwable t) { throw checkException(t); } }
@Override public void setObject(String parameterName, Object x) throws SQLException { try { stmt.setObject(parameterName, x); } catch (Throwable t) { throw checkException(t); } }
@Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { final PGobject obj = toPGobject( value, options ); st.setObject( name, obj ); }
@Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { st.setObject( name, javaTypeDescriptor.unwrap( value, UUID.class, options ), getSqlType() ); } };
@Override public void callableStatement_setObject(CallableStatementProxy statement, String parameterName, Object x, int targetSqlType, int scale) throws SQLException { if (this.pos < filterSize) { nextFilter().callableStatement_setObject(this, statement, parameterName, x, targetSqlType, scale); return; } statement.getRawObject().setObject(parameterName, x, targetSqlType, scale); }
@Override public void callableStatement_setObject(CallableStatementProxy statement, String parameterName, Object x, int targetSqlType) throws SQLException { if (this.pos < filterSize) { nextFilter().callableStatement_setObject(this, statement, parameterName, x, targetSqlType); return; } statement.getRawObject().setObject(parameterName, x, targetSqlType); }
@Override public void callableStatement_setObject(CallableStatementProxy statement, String parameterName, Object x) throws SQLException { if (this.pos < filterSize) { nextFilter().callableStatement_setObject(this, statement, parameterName, x); return; } statement.getRawObject().setObject(parameterName, x); }
private void verifyAddInvoiceWithoutMetaData(boolean isFunction) throws SQLException { if (isFunction) { verify(callableStatement).registerOutParameter(1, 4); verify(callableStatement).setObject(2, 1103, 4); verify(callableStatement).setObject(3, 3, 4); } else { verify(callableStatement).setObject(1, 1103, 4); verify(callableStatement).setObject(2, 3, 4); verify(callableStatement).registerOutParameter(3, 4); } verify(callableStatement).close(); }
@Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { final Geometry geometry = getJavaDescriptor().unwrap( value, Geometry.class, options ); final byte[] bytes = Encoders.encode( geometry ); st.setObject( name, bytes ); }
@Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { final Point<?> geometry = getJavaDescriptor().unwrap( value, Point.class, options ); st.setObject( name, HANASpatialUtils.toEWKB( geometry ) ); }
@Override public void bind( CallableStatement st, J value, String name, WrapperOptions options) throws SQLException { if ( value == null ) { st.setNull( name, Types.STRUCT, SQL_TYPE_NAME ); } else { final Geometry geometry = javaTypeDescriptor.unwrap( value, Geometry.class, options ); final Object dbGeom = toNative( geometry, st.getConnection() ); st.setObject( name, dbGeom ); } }
private void verifyAddInvoiceWithMetaData(boolean isFunction) throws SQLException { ResultSet proceduresResultSet = databaseMetaData.getProcedures("", "ME", "ADD_INVOICE"); ResultSet procedureColumnsResultSet = databaseMetaData.getProcedureColumns("", "ME", "ADD_INVOICE", null); if (isFunction) { verify(callableStatement).registerOutParameter(1, 4); verify(callableStatement).setObject(2, 1103, 4); verify(callableStatement).setObject(3, 3, 4); } else { verify(callableStatement).setObject(1, 1103, 4); verify(callableStatement).setObject(2, 3, 4); verify(callableStatement).registerOutParameter(3, 4); } verify(callableStatement).close(); verify(proceduresResultSet).close(); verify(procedureColumnsResultSet).close(); }
@Test public void testAddInvoices() throws Exception { given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getObject(3)).willReturn(4); given(connection.prepareCall("{call " + AddInvoice.SQL + "(?, ?, ?)}") ).willReturn(callableStatement); testAddInvoice(1106, 3); verify(callableStatement).setObject(1, 1106, Types.INTEGER); verify(callableStatement).setObject(2, 3, Types.INTEGER); verify(callableStatement).registerOutParameter(3, Types.INTEGER); }
@Test public void testAddInvoicesUsingObjectArray() throws Exception { given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getObject(3)).willReturn(5); given(connection.prepareCall("{call " + AddInvoice.SQL + "(?, ?, ?)}") ).willReturn(callableStatement); testAddInvoiceUsingObjectArray(1106, 4); verify(callableStatement).setObject(1, 1106, Types.INTEGER); verify(callableStatement).setObject(2, 4, Types.INTEGER); verify(callableStatement).registerOutParameter(3, Types.INTEGER); }
@Test public void testAddInvoicesWithinTransaction() throws Exception { given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getObject(3)).willReturn(4); given(connection.prepareCall("{call " + AddInvoice.SQL + "(?, ?, ?)}") ).willReturn(callableStatement); TransactionSynchronizationManager.bindResource(dataSource, new ConnectionHolder(connection)); try { testAddInvoice(1106, 3); verify(callableStatement).setObject(1, 1106, Types.INTEGER); verify(callableStatement).setObject(2, 3, Types.INTEGER); verify(callableStatement).registerOutParameter(3, Types.INTEGER); verify(connection, never()).close(); } finally { TransactionSynchronizationManager.unbindResource(dataSource); connection.close(); } }
@Test public void testSqlTypeValue() throws Exception { int[] testVal = new int[] { 1, 2 }; given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getObject(2)).willReturn("OK"); given(connection.prepareCall("{call " + SqlTypeValueStoredProcedure.SQL + "(?, ?)}") ).willReturn(callableStatement); SqlTypeValueStoredProcedure stvsp = new SqlTypeValueStoredProcedure(dataSource); Map<String, Object> out = stvsp.executeTest(testVal); assertEquals("OK", out.get("out")); verify(callableStatement).setObject(1, testVal, Types.ARRAY); verify(callableStatement).registerOutParameter(2, Types.VARCHAR); }
@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(); }
/** * Confirm our JdbcTemplate is used * * @throws Exception */ @Test public void testStoredProcedureConfiguredViaJdbcTemplate() throws Exception { given(callableStatement.execute()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getObject(2)).willReturn(4); given(connection.prepareCall("{call " + StoredProcedureConfiguredViaJdbcTemplate.SQL + "(?, ?)}") ).willReturn(callableStatement); JdbcTemplate t = new JdbcTemplate(); t.setDataSource(dataSource); StoredProcedureConfiguredViaJdbcTemplate sp = new StoredProcedureConfiguredViaJdbcTemplate(t); assertEquals(4, sp.execute(1106)); verify(callableStatement).setObject(1, 1106, Types.INTEGER); verify(callableStatement).registerOutParameter(2, Types.INTEGER); }