use of com.ctrip.platform.dal.dao.client.DalConnection in project dal by ctripcorp.
the class DalConnectionTest method testApplyHints.
@Test
public void testApplyHints() throws SQLException {
Connection conn = null;
try {
DalConnection test = getConnection();
DalHints hints = new DalHints();
hints.setIsolationLevel(Connection.TRANSACTION_SERIALIZABLE);
test.applyHints(hints);
conn = test.getConn();
assertTrue(conn.getTransactionIsolation() == Connection.TRANSACTION_SERIALIZABLE);
hints.setIsolationLevel(Connection.TRANSACTION_NONE);
test.applyHints(hints);
assertTrue(conn.getTransactionIsolation() == Connection.TRANSACTION_NONE);
} catch (Throwable e) {
fail();
e.printStackTrace();
} finally {
if (conn != null)
conn.close();
}
}
use of com.ctrip.platform.dal.dao.client.DalConnection 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.dao.client.DalConnection in project dal by ctripcorp.
the class ConnectionActionTest method testCleanupCloseConnectionNegative.
@Test
public void testCleanupCloseConnectionNegative() {
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(new NullPointerException("0800"));
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.dao.client.DalConnection in project dal by ctripcorp.
the class ConnectionActionTest method getDalConnection.
private DalConnection getDalConnection() throws Exception {
Connection conn = null;
conn = DalClientFactory.getDalConfigure().getLocator().getConnection(connectionString);
return new DalConnection(conn, true, null, DbMeta.createIfAbsent(connectionString, DalClientFactory.getDalConfigure().getDatabaseSet(connectionString).getDatabaseCategory(), conn));
}
use of com.ctrip.platform.dal.dao.client.DalConnection in project dal by ctripcorp.
the class DalTransactionTest method getDalConnection.
private DalConnection getDalConnection() throws Exception {
Connection conn = null;
conn = DalClientFactory.getDalConfigure().getLocator().getConnection(logicDbName);
return new DalConnection(conn, true, null, DbMeta.createIfAbsent(logicDbName, null, conn));
}
Aggregations