Search in sources :

Example 41 with ClientTestModel

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

the class DalDirectClientTestStub method queryTestWithoutParameters.

/**
 * Test the basic query function without parameters
 *
 * @throws SQLException
 */
@Test
public void queryTestWithoutParameters() throws SQLException {
    String querySql = "SELECT * FROM " + TABLE_NAME;
    StatementParameters parameters = new StatementParameters();
    ClientTestDalRowMapper mapper = new ClientTestDalRowMapper();
    DalHints hints = new DalHints();
    List<ClientTestModel> res = client.query(querySql, parameters, hints, new DalRowMapperExtractor<ClientTestModel>(mapper));
    Assert.assertTrue(null != res && res.size() == 3);
    ClientTestModel model = res.get(0);
    Assert.assertTrue(model.getQuantity() == 10 && model.getType() == 1 && model.getAddress().equals("SH INFO"));
}
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 42 with ClientTestModel

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

the class DalDirectClientTestStub method batchUpdateTestWithRollback.

@Test
public void batchUpdateTestWithRollback() throws SQLException {
    String[] sqls = new String[] { "DELETE FROM " + TABLE_NAME + " WHERE ID = 1", "DELETE FROM " + TABLE_NAME + " WHERE _ID = 2", "DELETE FROM " + TABLE_NAME + " WHERE ID = 3" };
    DalHints hints = new DalHints();
    // hints.set(DalHintEnum.forceAutoCommit);
    try {
        client.batchUpdate(sqls, hints);
        Assert.fail();
    } catch (Exception e) {
    }
    List<ClientTestModel> models = this.queryModelsByIds();
    Assert.assertEquals(3, models.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 43 with ClientTestModel

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

the class DalDirectClientTestStub method callTestWithoutParametersForSpWithoutOutParameter.

/**
 * Test call without parameters and has no resultsParameter
 * @throws SQLException
 */
@Test
public void callTestWithoutParametersForSpWithoutOutParameter() throws SQLException {
    String callSql = "{call " + SP_WITHOUT_OUT_PARAM + "(4, 12,1,'SZ INFO')}";
    StatementParameters parameters = new StatementParameters();
    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 44 with ClientTestModel

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

the class DalDirectClientTestStub method callTestForSpWithInOutParameters.

/**
 * Test the call function with in-out parameters
 * @throws SQLException
 */
@Test
public void callTestForSpWithInOutParameters() throws SQLException {
    String callSql = "{call " + SP_WITH_IN_OUT_PARAM + "(?,?,?,?)}";
    StatementParameters parameters = new StatementParameters();
    parameters.set("v_id", Types.INTEGER, 1);
    parameters.set("v_quantity", Types.INTEGER, 10);
    parameters.set("v_type", Types.SMALLINT, 3);
    parameters.registerInOut("v_address", Types.VARCHAR, "SZ INFO");
    DalHints hints = new DalHints();
    Map<String, ?> res = client.call(callSql, parameters, hints);
    Assert.assertTrue(null != res);
    Assert.assertEquals(1, res.size());
    Assert.assertTrue(res.containsKey("v_address"));
    Assert.assertEquals("output", parameters.get("v_address", ParameterDirection.InputOutput).getValue());
    List<ClientTestModel> models = this.queryModelsByIds(1);
    Assert.assertEquals(1, models.size());
    Assert.assertEquals("SZ INFO", 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 45 with ClientTestModel

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

the class DalDirectClientTestStub method batchUpdateTestWithParametersAllSuccessed.

/**
 * Test the batch update function with parameters all success.
 *
 * @throws SQLException
 */
@Test
public void batchUpdateTestWithParametersAllSuccessed() throws SQLException {
    String sql = "INSERT INTO " + TABLE_NAME + "(quantity,type,address,last_changed) VALUES(?, ?, ?,?)";
    StatementParameters[] parameterList = new StatementParameters[2];
    parameterList[0] = new StatementParameters();
    parameterList[0].set(1, Types.INTEGER, 11);
    parameterList[0].set(2, Types.SMALLINT, 2);
    parameterList[0].set(3, Types.VARCHAR, "SZ INFO");
    parameterList[0].set(4, Types.TIMESTAMP, new Timestamp(System.currentTimeMillis()));
    parameterList[1] = new StatementParameters();
    parameterList[1].set(1, Types.INTEGER, 11);
    parameterList[1].set(2, Types.SMALLINT, 2);
    parameterList[1].set(3, Types.VARCHAR, "HK INFO");
    parameterList[1].set(4, Types.TIMESTAMP, new Timestamp(System.currentTimeMillis()));
    DalHints hints = new DalHints();
    int[] counts = client.batchUpdate(sql, parameterList, hints);
    assertEqualsBatchInsert(new int[] { 1, 1 }, counts, 3 + 2);
    List<ClientTestModel> models = this.queryModelsByIds();
    Assert.assertEquals(5, 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) Timestamp(java.sql.Timestamp) 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