Search in sources :

Example 31 with ClientTestModel

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

the class DalDirectClientTestStub method batchUpdateTestWithoutRollback.

// The SQL server does not support auto commit for batch update
@Test
public void batchUpdateTestWithoutRollback() throws SQLException {
    if (diff.category == DatabaseCategory.SqlServer)
        return;
    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 - 1, 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 32 with ClientTestModel

use of test.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 : 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 33 with ClientTestModel

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

the class DalQueryDaoTestStub method testQueryFromSuccess.

/**
 * Test query for From success
 * @throws SQLException
 */
@Test
public void testQueryFromSuccess() throws SQLException {
    String sql = "SELECT * FROM " + TABLE_NAME;
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    List<ClientTestModel> models = client.queryFrom(sql, param, hints, mapper, 0, 10);
    Assert.assertEquals(10, models.size());
    Assert.assertEquals(1, models.get(0).getId().intValue());
    List<ClientTestModel> models_2 = client.queryFrom(sql, param, hints, mapper, 100, 10);
    Assert.assertEquals(10, models_2.size());
    Assert.assertEquals(101, models_2.get(0).getId().intValue());
}
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 34 with ClientTestModel

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

the class DalQueryDaoTestStub method testQueryTopFailed.

/**
 * Test query for Top failed
 * @throws SQLException
 */
@Test
public void testQueryTopFailed() throws SQLException {
    String sql = "SELECT * FROM " + TABLE_NAME + " WHERE iid = -1";
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    try {
        List<ClientTestModel> models = client.queryTop(sql, param, hints, mapper, 1000);
        Assert.fail();
    } catch (Exception e) {
    }
}
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) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 35 with ClientTestModel

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

the class DalQueryDaoTestStub method testQueryWithCallback.

/**
 * Test the query function with callback
 * @throws SQLException
 */
@Test
public void testQueryWithCallback() throws SQLException {
    String sql = "SELECT * FROM " + TABLE_NAME + " WHERE id = 1";
    final ClientTestModel model = new ClientTestModel();
    DalRowCallback callback = new DalRowCallback() {

        @Override
        public void process(ResultSet rs) throws SQLException {
            model.setId(rs.getInt(1));
            model.setQuantity(rs.getInt(2));
            model.setType(rs.getShort(3));
            model.setAddress(rs.getString(4));
            model.setLastChanged(rs.getTimestamp(5));
        }
    };
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    client.query(sql, param, hints, callback);
    Assert.assertEquals(1, model.getId().intValue());
}
Also used : DalRowCallback(com.ctrip.platform.dal.dao.DalRowCallback) DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ResultSet(java.sql.ResultSet) 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