Search in sources :

Example 46 with ClientTestModel

use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalDirectClientTestStub method batchCallTestForSpWithOutParameter.

/**
 * Test batch call with parameters and has ResultParameters
 * @throws SQLException
 */
@Test
public void batchCallTestForSpWithOutParameter() throws SQLException {
    // Oracle do not support out parameter for batch store procedure update
    if (!diff.supportBatchSpWithOutParameter)
        return;
    String callSql = "{call " + SP_WITH_OUT_PARAM + "(?,?)}";
    StatementParameters[] parametersList = new StatementParameters[3];
    for (int i = 0; i < 3; i++) {
        StatementParameters parameters = new StatementParameters();
        parameters.set("v_id", Types.INTEGER, i + 1);
        parameters.registerOut("count", Types.INTEGER);
        parametersList[i] = parameters;
    }
    DalHints hints = new DalHints();
    int[] res = client.batchCall(callSql, parametersList, hints);
    Assert.assertEquals(3, res.length);
    List<ClientTestModel> models = this.queryModelsByIds(1, 2, 3);
    Assert.assertEquals(0, models.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 47 with ClientTestModel

use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalDirectClientTestStub method queryTestWithParameters.

/**
 * Test the basic query function without parameters
 *
 * @throws SQLException
 */
@Test
public void queryTestWithParameters() throws SQLException {
    String querySql = "SELECT * FROM " + TABLE_NAME + " WHERE type = ?";
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.SMALLINT, 1);
    ClientTestDalRowMapper mapper = new ClientTestDalRowMapper();
    DalHints hints = new DalHints();
    List<ClientTestModel> res = client.query(querySql, parameters, hints, new DalRowMapperExtractor<ClientTestModel>(mapper));
    Assert.assertTrue(null != res);
    Assert.assertEquals(2, res.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ClientTestDalRowMapper(com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper) Test(org.junit.Test)

Example 48 with ClientTestModel

use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalDirectClientTestStub method updateTestWithoutParameters.

/**
 * Test the update function without parameters
 *
 * @throws SQLException
 */
@Test
public void updateTestWithoutParameters() throws SQLException {
    String updateSql = String.format("UPDATE %s SET address=%s WHERE id=%s", TABLE_NAME, "'BJ INFO'", 1);
    StatementParameters parameters = new StatementParameters();
    DalHints hints = new DalHints();
    int count = client.update(updateSql, parameters, hints);
    assertEquals(1, count, 3);
    List<ClientTestModel> po_models = this.queryModelsByIds(1);
    Assert.assertTrue(null != po_models);
    Assert.assertEquals(1, po_models.size());
    Assert.assertEquals("BJ INFO", po_models.get(0).getAddress());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 49 with ClientTestModel

use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalDirectClientTestStub method callTestWithParametersForSpWithoutOutParameter.

/**
 * Test call with parameters but has no resultsParameter
 * @throws SQLException
 */
@Test
public void callTestWithParametersForSpWithoutOutParameter() throws SQLException {
    String callSql = "{call " + SP_WITHOUT_OUT_PARAM + "(?,?,?,?)}";
    StatementParameters parameters = new StatementParameters();
    parameters.set("v_id", Types.INTEGER, 4);
    parameters.set("v_quantity", Types.INTEGER, 10);
    parameters.set("v_type", Types.SMALLINT, 3);
    parameters.set("v_address", Types.VARCHAR, "SZ INFO");
    DalHints hints = new DalHints();
    Map<String, ?> res = client.call(callSql, parameters, hints);
    Assert.assertTrue(null != res);
    Assert.assertEquals(0, res.size());
    List<ClientTestModel> models = this.queryModelsByIds();
    Assert.assertEquals(4, models.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 50 with ClientTestModel

use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.

the class DalQueryDaoTestStub method testQueryFirstNullableSuccess.

/**
 * Test query for first success
 * @throws SQLException
 */
@Test
public void testQueryFirstNullableSuccess() throws SQLException {
    String sql = "SELECT * FROM " + TABLE_NAME + " WHERE id = 1";
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    ClientTestModel model = client.queryFirstNullable(sql, param, hints, mapper);
    Assert.assertEquals(1, model.getId().intValue());
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) Test(org.junit.Test)

Aggregations

ClientTestModel (com.ctrip.platform.dal.dao.unitbase.ClientTestModel)57 Test (org.junit.Test)55 DalHints (com.ctrip.platform.dal.dao.DalHints)29 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)27 ArrayList (java.util.ArrayList)13 SQLException (java.sql.SQLException)9 SelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)5 DalClient (com.ctrip.platform.dal.dao.DalClient)3 DalCommand (com.ctrip.platform.dal.dao.DalCommand)3 ClientTestDalRowMapper (com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper)3 DalRowMapperExtractor (com.ctrip.platform.dal.dao.helper.DalRowMapperExtractor)2 DalCustomRowMapper (com.ctrip.platform.dal.dao.helper.DalCustomRowMapper)1 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)1 ResultSet (java.sql.ResultSet)1 Timestamp (java.sql.Timestamp)1 List (java.util.List)1 Map (java.util.Map)1