當前位置: 首頁>>代碼示例>>Java>>正文


Java PooledConnection類代碼示例

本文整理匯總了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;
    }
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:18,代碼來源:ManagedPoolDataSource.java

示例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();
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:25,代碼來源:ManagedPoolDataSource.java

示例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.");
    }
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:21,代碼來源:ManagedPoolDataSource.java

示例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;
    }
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:31,代碼來源:JDBCConnectionPoolDataSource.java

示例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);

}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:29,代碼來源:ConnectionRegressionTest.java

示例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)));
}
 
開發者ID:jcustenborder,項目名稱:kafka-connect-cdc-mssql,代碼行數:26,代碼來源:QueryServiceTest.java

示例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();
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:24,代碼來源:MiniConnectionPoolManager.java

示例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;
    }
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:24,代碼來源:MiniConnectionPoolManager.java

示例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;
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:26,代碼來源:MiniConnectionPoolManager.java

示例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();
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:19,代碼來源:MiniConnectionPoolManager.java

示例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);
      }
    }
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:22,代碼來源:GemFireConnPooledDataSource.java

示例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());
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:30,代碼來源:TranxPoolCacheImpl.java

示例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());
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:31,代碼來源:ConnectionPoolCacheImpl.java

示例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
  // + "***********");
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:23,代碼來源:ConnectionPoolCacheImplJUnitTest.java

示例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");
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:24,代碼來源:AbstractPoolCacheJUnitTest.java


注:本文中的javax.sql.PooledConnection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。