Search in sources :

Example 21 with ClientTestModel

use of test.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(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 22 with ClientTestModel

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

the class DalDirectClientTestStub method executeTestWithMultipleCommandsAllSuccessed.

/**
 * Test execute multiple commands and all successes.
 * @throws SQLException
 */
@Test
public void executeTestWithMultipleCommandsAllSuccessed() throws SQLException {
    final DalHints hints = new DalHints();
    List<DalCommand> commands = new ArrayList<DalCommand>();
    commands.add(new DalCommand() {

        @Override
        public boolean execute(DalClient client) throws SQLException {
            String sql = "DELETE FROM " + TABLE_NAME + " WHERE id = 1";
            StatementParameters parameters = new StatementParameters();
            client.update(sql, parameters, hints);
            return true;
        }
    });
    commands.add(new DalCommand() {

        @Override
        public boolean execute(DalClient client) throws SQLException {
            String sql = "DELETE FROM " + TABLE_NAME + " WHERE id = 2";
            StatementParameters parameters = new StatementParameters();
            client.update(sql, parameters, hints);
            return true;
        }
    });
    commands.add(new DalCommand() {

        @Override
        public boolean execute(DalClient client) throws SQLException {
            String sql = "DELETE FROM " + TABLE_NAME + " WHERE id = 3";
            StatementParameters parameters = new StatementParameters();
            client.update(sql, parameters, hints);
            return true;
        }
    });
    client.execute(commands, hints);
    List<ClientTestModel> models = this.queryModelsByIds();
    Assert.assertEquals(0, models.size());
}
Also used : DalCommand(com.ctrip.platform.dal.dao.DalCommand) DalHints(com.ctrip.platform.dal.dao.DalHints) DalClient(com.ctrip.platform.dal.dao.DalClient) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) SQLException(java.sql.SQLException) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 23 with ClientTestModel

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

the class DalDirectClientTestStub method queryTestWithFetchSizeLimit.

/**
 * Test the basic query function with maxRows limit
 *
 * @throws SQLException
 */
@Test
public void queryTestWithFetchSizeLimit() throws SQLException {
    String querySql = "SELECT * FROM " + TABLE_NAME;
    StatementParameters parameters = new StatementParameters();
    ClientTestDalRowMapper mapper = new ClientTestDalRowMapper();
    DalHints hints = new DalHints();
    // Set fetch size limit
    hints.set(DalHintEnum.maxRows, 1);
    List<ClientTestModel> res = client.query(querySql, parameters, hints, new DalRowMapperExtractor<ClientTestModel>(mapper));
    Assert.assertTrue(null != res);
    Assert.assertEquals(1, res.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ClientTestDalRowMapper(test.com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper) Test(org.junit.Test)

Example 24 with ClientTestModel

use of test.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(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 25 with ClientTestModel

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

the class DalDirectClientTestStub method batchUpdateTestWithParametersNotAllSuccessed.

/**
 * Test the batch update function with parameters not all success.
 *
 * @throws SQLException
 */
@Test
public void batchUpdateTestWithParametersNotAllSuccessed() throws SQLException {
    String sql = "DELETE FROM " + TABLE_NAME + " WHERE id = ?";
    StatementParameters[] parameterList = new StatementParameters[2];
    parameterList[0] = new StatementParameters();
    parameterList[0].set(1, Types.INTEGER, 1);
    parameterList[1] = new StatementParameters();
    parameterList[1].set(1, Types.INTEGER, 100);
    DalHints hints = new DalHints();
    int[] counts = client.batchUpdate(sql, parameterList, hints);
    Assert.assertEquals(2, counts.length);
    assertEqualsBatch(new int[] { 1, 0 }, counts, 3 - 1);
    List<ClientTestModel> models = this.queryModelsByIds();
    Assert.assertEquals(2, models.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)61 ClientTestModel (test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel)61 Test (org.junit.Test)59 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)40 ArrayList (java.util.ArrayList)13 SQLException (java.sql.SQLException)9 DalClient (com.ctrip.platform.dal.dao.DalClient)3 DalCommand (com.ctrip.platform.dal.dao.DalCommand)3 SelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)3 ClientTestDalRowMapper (test.com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper)3 KeyHolder (com.ctrip.platform.dal.dao.KeyHolder)2 DalRowMapperExtractor (com.ctrip.platform.dal.dao.helper.DalRowMapperExtractor)2 DalRowCallback (com.ctrip.platform.dal.dao.DalRowCallback)1 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