use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.
the class SingleUpdateTaskTestStub method testIncludeColumnsByDao.
@Test
public void testIncludeColumnsByDao() throws SQLException {
//Table Index and Address is not updatable
DalParser<NonUpdatableModel> parser = new DalDefaultJpaParser<>(NonUpdatableModel.class, getDbName());
DalHints hints = new DalHints();
DalTableDao<NonUpdatableModel> dao = new DalTableDao<>(parser);
NonUpdatableModel model = dao.query("1=1", new StatementParameters(), new DalHints()).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 = dao.update(hints.include("dbIndex", "type"), model);
assertIntEquals(1, result);
model = dao.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());
}
use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.
the class DalDefaultJpaParserTest method testConstructByDbname.
@Test
public void testConstructByDbname() throws Exception {
DalParser<PersonEntity> parser = new DalDefaultJpaParser(PersonEntity.class);
Assert.assertEquals("dao_test_M", parser.getDatabaseName());
Assert.assertEquals("person", parser.getTableName());
String testDbName = "test";
String testTabeleName = "test2";
parser = new DalDefaultJpaParser(PersonEntity.class, testDbName);
Assert.assertEquals(testDbName, parser.getDatabaseName());
Assert.assertEquals("person", parser.getTableName());
parser = new DalDefaultJpaParser(PersonEntity.class, testDbName, testTabeleName);
Assert.assertEquals(testDbName, parser.getDatabaseName());
Assert.assertEquals(testTabeleName, parser.getTableName());
}
use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.
the class BatchUpdateTaskTestStub method testUpdatableWithIntVersionByDao.
@Test
public void testUpdatableWithIntVersionByDao() throws SQLException {
DalParser<UpdatableIntVersionModel> parser = new DalDefaultJpaParser<>(UpdatableIntVersionModel.class, getDbName());
DalTableDao<UpdatableIntVersionModel> dao = new DalTableDao<>(parser);
DalHints hints = new DalHints();
List<UpdatableIntVersionModel> pojos = dao.query("1=1", new StatementParameters(), new DalHints());
int i = 0;
for (UpdatableIntVersionModel model : pojos) {
model.setAddress("1122334455");
// Make the version incorrect
model.setTableIndex(-1);
}
int[] result = dao.batchUpdate(hints, pojos);
assertArrayEquals(new int[] { 0, 0, 0 }, result);
pojos = dao.query("1=1", new StatementParameters(), new DalHints());
for (UpdatableIntVersionModel model : pojos) //Still old value because version is incorrect
assertEquals("SH INFO", model.getAddress());
// Now the right case
Integer[] oldValue = new Integer[3];
pojos = dao.query("1=1", new StatementParameters(), new DalHints());
i = 0;
for (UpdatableIntVersionModel model : pojos) {
model.setAddress("1122334455");
oldValue[i++] = model.getTableIndex();
}
result = dao.batchUpdate(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 BatchUpdateTaskTestStub method testNotUpdatableVersion.
@Test
public void testNotUpdatableVersion() throws SQLException {
BatchUpdateTask<NonUpdatableVersionModel> test = new BatchUpdateTask<>();
DalParser<NonUpdatableVersionModel> parser = new DalDefaultJpaParser<>(NonUpdatableVersionModel.class, getDbName());
test.initialize(parser);
DalTableDao<NonUpdatableVersionModel> dao = new DalTableDao<>(parser);
DalHints hints = new DalHints();
List<NonUpdatableVersionModel> pojos = dao.query("1=1", new StatementParameters(), new DalHints());
for (NonUpdatableVersionModel model : pojos) {
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 (NonUpdatableVersionModel model : pojos) assertEquals("1122334455", model.getAddress());
}
use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.
the class DalDefaultJpaParserTest method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() throws Exception {
DalClientFactory.initClientFactory();
personParser = new DalDefaultJpaParser(PersonEntity.class);
allTypesParser = new DalDefaultJpaParser(AllTypesEntity.class);
}
Aggregations