本文整理汇总了Java中javax.sql.PooledConnection类的典型用法代码示例。如果您正苦于以下问题:Java PooledConnection类的具体用法?Java PooledConnection怎么用?Java PooledConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PooledConnection类属于javax.sql包,在下文中一共展示了PooledConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: connectionErrorOccurred
import javax.sql.PooledConnection; //导入依赖的package包/类
/**
*
* A fatal error has occurred and the connection cannot be used anymore.
* A close event from such a connection should be ignored. The connection should not be reused.
* A new connection will be created to replace the invalid connection, when the next client
* calls getConnection().
*/
public synchronized void connectionErrorOccurred(ConnectionEvent event) {
PooledConnection connection = (PooledConnection) event.getSource();
connection.removeConnectionEventListener(this);
this.connectionsInUse.remove(connection);
this.sessionConnectionWrappers.remove(connection);
logInfo(
"Fatal exception occurred on pooled connection. Connection is removed from pool: ");
logInfo(event.getSQLException());
closePhysically(connection, "closing invalid, removed connection.");
//notify threads waiting for connections or for the pool to close.
//one waiting thread can now create a new connection since the pool has space for a new connection.
//if a thread waits for the pool to close this could be the last unclosed connection in the pool.
this.notifyAll();
}
示例3: closeImmediatedly
import javax.sql.PooledConnection; //导入依赖的package包/类
/**
* Closes this connection
*/
public synchronized void closeImmediatedly() {
close();
Iterator iterator = this.connectionsInUse.iterator();
while (iterator.hasNext()) {
PooledConnection connection = (PooledConnection) iterator.next();
SessionConnectionWrapper sessionWrapper =
(SessionConnectionWrapper) this.sessionConnectionWrappers.get(
connection);
closeSessionWrapper(
sessionWrapper,
"Error closing session wrapper. Connection pool was shutdown immediatedly.");
}
}
示例4: getQueryObjectGenerator
import javax.sql.PooledConnection; //导入依赖的package包/类
/**
* Retrieves the QueryObjectGenerator for the given JDBC driver. If the
* JDBC driver does not provide its own QueryObjectGenerator, NULL is
* returned.
* @return The QueryObjectGenerator for this JDBC Driver or NULL if the driver does not provide its own
* implementation
* @exception SQLException if a database access error occurs
* @since JDK 1.6, HSQLDB 1.8.x
*/
//#ifdef JAVA6BETA
/*
public QueryObjectGenerator getQueryObjectGenerator() throws SQLException {
return null;
}
*/
//#endif JAVA6BETA
// ------------------------ internal implementation ------------------------
private PooledConnection createPooledConnection(JDBCConnection connection)
throws SQLException {
LifeTimeConnectionWrapper connectionWrapper =
new LifeTimeConnectionWrapper(connection, this.connectionDefaults);
JDBCPooledConnection pooledConnection =
new JDBCPooledConnection(connectionWrapper);
connectionWrapper.setPooledConnection(pooledConnection);
return pooledConnection;
}
示例5: testBug62452
import javax.sql.PooledConnection; //导入依赖的package包/类
/**
* Tests fix for BUG#62452 - NPE thrown in JDBC4MySQLPooledException when statement is closed.
*
* @throws Exception
*/
public void testBug62452() throws Exception {
PooledConnection con = null;
MysqlConnectionPoolDataSource pds = new MysqlConnectionPoolDataSource();
pds.setUrl(dbUrl);
con = pds.getPooledConnection();
assertTrue(con instanceof JDBC4MysqlPooledConnection);
testBug62452WithConnection(con);
MysqlXADataSource xads = new MysqlXADataSource();
xads.setUrl(dbUrl);
xads.setPinGlobalTxToPhysicalConnection(false);
con = xads.getXAConnection();
assertTrue(con instanceof JDBC4MysqlXAConnection);
testBug62452WithConnection(con);
xads.setPinGlobalTxToPhysicalConnection(true);
con = xads.getXAConnection();
assertTrue(con instanceof JDBC4SuspendableXAConnection);
testBug62452WithConnection(con);
}
示例6: queryTable
import javax.sql.PooledConnection; //导入依赖的package包/类
@TestFactory
public Stream<DynamicTest> queryTable() throws SQLException {
List<ChangeKey> changeCaptureTables = new ArrayList<>();
PooledConnection pooledConnection = null;
try {
pooledConnection = JdbcUtils.openPooledConnection(this.config, new ChangeKey(MsSqlTestConstants.DATABASE_NAME, null, null));
MsSqlQueryBuilder queryBuilder = new MsSqlQueryBuilder(pooledConnection.getConnection());
try (PreparedStatement statement = queryBuilder.listChangeTrackingTablesStatement()) {
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
String databaseName = resultSet.getString("databaseName");
String schemaName = resultSet.getString("schemaName");
String tableName = resultSet.getString("tableName");
ChangeKey changeKey = new ChangeKey(databaseName, schemaName, tableName);
changeCaptureTables.add(changeKey);
log.trace("Found Change Tracking Enabled Table {}", changeKey);
}
}
}
} finally {
JdbcUtils.closeConnection(pooledConnection);
}
return changeCaptureTables.stream().map(data -> dynamicTest(data.tableName, () -> queryTable(data)));
}
示例7: MiniConnectionPoolManager
import javax.sql.PooledConnection; //导入依赖的package包/类
/**
* Constructs a MiniConnectionPoolManager object.
*
* @param dataSource the data source for the connections.
* @param maxConnections the maximum number of connections.
* @param timeout the maximum time in seconds to wait for a free connection.
*/
public MiniConnectionPoolManager(ConnectionPoolDataSource dataSource, int maxConnections,
int timeout) {
this.dataSource = dataSource;
this.maxConnections = maxConnections;
this.timeoutMs = timeout * 1000L;
try {
logWriter = dataSource.getLogWriter();
} catch (SQLException e) {
}
if (maxConnections < 1) {
throw new IllegalArgumentException("Invalid maxConnections value.");
}
semaphore = new Semaphore(maxConnections, true);
recycledConnections = new LinkedList<PooledConnection>();
poolConnectionEventListener = new PoolConnectionEventListener();
}
示例8: dispose
import javax.sql.PooledConnection; //导入依赖的package包/类
/**
* Closes all unused pooled connections.
*/
public synchronized void dispose() throws SQLException {
if (isDisposed) {
return;
}
isDisposed = true;
SQLException e = null;
while (!recycledConnections.isEmpty()) {
PooledConnection pconn = recycledConnections.remove();
try {
pconn.close();
} catch (SQLException e2) {
if (e == null) {
e = e2;
}
}
}
if (e != null) {
throw e;
}
}
示例9: 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;
}
示例10: recycleConnection
import javax.sql.PooledConnection; //导入依赖的package包/类
private synchronized void recycleConnection(PooledConnection pconn) {
if (isDisposed || doPurgeConnection) {
disposeConnection(pconn);
return;
}
if (pconn == connectionInTransition) {
// This happens when a faulty JDBC driver calls ConnectionEventListener.connectionClosed()
// a second time within PooledConnection.getConnection().
return;
}
if (activeConnections <= 0) {
throw new AssertionError();
}
activeConnections--;
semaphore.release();
recycledConnections.add(pconn);
assertInnerState();
}
示例11: connectionErrorOccurred
import javax.sql.PooledConnection; //导入依赖的package包/类
/**
* 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::connectionErrorOccured:error in returning and expiring connection due to "
+ ex;
if (logger.isDebugEnabled()) {
logger.debug(exception, ex);
}
}
}
}
示例12: 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());
}
}
示例13: 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());
}
}
示例14: run
import javax.sql.PooledConnection; //导入依赖的package包/类
public void run() {
String threadName = Thread.currentThread().getName();
// System.out.println(" Inside Run method of " + threadName);
int numConn2 = 0;
// int display = 0;
while (numConn2 < maxPoolSize) {
try {
PooledConnection conn = (PooledConnection) poolCache.getPooledConnectionFromPool();
poolConnlist.add(conn);
numConn2++;
// System.out.println(" ********** Got connection " + numConn2+ "from
// " + threadName);
} catch (Exception ex) {
fail("Exception occured in trying to getPooledConnectionFromPool due to " + ex);
ex.printStackTrace();
}
}
if (numConn2 != maxPoolSize)
fail("#### Error in getting all connections from the " + threadName);
// System.out.println(" ****************GOT ALL connections "+ threadName
// + "***********");
}
示例15: testReturnPooledConnectionToPool
import javax.sql.PooledConnection; //导入依赖的package包/类
/**
* Test of returnPooledConnectionToPool method, of class
* org.apache.geode.internal.datasource.AbstractPoolCache.
*/
@Test
public void testReturnPooledConnectionToPool() throws Exception {
Context ctx = cache.getJNDIContext();
GemFireConnPooledDataSource ds =
(GemFireConnPooledDataSource) ctx.lookup("java:/PooledDataSource");
GemFireConnectionPoolManager provider =
(GemFireConnectionPoolManager) ds.getConnectionProvider();
ConnectionPoolCacheImpl poolCache = (ConnectionPoolCacheImpl) provider.getConnectionPoolCache();
PooledConnection conn = (PooledConnection) poolCache.getPooledConnectionFromPool();
if (poolCache.availableCache.containsKey(conn))
fail("connection not removed from available cache list");
if (!poolCache.activeCache.containsKey(conn))
fail("connection not put in active connection list");
provider.returnConnection(conn);
if (!poolCache.availableCache.containsKey(conn))
fail("connection not returned to pool");
if (poolCache.activeCache.containsKey(conn))
fail("connection not returned to active list");
}