use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser 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.helper.DalDefaultJpaParser in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testExcludeColumns.
@Test
public void testExcludeColumns() 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");
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());
}
}
use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testVersionIncorrect.
@Test
public void testVersionIncorrect() 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");
Timestamp t = model.getLastChanged();
t.setTime(t.getTime() + 100);
model.setLastChanged(t);
}
int[] result = execute(test, hints, pojos);
assertArrayEquals(new int[] { 0, 0, 0 }, result);
pojos = dao.query("1=1", new StatementParameters(), new DalHints());
for (UpdatableVersionModel model : pojos) assertEquals("SH INFO", model.getAddress());
}
use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testIncludeColumns.
@Test
public void testIncludeColumns() 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().include("address", "quantity");
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());
}
}
use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testDaoIncludeColumns.
@Test
public void testDaoIncludeColumns() throws SQLException {
DalParser<UpdatableIntVersionModel> parser = new DalDefaultJpaParser<>(UpdatableIntVersionModel.class, getDbName());
DalTableDao<UpdatableIntVersionModel> dao = new DalTableDao<>(parser);
DalHints hints = new DalHints().include("address", "quantity");
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 = dao.batchUpdate(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