Search in sources :

Example 26 with ClientTestModel

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

the class DalDirectClientTestStub method updateTestWithParameters.

/**
 * Test the update function with parameters
 *
 * @throws SQLException
 */
@Test
public void updateTestWithParameters() throws SQLException {
    String updateSql = String.format("UPDATE %s SET address=? WHERE id=?", TABLE_NAME);
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.VARCHAR, "BJ INFO");
    parameters.set(2, Types.INTEGER, 1);
    DalHints hints = new DalHints();
    int count = client.update(updateSql, parameters, hints);
    assertEquals(1, count, 2, "address='BJ INFO'");
    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 27 with ClientTestModel

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

the class DalDirectClientTestStub method callTestForSpWithOutParameter.

/**
 * Test the call function with out parameters
 * @throws SQLException
 */
@Test
public void callTestForSpWithOutParameter() throws SQLException {
    String callSql = diff.category == DatabaseCategory.SqlServer ? "{call " + SP_WITH_OUT_PARAM + "(?,?)}" : "call " + SP_WITH_OUT_PARAM + "(?,?)";
    StatementParameters parameters = new StatementParameters();
    parameters.set("v_id", Types.INTEGER, 1);
    parameters.registerOut("count", Types.INTEGER);
    DalHints hints = new DalHints();
    Map<String, ?> res = client.call(callSql, parameters, hints);
    Assert.assertTrue(null != res);
    Assert.assertEquals(1, res.size());
    Assert.assertEquals(2, ((Number) res.get("count")).intValue());
    List<ClientTestModel> models = this.queryModelsByIds(1);
    Assert.assertEquals(0, models.size());
    List<ClientTestModel> models_d = this.queryModelsByIds();
    Assert.assertEquals(2, models_d.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)

Example 28 with ClientTestModel

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

Example 29 with ClientTestModel

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

Example 30 with ClientTestModel

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

the class DalDirectClientTestStub method batchCallTestWithParametersForSpWithoutOutParameter.

/**
 * Test batch call with parameters but has no ResultParameters
 * @throws SQLException
 */
@Test
public void batchCallTestWithParametersForSpWithoutOutParameter() throws SQLException {
    String callSql = "{call " + SP_WITHOUT_OUT_PARAM + "(?,?,?,?)}";
    StatementParameters[] parametersList = new StatementParameters[7];
    DalHints hints = new DalHints();
    for (int i = 0; i < 7; i++) {
        StatementParameters parameters = new StatementParameters();
        parameters.set("v_id", Types.INTEGER, null);
        parameters.set("v_quantity", Types.INTEGER, 10 + i);
        parameters.set("v_type", Types.SMALLINT, 3);
        parameters.set("v_address", Types.VARCHAR, "SZ INFO" + "_" + i);
        parametersList[i] = parameters;
    }
    int[] res = client.batchCall(callSql, parametersList, hints);
    Assert.assertEquals(7, res.length);
    List<ClientTestModel> models = this.queryModelsByIds();
    Assert.assertEquals(10, 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