Search in sources :

Example 1 with SqlInOutParameter

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

the class CallMetaDataContextTests method testMatchParameterValuesAndSqlInOutParameters.

@Test
public void testMatchParameterValuesAndSqlInOutParameters() throws Exception {
    final String TABLE = "customers";
    final String USER = "me";
    given(databaseMetaData.getDatabaseProductName()).willReturn("MyDB");
    given(databaseMetaData.getUserName()).willReturn(USER);
    given(databaseMetaData.storesLowerCaseIdentifiers()).willReturn(true);
    List<SqlParameter> parameters = new ArrayList<>();
    parameters.add(new SqlParameter("id", Types.NUMERIC));
    parameters.add(new SqlInOutParameter("name", Types.NUMERIC));
    parameters.add(new SqlOutParameter("customer_no", Types.NUMERIC));
    MapSqlParameterSource parameterSource = new MapSqlParameterSource();
    parameterSource.addValue("id", 1);
    parameterSource.addValue("name", "Sven");
    parameterSource.addValue("customer_no", "12345XYZ");
    context.setProcedureName(TABLE);
    context.initializeMetaData(dataSource);
    context.processParameters(parameters);
    Map<String, Object> inParameters = context.matchInParameterValuesWithCallParameters(parameterSource);
    assertEquals("Wrong number of matched in parameter values", 2, inParameters.size());
    assertTrue("in parameter value missing", inParameters.containsKey("id"));
    assertTrue("in out parameter value missing", inParameters.containsKey("name"));
    assertTrue("out parameter value matched", !inParameters.containsKey("customer_no"));
    List<String> names = context.getOutParameterNames();
    assertEquals("Wrong number of out parameters", 2, names.size());
    List<SqlParameter> callParameters = context.getCallParameters();
    assertEquals("Wrong number of call parameters", 3, callParameters.size());
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ArrayList(java.util.ArrayList) SqlOutParameter(org.springframework.jdbc.core.SqlOutParameter) SqlInOutParameter(org.springframework.jdbc.core.SqlInOutParameter) Test(org.junit.Test)

Example 2 with SqlInOutParameter

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

the class RdbmsOperationTests method validateInOutParameter.

@Test
public void validateInOutParameter() {
    operation.setDataSource(new DriverManagerDataSource());
    operation.setSql("DUMMY_PROC");
    operation.declareParameter(new SqlOutParameter("DUMMY_OUT_PARAM", Types.VARCHAR));
    operation.declareParameter(new SqlInOutParameter("DUMMY_IN_OUT_PARAM", Types.VARCHAR));
    operation.validateParameters(new Object[] { "DUMMY_VALUE1", "DUMMY_VALUE2" });
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) SqlOutParameter(org.springframework.jdbc.core.SqlOutParameter) SqlInOutParameter(org.springframework.jdbc.core.SqlInOutParameter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 SqlInOutParameter (org.springframework.jdbc.core.SqlInOutParameter)2 SqlOutParameter (org.springframework.jdbc.core.SqlOutParameter)2 ArrayList (java.util.ArrayList)1 SqlParameter (org.springframework.jdbc.core.SqlParameter)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)1