use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class OracleValidConnectionChecker method isValidConnection.
public boolean isValidConnection(Connection conn, String validateQuery, int validationQueryTimeout) throws Exception {
if (validateQuery == null || validateQuery.isEmpty()) {
validateQuery = this.defaultValidateQuery;
}
if (conn.isClosed()) {
return false;
}
if (conn instanceof DruidPooledConnection) {
conn = ((DruidPooledConnection) conn).getConnection();
}
if (conn instanceof ConnectionProxy) {
conn = ((ConnectionProxy) conn).getRawObject();
}
if (validateQuery == null || validateQuery.isEmpty()) {
return true;
}
int queryTimeout = validationQueryTimeout <= 0 ? timeout : validationQueryTimeout;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
stmt.setQueryTimeout(queryTimeout);
rs = stmt.executeQuery(validateQuery);
return true;
} finally {
JdbcUtils.close(rs);
JdbcUtils.close(stmt);
}
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DruidXADataSource method getXAConnection.
@Override
public XAConnection getXAConnection() throws SQLException {
DruidPooledConnection conn = this.getConnection();
Connection physicalConn = conn.unwrap(Connection.class);
XAConnection rawXAConnection = createPhysicalXAConnection(physicalConn);
return new DruidPooledXAConnection(conn, rawXAConnection);
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DruidConnectionHolderTest4 method test_toString.
public void test_toString() throws Exception {
DruidPooledConnection conn = dataSource.getConnection();
DruidConnectionHolder holder = conn.getConnectionHolder();
Field field = DruidConnectionHolder.class.getDeclaredField("statementPool");
field.setAccessible(true);
Assert.assertNull(field.get(holder));
holder.toString();
Assert.assertNull(field.get(holder));
holder.getStatementPool();
Assert.assertNotNull(field.get(holder));
holder.toString();
PreparedStatement stmt = conn.prepareStatement("select 1");
stmt.execute();
stmt.close();
conn.close();
Assert.assertEquals(1, holder.getStatementPool().size());
holder.toString();
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DruidDataSourceTest_getPooledConnection method test_event_error.
public void test_event_error() throws Exception {
DruidPooledConnection conn = (DruidPooledConnection) dataSource.getPooledConnection();
final AtomicInteger errorCount = new AtomicInteger();
conn.addConnectionEventListener(new ConnectionEventListener() {
@Override
public void connectionErrorOccurred(ConnectionEvent event) {
errorCount.incrementAndGet();
}
@Override
public void connectionClosed(ConnectionEvent event) {
}
});
PreparedStatement stmt = conn.prepareStatement("select ?");
try {
stmt.executeQuery();
} catch (SQLException e) {
}
Assert.assertEquals(1, errorCount.get());
conn.close();
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class DruidDataSourceTest_recycle2 method test_recycle.
public void test_recycle() throws Exception {
DruidPooledConnection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("select 1");
Assert.assertEquals(0, dataSource.getPoolingCount());
Assert.assertEquals(1, dataSource.getActiveCount());
conn.close();
Assert.assertEquals(1, dataSource.getPoolingCount());
Assert.assertEquals(0, dataSource.getActiveCount());
}
Aggregations