use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method testCrossShardDelete.
@Test
public void testCrossShardDelete() {
testCrossShardDelete(new DalHints());
testCrossShardDelete(asyncHints());
testCrossShardDelete(intHints());
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method testBatchUpdateByFields.
@Test
public void testBatchUpdateByFields() throws SQLException {
testBatchUpdateByFields(new DalHints());
testBatchUpdateByFields(asyncHints());
testBatchUpdateByFields(intHints());
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method batchDeleteTest.
private void batchDeleteTest(int shardId, int tableShardId, DalHints oldhints) throws SQLException {
int count = 1 + tableShardId;
Assert.assertEquals(count, getCount(shardId, tableShardId));
DalHints hints = copy(oldhints);
int[] res = dao.batchDelete(hints, getModels(shardId, tableShardId));
res = assertIntArray(res, hints);
int[] exp = new int[count];
for (int i = 0; i < count; i++) exp[i] = 1;
assertResEquals(exp, res);
Assert.assertEquals(0, getCount(shardId, tableShardId));
hints = copy(oldhints);
res = dao.insert(hints, create(count));
res = assertIntArray(res, hints);
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method testQueryByPkWithEntity.
private void testQueryByPkWithEntity(int shardId, DalHints oldHints) throws SQLException {
ClientTestModel pk = null;
ClientTestModel model = null;
DalHints hints;
for (int i = 0; i < tableMod; i++) {
int id = 1;
pk = new ClientTestModel();
pk.setId(1);
// By tabelShard
hints = copy(oldHints);
model = dao.queryByPk(pk, hints.inTableShard(i));
model = assertModel(model, hints);
assertQueryByPk(shardId, model, i, id);
// By tableShardValue
hints = copy(oldHints);
model = dao.queryByPk(pk, hints.setTableShardValue(i));
model = assertModel(model, hints);
assertQueryByPk(shardId, model, i, id);
// By shardColValue
hints = copy(oldHints);
model = dao.queryByPk(pk, hints.setShardColValue("table", i));
model = assertModel(model, hints);
assertQueryByPk(shardId, model, i, id);
// By shardColValue
hints = copy(oldHints);
model = dao.queryByPk(pk, hints.setShardColValue("tableIndex", i));
model = assertModel(model, hints);
assertQueryByPk(shardId, model, i, id);
// By fields
pk.setTableIndex(i);
pk.setDbIndex(shardId);
hints = copy(oldHints);
model = dao.queryByPk(pk, hints);
model = assertModel(model, hints);
assertQueryByPk(shardId, model, i, id);
}
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTest method testBatchUpdateMultiple.
@Test
public void testBatchUpdateMultiple() throws SQLException {
DalHints hints = new DalHints();
List<ClientTestModel> entities = new ArrayList<>();
for (int i = 0; i < 3; i++) {
ClientTestModel model = new ClientTestModel();
model.setId(i + 1);
model.setAddress("CTRIP");
entities.add(model);
}
int[] ress;
try {
ress = dao.batchUpdate(hints, entities);
fail();
} catch (Exception e) {
}
// By fields same shard
// holder = createKeyHolder();
entities.get(0).setTableIndex(0);
entities.get(0).setAddress("1234");
entities.get(1).setTableIndex(0);
entities.get(1).setAddress("1234");
entities.get(2).setTableIndex(0);
entities.get(2).setAddress("1234");
ress = dao.batchUpdate(new DalHints(), entities);
assertResEquals(3, ress);
List<ClientTestModel> result = dao.query("1=1", new StatementParameters(), new DalHints().inShard(0));
for (ClientTestModel m : result) assertEquals("1234", m.getAddress());
}
Aggregations