本文整理匯總了Java中javax.sql.PooledConnection.addConnectionEventListener方法的典型用法代碼示例。如果您正苦於以下問題:Java PooledConnection.addConnectionEventListener方法的具體用法?Java PooledConnection.addConnectionEventListener怎麽用?Java PooledConnection.addConnectionEventListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.sql.PooledConnection
的用法示例。
在下文中一共展示了PooledConnection.addConnectionEventListener方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createNewConnection
import javax.sql.PooledConnection; //導入方法依賴的package包/類
private PooledConnection createNewConnection() throws SQLException {
PooledConnection pooledConnection;
// I have changed "size() + 1" to "size()". I don't know why
// we would want to report 1 more than the actual pool size,
// so I am assuming that this is a coding error. (The size
// method does return the actual size of an array). -blaine
logInfo("Connection created since no connections available and "
+ "pool has space for more connections. Pool size: " + size());
pooledConnection = this.connectionPoolDataSource.getPooledConnection();
pooledConnection.addConnectionEventListener(this);
return pooledConnection;
}
示例2: getConnection3
import javax.sql.PooledConnection; //導入方法依賴的package包/類
private synchronized Connection getConnection3() throws SQLException {
if (isDisposed) { // test again within synchronized lock
throw new IllegalStateException("Connection pool has been disposed.");
}
PooledConnection pconn;
if (!recycledConnections.isEmpty()) {
pconn = recycledConnections.remove();
} else {
pconn = dataSource.getPooledConnection();
pconn.addConnectionEventListener(poolConnectionEventListener);
}
Connection conn;
try {
// The JDBC driver may call ConnectionEventListener.connectionErrorOccurred()
// from within PooledConnection.getConnection(). To detect this within
// disposeConnection(), we temporarily set connectionInTransition.
connectionInTransition = pconn;
conn = pconn.getConnection();
} finally {
connectionInTransition = null;
}
activeConnections++;
assertInnerState();
return conn;
}
示例3: getNewPoolConnection
import javax.sql.PooledConnection; //導入方法依賴的package包/類
/**
* Creates a new connection for the pool. This connection can participate in the transactions.
*
* @return the connection from the database as PooledConnection object.
*/
@Override
public Object getNewPoolConnection() throws PoolException {
if (m_xads != null) {
PooledConnection poolConn = null;
try {
poolConn = m_xads.getXAConnection(configProps.getUser(), configProps.getPassword());
} catch (SQLException sqx) {
throw new PoolException(
LocalizedStrings.TranxPoolCacheImpl_TRANXPOOLCACHEIMPLGETNEWCONNECTION_EXCEPTION_IN_CREATING_NEW_TRANSACTION_POOLEDCONNECTION
.toLocalizedString(),
sqx);
}
poolConn.addConnectionEventListener((javax.sql.ConnectionEventListener) connEventListner);
return poolConn;
} else {
if (logger.isDebugEnabled()) {
logger.debug(
"TranxPoolCacheImpl::getNewConnection: ConnectionPoolCache not intialized with XADatasource");
}
throw new PoolException(
LocalizedStrings.TranxPoolCacheImpl_TRANXPOOLCACHEIMPLGETNEWCONNECTION_CONNECTIONPOOLCACHE_NOT_INTIALIZED_WITH_XADATASOURCE
.toLocalizedString());
}
}
示例4: getNewPoolConnection
import javax.sql.PooledConnection; //導入方法依賴的package包/類
/**
* 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());
}
}
示例5: testPacketTooLargeException
import javax.sql.PooledConnection; //導入方法依賴的package包/類
/**
* Tests that PacketTooLargeException doesn't clober the connection.
*
* @throws Exception
* if the test fails.
*/
public void testPacketTooLargeException() throws Exception {
final ConnectionEventListener conListener = new ConnectionListener();
PooledConnection pc = null;
pc = this.cpds.getPooledConnection();
pc.addConnectionEventListener(conListener);
createTable("testPacketTooLarge", "(field1 LONGBLOB)");
Connection connFromPool = pc.getConnection();
PreparedStatement pstmtFromPool = ((ConnectionWrapper) connFromPool).clientPrepare("INSERT INTO testPacketTooLarge VALUES (?)");
this.rs = this.stmt.executeQuery("SHOW VARIABLES LIKE 'max_allowed_packet'");
this.rs.next();
int maxAllowedPacket = this.rs.getInt(2);
int numChars = (int) (maxAllowedPacket * 1.2);
pstmtFromPool.setBinaryStream(1, new BufferedInputStream(new FileInputStream(newTempBinaryFile("testPacketTooLargeException", numChars))), numChars);
try {
pstmtFromPool.executeUpdate();
fail("Expecting PacketTooLargeException");
} catch (PacketTooBigException ptbe) {
// We're expecting this one...
}
// This should still work okay, even though the last query on the same connection didn't...
this.rs = connFromPool.createStatement().executeQuery("SELECT 1");
assertTrue(this.connectionErrorEventCount == 0);
assertTrue(this.closeEventCount == 0);
}