use of com.ctrip.platform.dal.dao.task.BatchUpdateTask in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testVersionNotSet.
@Test
public void testVersionNotSet() throws SQLException {
BatchUpdateTask<UpdatableVersionModel> test = new BatchUpdateTask<>();
DalParser<UpdatableVersionModel> parser = new DalDefaultJpaParser<>(UpdatableVersionModel.class, getDbName());
test.initialize(parser);
DalTableDao<UpdatableVersionModel> dao = new DalTableDao<UpdatableVersionModel>(parser);
DalHints hints = new DalHints();
List<UpdatableVersionModel> pojos = dao.query("1=1", new StatementParameters(), new DalHints());
for (UpdatableVersionModel model : pojos) {
model.setAddress("1122334455");
model.setLastChanged(null);
}
try {
execute(test, hints, pojos);
fail();
} catch (SQLException e) {
assertEquals(ErrorCode.ValidateVersion.getMessage(), e.getMessage());
}
}
use of com.ctrip.platform.dal.dao.task.BatchUpdateTask in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testIgnorNullField.
@Test
public void testIgnorNullField() {
BatchUpdateTask<ClientTestModel> test = new BatchUpdateTask<>();
test.initialize(getParser());
DalHints hints = new DalHints();
try {
List<ClientTestModel> pojos = getAll();
for (ClientTestModel model : pojos) {
model.setAddress("1122334455");
model.setType((Short) null);
model.setQuantity(null);
model.setDbIndex(null);
model.setLastChanged(null);
model.setTableIndex(null);
}
int[] result = execute(test, hints, pojos);
assertEquals(3, result.length);
assertEquals(3, getCount());
pojos = getAll();
for (ClientTestModel model : pojos) {
assertEquals("1122334455", model.getAddress());
assertNotNull(model.getQuantity());
assertNotNull(model.getType());
assertNotNull(model.getDbIndex());
assertNotNull(model.getLastChanged());
assertNotNull(model.getTableIndex());
}
} catch (SQLException e) {
e.printStackTrace();
fail();
}
}
use of com.ctrip.platform.dal.dao.task.BatchUpdateTask in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testIncludeExcludeColumns.
@Test
public void testIncludeExcludeColumns() throws SQLException {
BatchUpdateTask<UpdatableIntVersionModel> test = new BatchUpdateTask<>();
DalParser<UpdatableIntVersionModel> parser = new DalDefaultJpaParser<>(UpdatableIntVersionModel.class, getDbName());
test.initialize(parser);
DalTableDao<UpdatableIntVersionModel> dao = new DalTableDao<>(parser);
DalHints hints = new DalHints().exclude("dbIndex").include("quantity", "dbIndex", "address");
List<UpdatableIntVersionModel> pojos = dao.query("1=1", new StatementParameters(), new DalHints());
for (UpdatableIntVersionModel model : pojos) {
model.setQuantity(500);
model.setDbIndex(100);
model.setAddress("1122334455");
}
int[] result = execute(test, hints, pojos);
assertArrayEquals(new int[] { 1, 1, 1 }, result);
pojos = dao.query("1=1", new StatementParameters(), new DalHints());
for (UpdatableIntVersionModel model : pojos) {
assertEquals("1122334455", model.getAddress());
assertEquals(500, model.getQuantity().intValue());
assertEquals(0, model.getDbIndex().intValue());
}
}
Aggregations