use of com.ctrip.platform.dal.dao.KeyHolder in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method testCombinedInsertFail.
private void testCombinedInsertFail(DalHints hints) throws SQLException {
reset();
List<ClientTestModel> entities = create(3);
KeyHolder holder = createKeyHolder();
int res;
try {
hints = copy(hints);
res = dao.combinedInsert(hints, holder, entities);
res = assertInt(res, hints);
Assert.fail();
} catch (Exception e) {
}
}
use of com.ctrip.platform.dal.dao.KeyHolder in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method testInsertMultipleAsListWithKeyHolderFail.
private void testInsertMultipleAsListWithKeyHolderFail(DalHints hints) throws SQLException {
reset();
List<ClientTestModel> entities = createListNoId(3);
KeyHolder holder = createKeyHolder();
int[] res;
try {
hints = copy(hints);
res = dao.insert(hints, holder, entities);
res = assertIntArray(res, hints);
Assert.fail();
} catch (Exception e) {
}
}
use of com.ctrip.platform.dal.dao.KeyHolder in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method testInsertMultipleAsListWithKeyHolderByFields.
private void testInsertMultipleAsListWithKeyHolderByFields(DalHints hints) throws SQLException {
reset();
List<ClientTestModel> entities = createListNoId(3);
int[] res;
KeyHolder holder = createKeyHolder();
deleteAllShardsByDbTable(dao, mod, tableMod);
// By fields not same shard
holder = createKeyHolder();
entities.get(0).setTableIndex(0);
entities.get(0).setDbIndex(0);
entities.get(1).setTableIndex(1);
entities.get(1).setDbIndex(1);
entities.get(2).setTableIndex(2);
entities.get(2).setDbIndex(2);
hints = copy(hints);
res = dao.insert(hints, holder, entities);
res = assertIntArray(res, hints);
assertResEquals(3, res);
Assert.assertEquals(1, getCount(0, 0));
Assert.assertEquals(1, getCount(1, 1));
Assert.assertEquals(1, getCount(0, 2));
assertKeyHolder(holder);
}
use of com.ctrip.platform.dal.dao.KeyHolder in project dal by ctripcorp.
the class CombinedInsertTaskTestStub method testExecuteWithId.
@Test
public void testExecuteWithId() {
CombinedInsertTask<ClientTestModel> test = new CombinedInsertTask<>();
test.initialize(new ClientTestDalParser(getDbName()));
DalHints hints = new DalHints().enableIdentityInsert();
if (enableKeyHolder)
hints.setKeyHolder(new KeyHolder());
try {
if (this instanceof CombinedInsertTaskSqlSvrTest)
SqlServerTestInitializer.turnOnIdentityInsert();
List<ClientTestModel> pojos = getAll();
int i = 111;
for (ClientTestModel pojo : pojos) {
pojo.setId(new Integer(i++));
}
execute(test, hints, null, pojos);
assertEquals(6, getCount());
pojos = getAll();
Set<Integer> ids = new HashSet<>();
for (ClientTestModel pojo : pojos) {
ids.add(pojo.getId());
}
assertTrue(ids.contains(111));
assertTrue(ids.contains(112));
assertTrue(ids.contains(113));
if (enableKeyHolder) {
// You have to merge before get size
assertEquals(3, hints.getKeyHolder().size());
}
assertEquals(3 + 3, getCount());
if (this instanceof CombinedInsertTaskSqlSvrTest)
SqlServerTestInitializer.turnOffIdentityInsert();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of com.ctrip.platform.dal.dao.KeyHolder 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"));
}
}
Aggregations