Search in sources :

Example 11 with ClientTestModel

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

the class DalTableDaoTestStub method testBatchDelete.

/**
 * Test batch delete multiple entities
 * @throws SQLException
 */
@Test
public void testBatchDelete() throws SQLException {
    List<ClientTestModel> entities = new ArrayList<ClientTestModel>();
    for (int i = 0; i < 3; i++) {
        ClientTestModel model = new ClientTestModel();
        model.setId(i + 1);
        entities.add(model);
    }
    int[] res = dao.batchDelete(new DalHints(), entities);
    assertEqualsBatch(new int[] { 1, 1, 1 }, res, 4 - 3);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with ClientTestModel

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

the class DalTableDaoTestStub method testCombinedInsert.

/**
 * Test Insert multiple entities with one SQL Statement
 * @throws SQLException
 */
@Test
public void testCombinedInsert() throws SQLException {
    if (!diff.supportInsertValues)
        return;
    List<ClientTestModel> entities = new ArrayList<ClientTestModel>();
    for (int i = 0; i < 3; i++) {
        ClientTestModel model = new ClientTestModel();
        model.setQuantity(10 + 1 % 3);
        model.setType(((Number) (1 % 3)).shortValue());
        model.setAddress("CTRIP");
        entities.add(model);
    }
    KeyHolder holder = diff.supportGetGeneratedKeys ? new KeyHolder() : null;
    DalHints hints = new DalHints();
    int res = dao.combinedInsert(hints, holder, entities);
    assertEquals(3, res, 4 + 3);
    if (diff.supportGetGeneratedKeys) {
        Assert.assertEquals(3, holder.size());
        Assert.assertTrue(holder.getKeyList().get(0).containsKey("GENERATED_KEY"));
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) ArrayList(java.util.ArrayList) KeyHolder(com.ctrip.platform.dal.dao.KeyHolder) Test(org.junit.Test)

Example 13 with ClientTestModel

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

the class DalTableDaoTestStub method testBatchUpdate.

/**
 * Test update multiple entities with primary key
 * @throws SQLException
 */
@Test
public void testBatchUpdate() throws SQLException {
    DalHints hints = new DalHints();
    List<ClientTestModel> modelList = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        ClientTestModel model = new ClientTestModel();
        model.setId(i + 1);
        model.setAddress("CTRIP");
        modelList.add(model);
    }
    int[] res = dao.batchUpdate(hints, modelList);
    assertEqualsBatch(new int[] { 1, 1, 1 }, res, 3, "address='CTRIP'");
    ClientTestModel model = dao.queryByPk(1, hints);
    Assert.assertTrue(null != model);
    Assert.assertEquals("CTRIP", model.getAddress());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 14 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryObjectAllColumns.

@Test
public void testQueryObjectAllColumns() throws SQLException {
    SelectSqlBuilder builder = new SelectSqlBuilder().selectAllColumns();
    builder.equal("type", 1, Types.SMALLINT);
    builder.requireFirst();
    ClientTestModel models = dao.queryObject(builder, new DalHints());
    Assert.assertNotNull(models);
    builder = new SelectSqlBuilder().selectAllColumns();
    builder.equal("type", 1, Types.SMALLINT);
    builder.requireFirst();
    models = dao.queryObject(builder.atPage(1, 1), new DalHints());
    Assert.assertNotNull(models);
    builder = new SelectSqlBuilder().selectAllColumns();
    builder.equal("type", 10, Types.SMALLINT);
    builder.requireFirst();
    models = dao.queryObject(builder.atPage(1, 10), new DalHints());
    Assert.assertNull(models);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder) Test(org.junit.Test)

Example 15 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryList.

@Test
public void testQueryList() throws SQLException {
    SelectSqlBuilder builder = new SelectSqlBuilder();
    builder.equal("type", 1, Types.SMALLINT);
    List<ClientTestModel> models = dao.query(builder, new DalHints());
    Assert.assertTrue(null != models);
    Assert.assertEquals(3, models.size());
    builder = new SelectSqlBuilder();
    builder.equal("type", 1, Types.SMALLINT);
    models = dao.query(builder.atPage(1, 1), new DalHints());
    Assert.assertTrue(null != models);
    Assert.assertEquals(1, models.size());
    builder = new SelectSqlBuilder();
    builder.equal("type", 10, Types.SMALLINT);
    models = dao.query(builder.atPage(1, 10), new DalHints());
    Assert.assertTrue(null != models);
    Assert.assertEquals(0, models.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder) 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