use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testUpdatableWithIntVersion.
@Test
public void testUpdatableWithIntVersion() 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();
Integer[] oldValue = new Integer[3];
List<UpdatableIntVersionModel> pojos = dao.query("1=1", new StatementParameters(), new DalHints());
int i = 0;
for (UpdatableIntVersionModel model : pojos) {
model.setAddress("1122334455");
oldValue[i++] = model.getTableIndex();
}
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 (UpdatableIntVersionModel model : pojos) {
assertEquals("1122334455", model.getAddress());
Assert.assertTrue(oldValue[i++] + 1 == model.getTableIndex());
}
}
use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.
the class BatchInsertTaskTestStub method testExecuteWithNonInsertable.
@Test
public void testExecuteWithNonInsertable() throws SQLException, InterruptedException {
BatchInsertTask<NonInsertableVersionModel> test = new BatchInsertTask<>();
DalParser<NonInsertableVersionModel> parser = new DalDefaultJpaParser<>(NonInsertableVersionModel.class, getDbName());
test.initialize(parser);
DalHints hints = new DalHints();
try {
List<ClientTestModel> old = getAll();
Thread.sleep(1000);
BulkTaskContext<NonInsertableVersionModel> ctx = test.createTaskContext(hints, test.getPojosFields(getAll(NonInsertableVersionModel.class)), getAll(NonInsertableVersionModel.class));
test.execute(hints, getAllMap(), ctx);
assertEquals(3 + 3, getCount());
List<ClientTestModel> newModel = getAll().subList(3, 6);
for (int i = 0; i < 3; i++) {
assertTrue(newModel.get(i).getLastChanged().getTime() > old.get(i).getLastChanged().getTime());
}
} catch (SQLException e) {
e.printStackTrace();
fail();
}
Map<Integer, Map<String, ?>> pojos = getAllMap();
for (Map<String, ?> pojo : pojos.values()) {
assertNotNull(pojo.get("last_changed"));
}
}
use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.
the class BatchInsertTaskTestStub method testExecuteNullColumns.
@Test
public void testExecuteNullColumns() throws SQLException {
BatchInsertTask<NonInsertableVersionModel> test = new BatchInsertTask<>();
DalParser<NonInsertableVersionModel> parser = new DalDefaultJpaParser<>(NonInsertableVersionModel.class, getDbName());
test.initialize(parser);
DalHints hints = new DalHints();
try {
List<NonInsertableVersionModel> models = getAll(NonInsertableVersionModel.class);
BulkTaskContext<NonInsertableVersionModel> ctx = test.createTaskContext(hints, test.getPojosFields(models), models);
for (NonInsertableVersionModel model : models) {
model.setType(null);
model.setDbIndex(null);
model.setTableIndex(null);
}
// Type Address, tableIndex will not be included in insert
test.execute(hints, test.getPojosFieldsMap(models), ctx);
assertEquals(3 + 3, getCount());
models = getAll(NonInsertableVersionModel.class).subList(3, 6);
for (NonInsertableVersionModel model : models) {
assertNull(model.getType());
assertNull(model.getTableIndex());
assertNull(model.getDbIndex());
}
} catch (SQLException e) {
e.printStackTrace();
fail();
}
Map<Integer, Map<String, ?>> pojos = getAllMap();
for (Map<String, ?> pojo : pojos.values()) {
assertNotNull(pojo.get("last_changed"));
}
}
use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.
the class CombinedInsertTaskTestStub method testExecuteWithNonInsertable.
@Test
public void testExecuteWithNonInsertable() throws SQLException {
CombinedInsertTask<NonInsertableVersionModel> test = new CombinedInsertTask<>();
DalParser<NonInsertableVersionModel> parser = new DalDefaultJpaParser<>(NonInsertableVersionModel.class, getDbName());
test.initialize(parser);
DalHints hints = new DalHints();
if (enableKeyHolder)
hints.setKeyHolder(new KeyHolder());
try {
execute(test, hints, getAllMap(), getAll(NonInsertableVersionModel.class));
if (enableKeyHolder) {
// You have to merge before get size
assertEquals(3, hints.getKeyHolder().size());
}
assertEquals(3 + 3, getCount());
} catch (SQLException e) {
e.printStackTrace();
fail();
}
Map<Integer, Map<String, ?>> pojos = getAllMap();
for (Map<String, ?> pojo : pojos.values()) {
assertNotNull(pojo.get("last_changed"));
}
}
use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser 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());
}
}
Aggregations