Search in sources :

Example 1 with CallableStatementCreator

use of org.springframework.jdbc.core.CallableStatementCreator in project spring-framework by spring-projects.

the class AbstractJdbcCall method executeCallInternal.

/**
	 * 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());
}
Also used : CallableStatementCreator(org.springframework.jdbc.core.CallableStatementCreator) SqlParameter(org.springframework.jdbc.core.SqlParameter)

Example 2 with CallableStatementCreator

use of org.springframework.jdbc.core.CallableStatementCreator in project spring-framework by spring-projects.

the class StoredProcedureTests method testStoredProcedureConfiguredViaJdbcTemplateWithCustomExceptionTranslator.

/**
	 * 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 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);
}
Also used : CallableStatementCreator(org.springframework.jdbc.core.CallableStatementCreator) List(java.util.List) SQLStateSQLExceptionTranslator(org.springframework.jdbc.support.SQLStateSQLExceptionTranslator) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.Test)

Aggregations

CallableStatementCreator (org.springframework.jdbc.core.CallableStatementCreator)2 List (java.util.List)1 Test (org.junit.Test)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1 SqlParameter (org.springframework.jdbc.core.SqlParameter)1 SQLStateSQLExceptionTranslator (org.springframework.jdbc.support.SQLStateSQLExceptionTranslator)1