use of com.ctrip.platform.dal.dao.task.BatchUpdateTask in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testExecute.
@Test
public void testExecute() {
BatchUpdateTask<ClientTestModel> test = new BatchUpdateTask<>();
test.initialize(getParser());
DalHints hints = new DalHints();
try {
List<ClientTestModel> pojos = getAll();
for (ClientTestModel model : pojos) model.setAddress("1122334455");
int[] result = execute(test, hints, pojos);
assertEquals(3, result.length);
assertArrayEquals(new int[] { 1, 1, 1 }, result);
assertEquals(3, getCount());
pojos = getAll();
for (ClientTestModel model : pojos) assertEquals("1122334455", model.getAddress());
} catch (SQLException e) {
e.printStackTrace();
fail();
}
}
use of com.ctrip.platform.dal.dao.task.BatchUpdateTask in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testValidteNullField.
@Test
public void testValidteNullField() {
BatchUpdateTask<ClientTestModel> test = new BatchUpdateTask<>();
test.initialize(getParser());
DalHints hints = new DalHints();
try {
List<ClientTestModel> pojos = getAll();
for (ClientTestModel model : pojos) {
model.setAddress(null);
model.setType(null);
model.setQuantity(null);
model.setDbIndex(null);
model.setLastChanged(null);
model.setTableIndex(null);
}
int[] result = execute(test, hints, pojos);
fail();
} catch (SQLException e) {
assertEquals(e.getMessage(), ErrorCode.ValidateFieldCount.getMessage());
}
}
use of com.ctrip.platform.dal.dao.task.BatchUpdateTask in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testUpdateNullField.
@Test
public void testUpdateNullField() {
BatchUpdateTask<ClientTestModel> test = new BatchUpdateTask<>();
test.initialize(getParser());
DalHints hints = new DalHints();
try {
List<ClientTestModel> pojos = getAll();
for (ClientTestModel model : pojos) {
model.setType((Short) null);
model.setQuantity(-100);
model.setDbIndex(null);
// My sql, it will use default value, while sqlserver will not
// model.setLastChanged(null);
model.setTableIndex(null);
}
int[] result = execute(test, hints.updateNullField(), pojos);
assertEquals(3, result.length);
assertEquals(3, getCount());
pojos = getAll();
for (ClientTestModel model : pojos) {
assertEquals(model.getQuantity().intValue(), -100);
assertEquals(0, model.getType().intValue());
assertNull(model.getDbIndex());
// The default value
// assertNotNull(model.getLastChanged());
assertNull(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 testUpdatableWithVersion.
@Test
public void testUpdatableWithVersion() 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());
long[] oldVer = new long[3];
int i = 0;
for (UpdatableVersionModel model : pojos) {
model.setAddress("1122334455");
oldVer[i++] = model.getLastChanged().getTime();
}
int[] result = execute(test, hints, pojos);
assertArrayEquals(new int[] { 1, 1, 1 }, result);
pojos = dao.query("1=1", new StatementParameters(), new DalHints());
i = 0;
for (UpdatableVersionModel model : pojos) {
assertEquals("1122334455", model.getAddress());
Assert.assertTrue(oldVer[i++] <= model.getLastChanged().getTime());
}
}
use of com.ctrip.platform.dal.dao.task.BatchUpdateTask in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testValidteUnchangedField.
@Test
public void testValidteUnchangedField() throws SQLException {
BatchUpdateTask<UpdatableClientTestModel> test = new BatchUpdateTask<>();
test.initialize(getParser(UpdatableClientTestModel.class));
DalHints hints = new DalHints();
try {
List<UpdatableClientTestModel> pojos = getAll(UpdatableClientTestModel.class);
int[] result = execute(test, hints, pojos);
fail();
} catch (SQLException e) {
assertEquals(e.getMessage(), ErrorCode.ValidateFieldCount.getMessage());
}
try {
List<UpdatableClientTestModel> pojos = getAll(UpdatableClientTestModel.class);
int[] result = execute(test, hints.updateUnchangedField(), pojos);
} catch (SQLException e) {
fail();
}
}
Aggregations