Search in sources :

Example 36 with PooledConnection

use of javax.sql.PooledConnection in project geode by apache.

the class GemFireTransactionDataSource method getSQLConnection.

/**
   * gets the connection from the pool
   * 
   * @param poolC
   * @return ???
   */
protected Connection getSQLConnection(PooledConnection poolC) throws SQLException {
    Connection conn = poolC.getConnection();
    boolean val = validateConnection(conn);
    if (val)
        return conn;
    else {
        provider.returnAndExpireConnection(poolC);
        throw new SQLException(LocalizedStrings.GemFireTransactionDataSource_GEMFIRECONNPOOLEDDATASOURCEGETCONNFROMCONNPOOLJAVASQLCONNECTION_OBTAINED_IS_INVALID.toLocalizedString());
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection)

Example 37 with PooledConnection

use of javax.sql.PooledConnection in project geode by apache.

the class GemFireTransactionDataSource method connectionErrorOccurred.

/**
   * Implementation of call back function from ConnectionEventListener interface. This callback will
   * be invoked on connection error event.
   * 
   * @param event Connection event object
   */
public void connectionErrorOccurred(ConnectionEvent event) {
    if (isActive) {
        try {
            PooledConnection conn = (PooledConnection) event.getSource();
            provider.returnAndExpireConnection(conn);
        } catch (Exception ex) {
            String exception = "GemFireTransactionDataSource::connectionErrorOccurred: Exception occurred due to " + ex;
            if (logger.isDebugEnabled()) {
                logger.debug(exception, ex);
            }
        }
    }
}
Also used : PooledConnection(javax.sql.PooledConnection) SQLException(java.sql.SQLException)

Example 38 with PooledConnection

use of javax.sql.PooledConnection in project geode by apache.

the class TranxPoolCacheImpl method getNewPoolConnection.

/**
   * 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());
    }
}
Also used : PooledConnection(javax.sql.PooledConnection) SQLException(java.sql.SQLException)

Example 39 with PooledConnection

use of javax.sql.PooledConnection in project cdap by caskdata.

the class DBConnectionPoolManager method dispose.

/**
   * 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;
    }
}
Also used : PooledConnection(javax.sql.PooledConnection) SQLException(java.sql.SQLException)

Example 40 with PooledConnection

use of javax.sql.PooledConnection in project spanner-jdbc by olavloite.

the class CloudSpannerConnectionPoolDataSourceTest method createDataSourceTest.

@Test
public void createDataSourceTest() throws SQLException {
    CloudSpannerConnectionPoolDataSource subject = new CloudSpannerConnectionPoolDataSource();
    subject.setProjectId("helpful-adroit-123456");
    subject.setInstanceId("test-instance");
    subject.setDatabase("test");
    subject.setPvtKeyPath("C:\\Users\\MyUserName\\Documents\\CloudSpannerKeys\\cloudspanner-key.json");
    subject.setPvtKeyPath(null);
    subject.setOauthAccessToken("TEST");
    subject.setSimulateProductName("PostgreSQL");
    subject.setAllowExtendedMode(true);
    subject.setLoginTimeout(10);
    subject.setDefaultAutoCommit(false);
    subject.setLogWriter(new PrintWriter(System.out));
    Assert.assertEquals("ConnectionPoolDataSource from " + nl.topicus.jdbc.CloudSpannerDriver.getVersion(), subject.getDescription());
    PooledConnection con = subject.getPooledConnection();
    Assert.assertNotNull(con);
    ICloudSpannerConnection connection = (ICloudSpannerConnection) con.getConnection();
    Assert.assertEquals("jdbc:cloudspanner://localhost", connection.getUrl());
    Assert.assertEquals("PostgreSQL", connection.getProductName());
    Assert.assertEquals("helpful-adroit-123456", connection.getSuppliedProperties().getProperty("Project"));
    Assert.assertEquals("test-instance", connection.getSuppliedProperties().getProperty("Instance"));
    Assert.assertEquals("test", connection.getSuppliedProperties().getProperty("Database"));
    Assert.assertEquals("TEST", connection.getSuppliedProperties().getProperty("OAuthAccessToken"));
    Assert.assertTrue(connection.isAllowExtendedMode());
    Assert.assertEquals(subject.isDefaultAutoCommit(), connection.getAutoCommit());
    PooledConnection con2 = subject.getPooledConnection("TEST", "TEST");
    Assert.assertNotNull(con2);
    boolean exception = false;
    try {
        subject.getParentLogger();
    } catch (SQLFeatureNotSupportedException e) {
        exception = true;
    }
    Assert.assertTrue(exception);
}
Also used : PooledConnection(javax.sql.PooledConnection) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) PrintWriter(java.io.PrintWriter) UnitTest(nl.topicus.jdbc.test.category.UnitTest) Test(org.junit.Test)

Aggregations

PooledConnection (javax.sql.PooledConnection)40 SQLException (java.sql.SQLException)21 Connection (java.sql.Connection)14 Test (org.junit.Test)7 Context (javax.naming.Context)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 ResultSet (java.sql.ResultSet)2 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)2 Statement (java.sql.Statement)2 Iterator (java.util.Iterator)2 XAConnection (javax.sql.XAConnection)2 DefaultPooledObject (org.apache.tomcat.dbcp.pool2.impl.DefaultPooledObject)2 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 InitialContext (javax.naming.InitialContext)1 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)1