use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method deleteAllShards.
public void deleteAllShards(int shardId) throws SQLException {
for (int i = 0; i < tableMod; i++) {
int j = 1;
dao.delete("1=1", new StatementParameters(), new DalHints().inShard(shardId).inTableShard(i));
}
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTest method testCrossShardDelete.
@Test
public void testCrossShardDelete() {
try {
int[] res;
ClientTestModel p = new ClientTestModel();
ClientTestModel[] pList = new ClientTestModel[6];
p = new ClientTestModel();
p.setId(1);
p.setAddress("aaa");
p.setTableIndex(0);
pList[0] = p;
p = new ClientTestModel();
p.setId(1);
p.setAddress("aaa");
p.setTableIndex(1);
pList[1] = p;
p = new ClientTestModel();
p.setId(2);
p.setAddress("aaa");
p.setTableIndex(2);
pList[2] = p;
p = new ClientTestModel();
p.setId(2);
p.setAddress("aaa");
p.setTableIndex(3);
pList[3] = p;
p = new ClientTestModel();
p.setId(3);
p.setAddress("aaa");
p.setTableIndex(5);
pList[4] = p;
p = new ClientTestModel();
p.setId(3);
p.setAddress("aaa");
p.setTableIndex(6);
pList[5] = p;
DalHints hints = new DalHints();
res = dao.batchDelete(hints, Arrays.asList(pList));
assertEquals(0, getCountByDb(dao, 0));
assertEquals(0, getCountByDb(dao, 1));
assertResEquals(new int[] { 1, 1, 1, 1, 1, 1 }, res);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTest method testUpdatePlainAllShardsAsync.
@Test
public void testUpdatePlainAllShardsAsync() throws SQLException {
String sql = "UPDATE " + TABLE_NAME + " SET address = 'CTRIP' WHERE id = 1";
StatementParameters parameters = new StatementParameters();
DalHints hints = new DalHints().asyncExecution();
int res;
// By allShards
sql = "UPDATE " + TABLE_NAME + " SET address = 'CTRIP' WHERE id = 1";
res = dao.update(sql, parameters, hints.inAllShards());
assertEquals(0, res);
res = getInt(hints);
assertResEquals(2, res);
assertEquals("CTRIP", dao.queryByPk(1, new DalHints().inShard(0)).getAddress());
assertEquals("CTRIP", dao.queryByPk(1, new DalHints().inShard(1)).getAddress());
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTest method testBatchUpdateMultipleCallback.
public void testBatchUpdateMultipleCallback() 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");
IntCallback callback = new IntCallback();
hints = new DalHints().callbackWith(callback);
ress = dao.batchUpdate(hints, entities);
assertNull(ress);
ress = callback.getIntArray();
assertResEquals(3, ress);
List<ClientTestModel> result = dao.query("1=1", new StatementParameters(), new DalHints().inShard(0));
for (ClientTestModel m : result) assertEquals("1234", m.getAddress());
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class ConnectionActionTest method testStart.
@Test
public void testStart() {
TestConnectionAction test = new TestConnectionAction();
test.initLogEntry(connectionString, new DalHints());
test.start();
assertTrue(test.start > 0);
}
Aggregations