Search in sources :

Example 31 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryFirstWithSelectSqlBuilder.

@Test
public void testQueryFirstWithSelectSqlBuilder() throws SQLException {
    String whereClause = "type=?";
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.SMALLINT, 1);
    SelectSqlBuilder builder = new SelectSqlBuilder().where(whereClause).with(parameters);
    ClientTestModel model = dao.queryFirst(builder, new DalHints());
    Assert.assertTrue(null != model);
    Assert.assertEquals(1, model.getId().intValue());
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder) Test(org.junit.Test)

Example 32 with ClientTestModel

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

the class DalTableDaoTestStub method testDeleteMultiple.

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

Example 33 with ClientTestModel

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

Example 34 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryFirstWithWhereClause.

/**
 * Test Query the first row with where clause
 *
 * @throws SQLException
 */
@Test
public void testQueryFirstWithWhereClause() throws SQLException {
    String whereClause = "type=?";
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.SMALLINT, 1);
    ClientTestModel model = dao.queryFirst(whereClause, parameters, new DalHints());
    Assert.assertTrue(null != model);
    Assert.assertEquals(1, model.getId().intValue());
}
Also used : ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) Test(org.junit.Test)

Example 35 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryByPkWithEntity.

/**
 * Query by Entity with Primary key
 *
 * @throws SQLException
 */
@Test
public void testQueryByPkWithEntity() throws SQLException {
    ClientTestModel pk = new ClientTestModel();
    pk.setId(1);
    ClientTestModel model = dao.queryByPk(pk, 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