use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testInsertMultipleAsListWithContinueOnErrorHints.
/**
* Test Test Insert multiple entities one by one with continueOnError hints
* @throws SQLException
*/
@Test
public void testInsertMultipleAsListWithContinueOnErrorHints() 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());
if (i == 1) {
model.setAddress("CTRIPCTRIPCTRIPCTRIPCTRIPCTRIPCTRIP" + "CTRIPCTRIPCTRIPCTRIPCTRIPCTRIPCTRIPCTRIPCTRIP" + "CTRIPCTRIPCTRIPCTRIP");
} else {
model.setAddress("CTRIP");
}
entities.add(model);
}
DalHints hints = new DalHints(DalHintEnum.continueOnError);
int[] res = dao.insert(hints, entities);
assertEquals(new int[] { 1, 0, 1 }, res, 4 + 2);
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testUpdateMultiple.
/**
* Test update multiple entities with primary key
* @throws SQLException
*/
@Test
public void testUpdateMultiple() throws SQLException {
DalHints hints = new DalHints();
List<ClientTestModel> models = new ArrayList<>();
for (int i = 0; i < 3; i++) {
ClientTestModel model = new ClientTestModel();
model.setId(i + 1);
model.setAddress("CTRIP");
models.add(model);
}
int[] res = dao.update(hints, models);
assertEquals(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 test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testQueryFromWithWhereClause.
/**
* Test Query range of result with where clause
* @throws SQLException
*/
@Test
public void testQueryFromWithWhereClause() throws SQLException {
String whereClause = "type=?";
StatementParameters parameters = new StatementParameters();
parameters.set(1, Types.SMALLINT, 1);
List<ClientTestModel> models = dao.queryFrom(whereClause, parameters, new DalHints(), 0, 1);
Assert.assertTrue(null != models);
Assert.assertEquals(1, models.size());
}
use of test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel in project dal by ctripcorp.
the class DalTableDaoTestStub method testUpdatePlain.
/**
* Test plain update with SQL
* @throws SQLException
*/
@Test
public void testUpdatePlain() throws SQLException {
String sql = "UPDATE " + TABLE_NAME + " SET address = 'CTRIP' WHERE id = 1";
StatementParameters parameters = new StatementParameters();
DalHints hints = new DalHints();
int res = dao.update(sql, parameters, hints);
assertEquals(1, res, 1, "address = 'CTRIP'");
ClientTestModel model = dao.queryByPk(1, hints);
Assert.assertTrue(null != model);
Assert.assertEquals("CTRIP", model.getAddress());
}
use of test.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);
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);
models = dao.query(builder.atPage(1, 10), new DalHints());
Assert.assertTrue(null != models);
Assert.assertEquals(0, models.size());
}
Aggregations