use of javax.sql.PooledConnection in project geode by apache.
the class ConnectionPoolCacheImpl method getNewPoolConnection.
/**
* Creates a new connection for the pool.
*
* @return the connection from the database as Object.
* @throws PoolException
*/
@Override
public Object getNewPoolConnection() throws PoolException {
if (m_cpds != null) {
PooledConnection poolConn = null;
try {
poolConn = m_cpds.getPooledConnection(configProps.getUser(), configProps.getPassword());
} catch (SQLException sqx) {
throw new PoolException(LocalizedStrings.ConnectionPoolCacheImpl_CONNECTIONPOOLCACHEIMPLGENEWCONNECTION_EXCEPTION_IN_CREATING_NEW_POOLEDCONNECTION.toLocalizedString(), sqx);
}
poolConn.addConnectionEventListener((javax.sql.ConnectionEventListener) connEventListner);
return poolConn;
} else {
if (logger.isDebugEnabled()) {
logger.debug("ConnectionPoolCacheImpl::geNewConnection: ConnectionPoolCache not intialized with ConnectionPoolDatasource");
}
throw new PoolException(LocalizedStrings.ConnectionPoolCacheImpl_CONNECTIONPOOLCACHEIMPLGENEWCONNECTION_CONNECTIONPOOLCACHE_NOT_INTIALIZED_WITH_CONNECTIONPOOLDATASOURCE.toLocalizedString());
}
}
use of javax.sql.PooledConnection in project geode by apache.
the class GemFireConnPooledDataSource method connectionErrorOccurred.
/**
* Implementation of call back function from ConnectionEventListener interface. This callback will
* be invoked on connection error event.
*
* @param event
*/
public void connectionErrorOccurred(ConnectionEvent event) {
if (isActive) {
try {
PooledConnection conn = (PooledConnection) event.getSource();
provider.returnAndExpireConnection(conn);
} catch (Exception ex) {
String exception = "GemFireConnPooledDataSource::connectionErrorOccurred:error in returning and expiring connection due to " + ex;
if (logger.isDebugEnabled()) {
logger.debug(exception, ex);
}
}
}
}
use of javax.sql.PooledConnection in project geode by apache.
the class GemFireConnPooledDataSource method connectionClosed.
/**
* Implementation of call back function from ConnectionEventListener interface. This callback will
* be invoked on connection close event.
*
* @param event
*/
public void connectionClosed(ConnectionEvent event) {
if (isActive) {
try {
PooledConnection conn = (PooledConnection) event.getSource();
provider.returnConnection(conn);
} catch (Exception ex) {
String exception = "GemFireConnPooledDataSource::connectionclosed:Exception =" + ex;
if (logger.isDebugEnabled()) {
logger.debug(exception, ex);
}
}
}
}
use of javax.sql.PooledConnection in project spanner-jdbc by olavloite.
the class CloudSpannerPooledConnection method getConnection.
/**
* Gets a handle for a client to use. This is a wrapper around the physical
* connection, so the client can call close and it will just return the
* connection to the pool without really closing the physical connection.
*
* <p>
* According to the JDBC 2.0 Optional Package spec (6.2.3), only one client
* may have an active handle to the connection at a time, so if there is a
* previous handle active when this is called, the previous one is forcibly
* closed and its work rolled back.
* </p>
*/
@Override
public ICloudSpannerConnection getConnection() throws SQLException {
if (con == null) {
// Before throwing the exception, let's notify the registered
// listeners about the error
SQLException sqlException = new CloudSpannerSQLException("This PooledConnection has already been closed.", Code.FAILED_PRECONDITION);
fireConnectionFatalError(sqlException);
throw sqlException;
}
// eliminate bad pooled connections.
try {
// Package spec section 6.2.3
if (last != null) {
last.close();
if (!con.getAutoCommit()) {
rollbackAndIgnoreException();
}
con.clearWarnings();
}
/*
* In XA-mode, autocommit is handled in PGXAConnection, because it
* depends on whether an XA-transaction is open or not
*/
if (!isXA) {
con.setAutoCommit(autoCommit);
}
} catch (SQLException sqlException) {
fireConnectionFatalError(sqlException);
throw (SQLException) sqlException.fillInStackTrace();
}
ConnectionHandler handler = new ConnectionHandler(con);
last = handler;
ICloudSpannerConnection proxyCon = (ICloudSpannerConnection) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { Connection.class, ICloudSpannerConnection.class }, handler);
last.setProxy(proxyCon);
return proxyCon;
}
use of javax.sql.PooledConnection in project tomcat by apache.
the class Bug54227 method testPool.
@Test
public void testPool() throws SQLException, InterruptedException {
PoolProperties poolProperties = new DefaultProperties();
poolProperties.setMinIdle(0);
poolProperties.setInitialSize(0);
poolProperties.setMaxActive(1);
poolProperties.setMaxWait(5000);
poolProperties.setMaxAge(100);
poolProperties.setRemoveAbandoned(false);
final DataSource ds = new DataSource(poolProperties);
Connection con;
Connection actual1;
Connection actual2;
con = ds.getConnection();
actual1 = ((PooledConnection) con).getConnection();
con.close();
con = ds.getConnection();
actual2 = ((PooledConnection) con).getConnection();
assertSame(actual1, actual2);
con.close();
Thread.sleep(150);
con = ds.getConnection();
actual2 = ((PooledConnection) con).getConnection();
assertNotSame(actual1, actual2);
con.close();
}
Aggregations