use of com.ctrip.platform.dal.dao.helper.DefaultResultCallback 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.helper.DefaultResultCallback in project dal by ctripcorp.
the class BaseDalTabelDaoShardByTableTest method testQueryTopWithWhereClauseFailedCallback.
@Test
public void testQueryTopWithWhereClauseFailedCallback() throws SQLException {
String whereClause = "type=?";
StatementParameters parameters = new StatementParameters();
parameters.set(1, Types.SMALLINT, 10);
List<ClientTestModel> models;
DefaultResultCallback callback = new DefaultResultCallback();
DalHints hints = new DalHints().callbackWith(callback);
models = dao.queryTop(whereClause, parameters, hints, 2);
try {
callback.waitForDone();
} catch (InterruptedException e) {
e.printStackTrace();
}
assertTrue(!callback.isSuccess());
assertNull(callback.getResult());
assertNotNull(callback.getError());
models = dao.queryTop(whereClause, parameters, new DalHints().inTableShard(1), 2);
assertTrue(null != models);
assertEquals(0, models.size());
}
use of com.ctrip.platform.dal.dao.helper.DefaultResultCallback in project dal by ctripcorp.
the class BaseDalTabelDaoShardByTableTest method testBatchUpdateCallback.
@Test
public void testBatchUpdateCallback() throws SQLException {
DefaultResultCallback callback = new DefaultResultCallback();
DalHints hints = new DalHints().callbackWith(callback);
List<ClientTestModel> entities = new ArrayList<>();
for (int i = 0; i < 4; i++) {
ClientTestModel model = new ClientTestModel();
model.setId(i + 1);
model.setAddress("CTRIP");
entities.add(model);
}
int[] res;
try {
res = dao.batchUpdate(hints, entities);
callback.waitForDone();
assertTrue(!callback.isSuccess());
} catch (Exception e) {
fail();
}
// By fields same shard
// holder = new KeyHolder();
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");
entities.get(3).setTableIndex(0);
entities.get(3).setAddress("1234");
dao.batchUpdate(new DalHints(), entities);
List<ClientTestModel> result = dao.query("1=1", new StatementParameters(), new DalHints().inTableShard(0));
for (ClientTestModel m : result) assertEquals("1234", m.getAddress());
}
use of com.ctrip.platform.dal.dao.helper.DefaultResultCallback in project dal by ctripcorp.
the class DalRequestExecutorTest method testExecuteCallback.
@Test
public void testExecuteCallback() {
DalRequestExecutor test = new DalRequestExecutor();
TestDalRequest request = new TestDalRequest(null, new Integer[] { 1 });
DalHints hints = new DalHints();
DefaultResultCallback callback = new DefaultResultCallback();
try {
Integer result = test.execute(hints.callbackWith(callback), request, true);
assertNull(result);
assertEquals(1, ((Integer) hints.getAsyncResult().get()).intValue());
assertEquals(1, ((Integer) callback.getResult()).intValue());
} catch (Exception e) {
fail();
}
}
use of com.ctrip.platform.dal.dao.helper.DefaultResultCallback in project dal by ctripcorp.
the class BaseDalTabelDaoShardByTableTest method testQueryFirstWithWhereClauseFailedCallback.
@Test
public void testQueryFirstWithWhereClauseFailedCallback() throws SQLException {
DalHints hints;
DefaultResultCallback callback;
String whereClause = "type=?";
StatementParameters parameters = new StatementParameters();
parameters.set(1, Types.SMALLINT, 10);
try {
callback = new DefaultResultCallback();
hints = new DalHints().callbackWith(callback);
Object model = dao.queryFirst(whereClause, parameters, hints.inTableShard(1));
callback.waitForDone();
assertNull(callback.getResult());
} catch (Throwable e) {
fail();
}
}
Aggregations