Search in sources :

Example 36 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryLike.

/**
 * Query against sample entity
 *
 * @throws SQLException
 */
@Test
public void testQueryLike() throws SQLException {
    ClientTestModel pk = new ClientTestModel();
    pk.setType((short) 1);
    List<ClientTestModel> models = dao.queryLike(pk, new DalHints());
    Assert.assertTrue(null != models);
    Assert.assertEquals(3, models.size());
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) Test(org.junit.Test)

Example 37 with ClientTestModel

use of 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);
    builder.orderBy("id", true);
    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);
    builder.orderBy("id", true);
    models = dao.query(builder.atPage(1, 10), new DalHints());
    Assert.assertTrue(null != models);
    Assert.assertEquals(0, models.size());
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder) Test(org.junit.Test)

Example 38 with ClientTestModel

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

the class DalTableDaoTestStub method testDelete.

/**
 * Test delete single entities
 *
 * @throws SQLException
 */
@Test
public void testDelete() throws SQLException {
    ClientTestModel model = new ClientTestModel();
    model.setId(1);
    int res = dao.delete(new DalHints(), model);
    Assert.assertEquals(1, res, 4 - 1);
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) Test(org.junit.Test)

Example 39 with ClientTestModel

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

the class DalTableDaoTestStub method testBatchInsert.

/**
 * Test Batch Insert multiple entities
 *
 * @throws SQLException
 */
@Test
public void testBatchInsert() throws SQLException {
    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);
    }
    int[] res = dao.batchInsert(new DalHints(), entities);
    assertEqualsBatchInsert(new int[] { 1, 1, 1 }, res, 7);
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 40 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryByPk.

/**
 * Test Query by Primary key
 *
 * @throws SQLException
 */
@Test
public void testQueryByPk() throws SQLException {
    ClientTestModel model = dao.queryByPk(1, new DalHints());
    Assert.assertTrue(null != model);
    Assert.assertEquals(10, model.getQuantity().intValue());
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) 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