use of com.ctrip.platform.dal.exceptions.DalException in project dal by ctripcorp.
the class DalRequestExecutor method internalExecute.
private <T> T internalExecute(DalHints hints, DalRequest<T> request, boolean nullable) throws SQLException {
T result = null;
Throwable error = null;
LogContext logContext = logger.start(request);
try {
request.validate();
if (request.isCrossShard())
result = crossShardExecute(logContext, hints, request);
else
result = nonCrossShardExecute(logContext, hints, request);
if (result == null && !nullable)
throw new DalException(ErrorCode.AssertNull);
request.endExecution();
} catch (Throwable e) {
error = e;
}
logger.end(logContext, error);
handleCallback(hints, result, error);
if (error != null)
throw DalException.wrap(error);
return result;
}
use of com.ctrip.platform.dal.exceptions.DalException in project dal by ctripcorp.
the class ConnectionActionTest method testCleanupCloseConnection.
@Test
public void testCleanupCloseConnection() {
SQLException e1 = new SQLException("test discard", "1234");
e1.setNextException(new SQLException("test discard", "08006"));
SQLException e2 = new SQLException("test discard", "1234");
e2.setNextException(new SQLException("test discard", "08S01"));
Exception[] el = new Exception[] { // Case 1 detect direct SQLException
new SQLException("test discard", "08006"), // Case 2 detect embedded SQLException wrapped by DalException
new DalException("test discard", new SQLException("test discard", "08006")), // Case 3 detect embedded SQLException wrapped by NullPinterException
new RuntimeException("test discard", new SQLException("test discard", "08006")), // Case 4 detect embedded SQLException wrapped by NullPinterException
new RuntimeException("test discard", e1), // Case 1 detect direct SQLException
new SQLException("test discard", "08006"), // Case 2 detect embedded SQLException wrapped by DalException
new DalException("test discard", new SQLException("test discard", "08006")), // Case 3 detect embedded SQLException wrapped by NullPinterException
new RuntimeException("test discard", new SQLException("test discard", "08006")), // Case 4 detect embedded SQLException wrapped by NullPinterException
new RuntimeException("test discard", e2) };
for (Exception e : el) {
try {
TestConnectionAction test = new TestConnectionAction();
DalConnection connHolder = getDalConnection();
test.connHolder = connHolder;
test.statement = test.connHolder.getConn().createStatement();
test.rs = test.statement.executeQuery("select * from " + SqlServerTestInitializer.TABLE_NAME);
test.rs.next();
PooledConnection c = (PooledConnection) connHolder.getConn().unwrap(PooledConnection.class);
connHolder.error(e);
test.cleanup();
assertTrue(c.isDiscarded());
assertTrue(c.isReleased());
assertNotNull(test);
assertTrue(test.conn == null);
assertTrue(test.statement == null);
assertTrue(test.rs == null);
assertTrue(test.connHolder == null);
} catch (Exception ex) {
ex.printStackTrace();
fail("There should be no exception here");
}
}
}
use of com.ctrip.platform.dal.exceptions.DalException in project dal by ctripcorp.
the class DalSingleResultExtractor method extract.
@Override
public T extract(ResultSet rs) throws SQLException {
T result = null;
checkHints(rs);
if (rs.next()) {
result = mapper.map(rs, 0);
if (rs.next() && requireSingle)
throw new DalException(ErrorCode.AssertSingle);
}
return result;
}
use of com.ctrip.platform.dal.exceptions.DalException in project dal by ctripcorp.
the class DalTransaction method endTransaction.
public void endTransaction(int startLevel) throws SQLException {
if (rolledBack || completed)
throw new DalException(ErrorCode.TransactionState);
if (startLevel != (level - 1)) {
rollbackTransaction();
throw new DalException(ErrorCode.TransactionLevelMatch, (level - 1), startLevel);
}
if (level > 1) {
level--;
return;
}
// Back to the first transaction, about to commit
beforeCommit();
level = 0;
completed = true;
cleanup(true);
afterCommit();
}
use of com.ctrip.platform.dal.exceptions.DalException in project dal by ctripcorp.
the class PartialQueryQueryDaoTest method testIgnorMissingFields.
@Test
public void testIgnorMissingFields() 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();
FreeEntityPartialPojo ret;
try {
hints = new DalHints();
ret = findFreeFirstBigger(name, cityIds, hints.inShard(1).partialQuery("PeopleID", "Name", "CityID", "ProvinceID"));
fail();
} catch (DalException e) {
Assert.assertEquals(ErrorCode.FieldNotExists.getCode(), e.getErrorCode());
}
hints = new DalHints().ignoreMissingFields().partialQuery("PeopleID", "Name", "CityID", "ProvinceID");
ret = findFreeFirstBigger(name, cityIds, hints.inShard(1));
assertNotNull(ret);
hints = new DalHints().ignoreMissingFields().partialQuery("PeopleID", "Name", "CityID", "ProvinceID");
ret = findFreeFirstBigger(name, cityIds, hints.inAllShards());
assertNotNull(ret);
}
Aggregations