Search in sources :

Example 1 with SqlInOutParameter

use of cn.taketoday.jdbc.core.SqlInOutParameter in project today-infrastructure by TAKETODAY.

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(cn.taketoday.jdbc.datasource.DriverManagerDataSource) SqlOutParameter(cn.taketoday.jdbc.core.SqlOutParameter) SqlInOutParameter(cn.taketoday.jdbc.core.SqlInOutParameter) Test(org.junit.jupiter.api.Test)

Example 2 with SqlInOutParameter

use of cn.taketoday.jdbc.core.SqlInOutParameter in project today-framework by TAKETODAY.

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);
    assertThat(inParameters.size()).as("Wrong number of matched in parameter values").isEqualTo(2);
    assertThat(inParameters.containsKey("id")).as("in parameter value missing").isTrue();
    assertThat(inParameters.containsKey("name")).as("in out parameter value missing").isTrue();
    boolean condition = !inParameters.containsKey("customer_no");
    assertThat(condition).as("out parameter value matched").isTrue();
    List<String> names = context.getOutParameterNames();
    assertThat(names.size()).as("Wrong number of out parameters").isEqualTo(2);
    List<SqlParameter> callParameters = context.getCallParameters();
    assertThat(callParameters.size()).as("Wrong number of call parameters").isEqualTo(3);
}
Also used : SqlParameter(cn.taketoday.jdbc.core.SqlParameter) MapSqlParameterSource(cn.taketoday.jdbc.core.namedparam.MapSqlParameterSource) ArrayList(java.util.ArrayList) SqlOutParameter(cn.taketoday.jdbc.core.SqlOutParameter) SqlInOutParameter(cn.taketoday.jdbc.core.SqlInOutParameter) Test(org.junit.jupiter.api.Test)

Example 3 with SqlInOutParameter

use of cn.taketoday.jdbc.core.SqlInOutParameter in project today-framework by TAKETODAY.

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(cn.taketoday.jdbc.datasource.DriverManagerDataSource) SqlOutParameter(cn.taketoday.jdbc.core.SqlOutParameter) SqlInOutParameter(cn.taketoday.jdbc.core.SqlInOutParameter) Test(org.junit.jupiter.api.Test)

Example 4 with SqlInOutParameter

use of cn.taketoday.jdbc.core.SqlInOutParameter in project today-infrastructure by TAKETODAY.

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);
    assertThat(inParameters.size()).as("Wrong number of matched in parameter values").isEqualTo(2);
    assertThat(inParameters.containsKey("id")).as("in parameter value missing").isTrue();
    assertThat(inParameters.containsKey("name")).as("in out parameter value missing").isTrue();
    boolean condition = !inParameters.containsKey("customer_no");
    assertThat(condition).as("out parameter value matched").isTrue();
    List<String> names = context.getOutParameterNames();
    assertThat(names.size()).as("Wrong number of out parameters").isEqualTo(2);
    List<SqlParameter> callParameters = context.getCallParameters();
    assertThat(callParameters.size()).as("Wrong number of call parameters").isEqualTo(3);
}
Also used : SqlParameter(cn.taketoday.jdbc.core.SqlParameter) MapSqlParameterSource(cn.taketoday.jdbc.core.namedparam.MapSqlParameterSource) ArrayList(java.util.ArrayList) SqlOutParameter(cn.taketoday.jdbc.core.SqlOutParameter) SqlInOutParameter(cn.taketoday.jdbc.core.SqlInOutParameter) Test(org.junit.jupiter.api.Test)

Aggregations

SqlInOutParameter (cn.taketoday.jdbc.core.SqlInOutParameter)4 SqlOutParameter (cn.taketoday.jdbc.core.SqlOutParameter)4 Test (org.junit.jupiter.api.Test)4 SqlParameter (cn.taketoday.jdbc.core.SqlParameter)2 MapSqlParameterSource (cn.taketoday.jdbc.core.namedparam.MapSqlParameterSource)2 DriverManagerDataSource (cn.taketoday.jdbc.datasource.DriverManagerDataSource)2 ArrayList (java.util.ArrayList)2