use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testQueryListAllColumns.
@Test
public void testQueryListAllColumns() throws SQLException {
SelectSqlBuilder builder = new SelectSqlBuilder().selectAllColumns();
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().selectAllColumns();
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().selectAllColumns();
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());
}
use of 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());
}
use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testCompatabilityWithTableSelectBuilder.
@Test
public void testCompatabilityWithTableSelectBuilder() throws SQLException {
SelectSqlBuilder builder = new SelectSqlBuilder();
builder.equal("type", 1, Types.SMALLINT);
List<ClientTestModel> models1 = dao.query((TableSelectBuilder) builder, new DalHints());
Assert.assertTrue(null != models1);
Assert.assertEquals(3, models1.size());
builder = new SelectSqlBuilder();
builder.equal("type", 1, Types.SMALLINT);
List<Short> models2 = dao.query((TableSelectBuilder) builder, new DalHints(), Short.class);
Assert.assertTrue(null != models2);
Assert.assertEquals(3, models2.size());
builder = new SelectSqlBuilder();
builder.equal("type", 1, Types.SMALLINT);
builder.requireFirst();
ClientTestModel clientTestModel = dao.queryObject((TableSelectBuilder) builder, new DalHints());
Assert.assertNotNull(clientTestModel);
builder = new SelectSqlBuilder();
builder.equal("type", 1, Types.SMALLINT);
builder.requireFirst();
Short shortResult = dao.queryObject((TableSelectBuilder) builder.atPage(1, 1), new DalHints(), Short.class);
Assert.assertNotNull(shortResult);
builder = new SelectSqlBuilder();
builder.selectCount();
builder.equal("type", 1, Types.SMALLINT);
Number number = dao.count((TableSelectBuilder) builder, new DalHints());
Assert.assertEquals(3, number.intValue());
}
use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testQueryByPkWithEntityByColumnNames.
/**
* Query by Entity with Primary key
*
* @throws SQLException
*/
@Test
public void testQueryByPkWithEntityByColumnNames() throws SQLException {
ClientTestModel pk = new ClientTestModel();
pk.setId(1);
ClientTestModel model = dao.queryByPk(pk, new DalHints().selectByNames());
Assert.assertTrue(null != model);
Assert.assertEquals(10, model.getQuantity().intValue());
model = dao.queryByPk(pk, new DalHints(DalHintEnum.selectByNames));
Assert.assertTrue(null != model);
Assert.assertEquals(10, model.getQuantity().intValue());
}
use of com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testInsertMultipleAsListWithKeyHolder.
/**
* Test Insert multiple entities with key-holder
*
* @throws SQLException
*/
@Test
public void testInsertMultipleAsListWithKeyHolder() 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);
}
KeyHolder holder = diff.supportGetGeneratedKeys ? new KeyHolder() : null;
int[] res = dao.insert(new DalHints(), holder, entities);
assertEquals(new int[] { 1, 1, 1 }, res, 4 + 3);
if (diff.supportGetGeneratedKeys) {
Assert.assertEquals(3, holder.size());
Assert.assertTrue(holder.getKeyList().get(0).containsKey("GENERATED_KEY"));
}
}
Aggregations