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


Java PooledConnection.addConnectionEventListener方法代碼示例

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

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

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

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

示例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);
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:42,代碼來源:PooledConnectionRegressionTest.java


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