use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class DalQueryDaoTest method testQueryTopAllShardsWithClassAsync.
@Test
public void testQueryTopAllShardsWithClassAsync() {
try {
DalHints hints = new DalHints();
List<Integer> result = dao.queryTop(sqlListQuantity, parameters(), hints.inAllShards().asyncExecution(), Integer.class, 4);
assertNull(result);
Future<List<Integer>> fr = (Future<List<Integer>>) hints.getAsyncResult();
result = fr.get();
assertEquals(4, result.size());
Integer t = result.get(0);
assertEquals(new Integer(10), t);
} catch (Exception e) {
fail();
}
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class DalTableDaoShardByDbTableSqlSvrTest method tearDown.
@After
public void tearDown() throws SQLException {
String sql = "DELETE FROM " + TABLE_NAME;
StatementParameters parameters = new StatementParameters();
DalHints hints = new DalHints();
sql = "DELETE FROM " + TABLE_NAME;
parameters = new StatementParameters();
hints = new DalHints();
try {
for (int j = 0; j < mod; j++) {
for (int i = 0; i < tableMod; i++) {
clientSqlSvr.update(sql + "_" + i, parameters, hints.inShard(j));
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method testCrossShardDelete.
public void testCrossShardDelete(DalHints oldhints) {
try {
reset();
for (int i = 0; i < mod; i++) {
for (int j = 0; j < tableMod; j++) {
Assert.assertEquals(j + 1, getCount(i, j));
}
}
ClientTestModel[] pList = new ClientTestModel[mod * (1 + tableMod) * tableMod / 2];
int x = 0;
for (int i = 0; i < mod; i++) {
for (int j = 0; j < tableMod; j++) {
for (int k = 0; k < j + 1; k++) {
ClientTestModel p = new ClientTestModel();
p = new ClientTestModel();
p.setId(1 + k);
p.setAddress("aaa");
p.setDbIndex(i);
p.setTableIndex(j);
pList[x++] = p;
}
}
}
DalHints hints = copy(oldhints);
int[] res = dao.batchDelete(hints, Arrays.asList(pList));
assertIntArray(res, hints);
for (int i = 0; i < mod; i++) {
for (int j = 0; j < tableMod; j++) {
Assert.assertEquals(0, getCount(i, j));
}
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method copy.
private DalHints copy(DalHints oldhints) {
DalHints hints = oldhints.clone();
if (hints.is(DalHintEnum.resultCallback)) {
DefaultResultCallback callback = (DefaultResultCallback) hints.get(DalHintEnum.resultCallback);
callback.reset();
}
return hints;
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTabelDaoShardByTableTest method testInsertMultipleAsListAsyncCallback.
@Test
public void testInsertMultipleAsListAsyncCallback() throws SQLException {
List<ClientTestModel> entities = new ArrayList<ClientTestModel>();
DalHints hints;
for (int i = 0; i < 3; i++) {
ClientTestModel model = new ClientTestModel();
model.setQuantity(10 + 1 % 3);
model.setType(((Number) (1 % 3)).shortValue());
model.setAddress("CTRIP");
entities.add(model);
}
int[] res;
try {
hints = new DalHints().asyncExecution();
res = dao.insert(hints, entities);
res = assertIntArray(res, hints);
fail();
} catch (Exception e) {
}
for (int i = 0; i < mod; i++) {
int j = 1;
// By tabelShard
hints = asyncHints();
res = dao.insert(hints.inTableShard(i), entities);
res = assertIntArray(res, hints);
assertEquals((i + 1) + j++ * 3, getCount(i));
// By tableShardValue
hints = intHints();
res = dao.insert(hints.setTableShardValue(i), entities);
res = assertIntArray(res, hints);
assertEquals((i + 1) + j++ * 3, getCount(i));
// By shardColValue
hints = asyncHints();
res = dao.insert(hints.setShardColValue("index", i), entities);
res = assertIntArray(res, hints);
assertEquals((i + 1) + j++ * 3, getCount(i));
// By shardColValue
hints = intHints();
res = dao.insert(hints.setShardColValue("tableIndex", i), entities);
res = assertIntArray(res, hints);
assertEquals((i + 1) + j++ * 3, getCount(i));
// By fields same shard
hints = asyncHints();
entities.get(0).setTableIndex(i);
entities.get(1).setTableIndex(i);
entities.get(2).setTableIndex(i);
res = dao.insert(hints, entities);
res = assertIntArray(res, hints);
assertEquals((i + 1) + j++ * 3, getCount(i));
}
deleteAllShards();
// By fields not same shard
entities.get(0).setTableIndex(0);
entities.get(1).setTableIndex(1);
entities.get(2).setTableIndex(2);
hints = intHints();
res = dao.insert(hints.continueOnError(), entities);
res = assertIntArray(res, hints);
assertEquals(1, getCount(0));
assertEquals(1, getCount(1));
assertEquals(1, getCount(2));
}
Aggregations