use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class DalQueryDaoTestStub method testQueryWithClazz.
@Test
public void testQueryWithClazz() throws SQLException {
String sql = "SELECT quantity FROM " + TABLE_NAME;
StatementParameters param = new StatementParameters();
DalHints hints = new DalHints();
List<Integer> models = client.query(sql, param, hints, Integer.class);
Assert.assertEquals(ROW_COUNT, models.size());
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class DalTransactionManagerTest method testRegister.
@Test
public void testRegister() {
final DalHints hints = new DalHints();
final DalTransactionListener testListener = new DalTransactionListener() {
@Override
public void beforeCommit() {
}
@Override
public void beforeRollback() {
}
@Override
public void afterCommit() {
}
@Override
public void afterRollback() {
}
};
try {
final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
DalTransactionManager.register(testListener);
fail();
} catch (Exception e) {
}
try {
final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
ConnectionAction<?> action = new ConnectionAction<Object>() {
public Object execute() throws Exception {
DalTransactionManager.register(testListener);
return null;
}
};
action.operation = DalEventEnum.EXECUTE;
test.doInTransaction(action, hints);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class PartialQueryQueryDaoTest method testAllowPartial.
@Test
public void testAllowPartial() throws Exception {
// Test value here
String name = "Test";
List<Integer> cityIds = new ArrayList<>();
cityIds.add(1);
cityIds.add(2);
cityIds.add(3);
DalHints hints = new DalHints();
FreeEntityMismatchPojo ret;
try {
hints = new DalHints();
ret = findFreeFirstMismatch(name, cityIds, hints.inShard(1));
fail();
} catch (DalException e) {
Assert.assertEquals(ErrorCode.ResultMappingError.getCode(), e.getErrorCode());
}
hints = new DalHints().allowPartial();
ret = findFreeFirstMismatch(name, cityIds, hints.inShard(1));
assertNotNull(ret);
hints = new DalHints().allowPartial();
ret = findFreeFirstMismatch(name, cityIds, hints.inAllShards());
assertNotNull(ret);
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class DalTransactionManagerTest method testIsInTransaction.
@Test
public void testIsInTransaction() {
try {
final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
assertFalse(DalTransactionManager.isInTransaction());
ConnectionAction<?> action = new ConnectionAction<Object>() {
public Object execute() throws Exception {
Assert.assertTrue(DalTransactionManager.isInTransaction());
return null;
}
};
action.operation = DalEventEnum.EXECUTE;
test.doInTransaction(action, new DalHints());
} catch (Exception e) {
fail();
e.printStackTrace();
}
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class DalTransactionManagerTest method testClearCurrentTransaction.
@Test
public void testClearCurrentTransaction() {
final DalHints hints = new DalHints();
try {
final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
assertFalse(DalTransactionManager.isInTransaction());
ConnectionAction<?> action = new ConnectionAction<Object>() {
public Object execute() throws Exception {
assertNotNull(DalTransactionManager.getCurrentDbMeta());
return null;
}
};
action.operation = DalEventEnum.EXECUTE;
test.doInTransaction(action, hints);
} catch (Exception e) {
fail();
e.printStackTrace();
}
assertFalse(DalTransactionManager.isInTransaction());
assertNull(DalTransactionManager.getCurrentDbMeta());
}
Aggregations