本文整理汇总了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);
}