use of com.ctrip.platform.dal.dao.task.SingleUpdateTask in project dal by ctripcorp.
the class SingleUpdateTaskTestStub method testExecuteUpdatableEntityNoChangeWithUpdateNoChangeHints.
@Test
public void testExecuteUpdatableEntityNoChangeWithUpdateNoChangeHints() throws SQLException, InterruptedException {
SingleUpdateTask<UpdatableClientTestModel> test = new SingleUpdateTask<>();
DalParser<UpdatableClientTestModel> parser = getParser(UpdatableClientTestModel.class);
test.initialize(parser);
DalHints hints = new DalHints();
try {
UpdatableClientTestModel model = getAll(UpdatableClientTestModel.class).get(0);
Timestamp version = model.getLastChanged();
System.out.println(version);
Thread.sleep(1000);
int result = test.execute(hints.updateUnchangedField(), parser.getFields(model), model);
assertIntEquals(1, result);
model = getDao(UpdatableClientTestModel.class).queryByPk(model, new DalHints());
System.out.println(model.getLastChanged());
Assert.assertTrue(model.getLastChanged().getTime() > version.getTime());
} catch (SQLException e) {
e.printStackTrace();
fail();
}
}
use of com.ctrip.platform.dal.dao.task.SingleUpdateTask in project dal by ctripcorp.
the class SingleUpdateTaskTestStub method testExecuteUpdatableEntity.
@Test
public void testExecuteUpdatableEntity() throws SQLException {
SingleUpdateTask<UpdatableClientTestModel> test = new SingleUpdateTask<>();
DalParser<UpdatableClientTestModel> parser = getParser(UpdatableClientTestModel.class);
test.initialize(parser);
DalHints hints = new DalHints();
try {
UpdatableClientTestModel model = getAll(UpdatableClientTestModel.class).get(0);
model.setAddress("1122334455");
ClientTestModel oldModel = getAll().get(0);
oldModel.setQuantity(1000);
oldModel.setTableIndex(1000);
oldModel.setDbIndex(1000);
// This is ignored by default
oldModel.setType(null);
getDao().update(hints, oldModel);
int result = test.execute(hints, parser.getFields(model), model);
assertIntEquals(1, result);
model = getDao(UpdatableClientTestModel.class).queryByPk(model, new DalHints());
assertEquals("1122334455", model.getAddress());
assertEquals(1000, model.getQuantity().intValue());
assertEquals(1000, model.getDbIndex().intValue());
assertEquals(1000, model.getTableIndex().intValue());
Assert.assertNotNull(model.getType());
} catch (SQLException e) {
e.printStackTrace();
fail();
}
}
use of com.ctrip.platform.dal.dao.task.SingleUpdateTask in project dal by ctripcorp.
the class SingleUpdateTaskTestStub method testVersionIncorrect.
@Test
public void testVersionIncorrect() throws SQLException {
SingleUpdateTask<UpdatableVersionModel> test = new SingleUpdateTask<>();
DalParser<UpdatableVersionModel> parser = new DalDefaultJpaParser<>(UpdatableVersionModel.class, getDbName());
test.initialize(parser);
DalHints hints = new DalHints();
UpdatableVersionModel model = getAll(UpdatableVersionModel.class).get(0);
model.setAddress("1122334455");
Timestamp t = model.getLastChanged();
t.setTime(t.getTime() + 100);
model.setLastChanged(t);
int result = test.execute(hints, getFields(model), model);
assertIntEquals(0, result);
model = getDao(UpdatableVersionModel.class).queryByPk(model, new DalHints());
assertEquals("SH INFO", model.getAddress());
}
use of com.ctrip.platform.dal.dao.task.SingleUpdateTask in project dal by ctripcorp.
the class SingleUpdateTaskTestStub method testNotUpdatableField.
@Test
public void testNotUpdatableField() throws SQLException {
//Table Index and Address is not updatable
SingleUpdateTask<NonUpdatableModel> test = new SingleUpdateTask<>();
DalParser<NonUpdatableModel> parser = new DalDefaultJpaParser<>(NonUpdatableModel.class, getDbName());
test.initialize(parser);
DalHints hints = new DalHints();
NonUpdatableModel model = getAll(NonUpdatableModel.class).get(0);
String oldAddr = model.getAddress();
Integer oldTableIndex = model.getTableIndex();
model.setDbIndex(-100);
model.setAddress("1122334455");
model.setTableIndex(100);
int result = test.execute(hints, getFields(model), model);
assertIntEquals(1, result);
model = getDao(NonUpdatableModel.class).queryByPk(model, new DalHints());
assertEquals(oldAddr, model.getAddress());
assertEquals(oldTableIndex, model.getTableIndex());
assertEquals(-100, model.getDbIndex().intValue());
}
use of com.ctrip.platform.dal.dao.task.SingleUpdateTask in project dal by ctripcorp.
the class SingleUpdateTaskTestStub method testIncludeColumns.
@Test
public void testIncludeColumns() throws SQLException {
//Table Index and Address is not updatable
SingleUpdateTask<NonUpdatableModel> test = new SingleUpdateTask<>();
DalParser<NonUpdatableModel> parser = new DalDefaultJpaParser<>(NonUpdatableModel.class, getDbName());
test.initialize(parser);
DalHints hints = new DalHints();
NonUpdatableModel model = getAll(NonUpdatableModel.class).get(0);
String oldAddr = model.getAddress();
Integer oldTableIndex = model.getTableIndex();
Integer oldQuantity = model.getQuantity();
model.setDbIndex(-100);
model.setAddress("1122334455");
model.setTableIndex(100);
model.setQuantity(500);
model.setType((short) 8);
int result = test.execute(hints.include("dbIndex", "type"), getFields(model), model);
assertIntEquals(1, result);
model = getDao(NonUpdatableModel.class).queryByPk(model, new DalHints());
assertEquals(oldAddr, model.getAddress());
assertEquals(oldTableIndex, model.getTableIndex());
assertEquals(oldQuantity, model.getQuantity());
assertEquals(-100, model.getDbIndex().intValue());
assertEquals(8, model.getType().shortValue());
}
Aggregations