javax.sql.PooledConnection Java Examples

The following examples show how to use javax.sql.PooledConnection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatementPoolingTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the statement cache is able to throw out prepared statements
 * when it reaches maximum capacity.
 *
 * @throws SQLException if something goes wrong...
 */
public void testCacheOverflow()
        throws SQLException {
    final int stmtCount = 150;
    ConnectionPoolDataSource cpDs =
            J2EEDataSource.getConnectionPoolDataSource();
    J2EEDataSource.setBeanProperty(cpDs, "maxStatements", new Integer(11));
    J2EEDataSource.setBeanProperty(cpDs, "createDatabase", "create");
    PooledConnection pc = cpDs.getPooledConnection();
    Connection con = pc.getConnection();
    for (int i=0; i < stmtCount; i++) {
        // Yes, the "values + i" is intended here.
        PreparedStatement pStmt = con.prepareStatement("values " + i);
        ResultSet rs = pStmt.executeQuery();
        JDBC.assertSingleValueResultSet(rs, Integer.toString(i));
        pStmt.close();
    }
    con.close();
    pc.close();
}
 
Example #2
Source File: MiniConnectionPoolManager.java    From fixflow with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
	}
}
 
Example #3
Source File: MiniConnectionPoolManager.java    From fixflow with Apache License 2.0 6 votes vote down vote up
private synchronized Connection getConnection3() throws SQLException {
	if (isDisposed) {
		throw new IllegalStateException("Connection pool has been disposed.");
	} // test again with lock
	PooledConnection pconn;
	if (!recycledConnections.isEmpty()) {
		pconn = recycledConnections.remove();
	} else {
		pconn = dataSource.getPooledConnection();
		pconn.addConnectionEventListener(poolConnectionEventListener);
	}
	Connection conn = pconn.getConnection();
	activeConnections++;
	assertInnerState();
	return conn;
}
 
Example #4
Source File: TestValidation.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private void obtainThenReleaseCxnAndAssessIdleValidationWithOutcome(ValidationOutcome validationOutcome, String validationQuery, Boolean autoCommit)
        throws SQLException, InterruptedException {
    datasource.getPoolProperties().setTestWhileIdle(true);
    datasource.getPoolProperties().setValidationInterval(1);
    datasource.getPoolProperties().setDefaultAutoCommit(autoCommit);
    datasource.getPoolProperties().setValidationQuery(validationQuery);
    datasource.setUrl(MockDriver.getUrlWithValidationOutcomes(validationOutcome));

    PooledConnection cxn1 = getPooledConnection();
    MockConnection mockCxn1 = getMock(cxn1);
    Assert.assertFalse("No transaction must be running after connection is obtained", mockCxn1.isRunningTransaction());

    cxn1.close();
    Assert.assertEquals("Pool must contain 1 idle connection at this time", datasource.getIdle(), 1);

    Thread.sleep(1200); // Nasty - instrument PooledConnection to drive time measurement instead of hard-coded System.currentTimeMillis()
    datasource.testIdle();

    if (validationOutcome == ValidationOutcome.SUCCESS) {
        Assert.assertEquals("Pool must contain 1 idle connection at this time", datasource.getIdle(), 1);
    }
    else {
        Assert.assertEquals("Pool must not contain any idle connection at this time", datasource.getIdle(), 0);
    }
}
 
Example #5
Source File: StatementPoolingTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the statement cache is able to throw out prepared statements
 * when it reaches maximum capacity.
 *
 * @throws SQLException if something goes wrong...
 */
public void testCacheOverflow()
        throws SQLException {
    final int stmtCount = 150;
    ConnectionPoolDataSource cpDs =
            J2EEDataSource.getConnectionPoolDataSource();
    J2EEDataSource.setBeanProperty(cpDs, "maxStatements", new Integer(11));
    J2EEDataSource.setBeanProperty(cpDs, "createDatabase", "create");
    PooledConnection pc = cpDs.getPooledConnection();
    Connection con = pc.getConnection();
    for (int i=0; i < stmtCount; i++) {
        // Yes, the "values + i" is intended here.
        PreparedStatement pStmt = con.prepareStatement("values " + i);
        ResultSet rs = pStmt.executeQuery();
        JDBC.assertSingleValueResultSet(rs, Integer.toString(i));
        pStmt.close();
    }
    con.close();
    pc.close();
}
 
Example #6
Source File: J2EEDataSourceTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Test that isolation is reset on PooledConnection.getConnection()
 * @param pooledConnType   Descripiton of the type of pooled connection
 * @param pc               PooledConnection or XAConnection  
 * @throws SQLException
 */
private void assertPooledConnIso(
    String pooledConnType, PooledConnection pc) throws SQLException {
    Connection conn = pc.getConnection();

    setupDerby1144Table(conn);

    // *** Test isolation level reset on conntype.getConnection()          
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
    assertIsoLocks(conn, Connection.TRANSACTION_READ_UNCOMMITTED);

    conn.close();
    //Get a new connection with pooledConnType.getConnection()
    // Isolation level should be reset to READ_COMMITTED
    Connection newconn = pc.getConnection();
    assertIsoLocks(newconn, Connection.TRANSACTION_READ_COMMITTED);
}
 
Example #7
Source File: J2EEDataSourceTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Regression test for a NullPointerException when trying to use the LOB
 * stored procedures after closing and then getting a new logical
 * connection. The problem was that the LOB stored procedure objects on the
 * server side were closed and not reprepared.
 * See Jira issue DERBY-3799.
 */
public void testDerby3799() throws SQLException {
    ConnectionPoolDataSource cpDs =
            J2EEDataSource.getConnectionPoolDataSource();
    PooledConnection pc = cpDs.getPooledConnection();
    // Get first logical connection.
    Connection con1 = pc.getConnection();
    Statement stmt = con1.createStatement();
    ResultSet rs = stmt.executeQuery("select dClob from derby3799");
    assertTrue(rs.next());
    rs.getString(1);
    rs.close();
    con1.close();
    // Get second logical connection.
    Connection con2 = pc.getConnection();
    stmt = con2.createStatement();
    rs = stmt.executeQuery("select dClob from derby3799");
    assertTrue(rs.next());
    rs.getString(1); // NPE happened here.
    con2.close();
}
 
Example #8
Source File: J2EEDataSourceTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * check whether commit without statement will flow by checking its transaction id
 * on client. This test is run only for client where commits without an
 * active transactions will not flow to the server.
 * DERBY-4653
 *
 * @throws SQLException
 **/
public void testConnectionFlowCommit()
        throws SQLException {
    ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();

    PooledConnection pc = ds.getPooledConnection();
    Connection conn = pc.getConnection();

    testConnectionFlowCommitWork(conn);
    conn.close();

    //Test for XADataSource
    XADataSource xs = J2EEDataSource.getXADataSource();
    XAConnection xc = xs.getXAConnection();
    conn = xc.getConnection();
    testConnectionFlowCommitWork(conn);
    conn.close();

    //Test for DataSource
    DataSource jds = JDBCDataSource.getDataSource();
    conn = jds.getConnection();
    testConnectionFlowCommitWork(conn);
    conn.close();
}
 
Example #9
Source File: J2EEDataSourceTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Executes a test sequence to make sure the schema is reset between
 * logical connections.
 *
 * @param pc pooled connection to get logical connections from
 * @param userSchema name of the default schema for the connection (user)
 * @throws SQLException if something goes wrong...
 */
private void doTestSchemaIsReset(PooledConnection pc, String userSchema)
        throws SQLException {
    Connection con1 = pc.getConnection();
    JDBC.assertCurrentSchema(con1, userSchema);
    Statement stmt1 = con1.createStatement();
    // Change the schema.
    stmt1.execute("set schema APP");
    stmt1.close();
    JDBC.assertCurrentSchema(con1, "APP");
    // Close the logical connection and get a new one.
    con1.close();
    Connection con2 = pc.getConnection();
    // Make sure the schema has been reset from APP to the user name.
    JDBC.assertCurrentSchema(con2, userSchema);
    con2.close();
    // Try a third time, but don't change the schema now.
    Connection con3 = pc.getConnection();
    JDBC.assertCurrentSchema(con3, userSchema);
    con3.close();
    pc.close();
}
 
Example #10
Source File: KeyedCPDSConnectionFactory.java    From commons-dbcp with Apache License 2.0 6 votes vote down vote up
/**
 * If a fatal error occurs, close the underlying physical connection so as not to be returned in the future
 */
@Override
public void connectionErrorOccurred(final ConnectionEvent event) {
    final PooledConnection pc = (PooledConnection) event.getSource();
    if (null != event.getSQLException()) {
        System.err.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")");
    }
    pc.removeConnectionEventListener(this);

    final PooledConnectionAndInfo info = pcMap.get(pc);
    if (info == null) {
        throw new IllegalStateException(NO_KEY_MESSAGE);
    }
    try {
        pool.invalidateObject(info.getUserPassKey(), info);
    } catch (final Exception e) {
        System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + info);
        e.printStackTrace();
    }
}
 
Example #11
Source File: J2EEDataSourceTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Test that isolation is reset on PooledConnection.getConnection()
 * @param pooledConnType   Descripiton of the type of pooled connection
 * @param pc               PooledConnection or XAConnection  
 * @throws SQLException
 */
private void assertPooledConnIso(
        String pooledConnType, PooledConnection pc) throws SQLException {
    Connection conn = pc.getConnection();

    setupDerby1144Table(conn);

    // *** Test isolation level reset on conntype.getConnection()          
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
    assertIsoLocks(conn, Connection.TRANSACTION_READ_UNCOMMITTED);

    conn.close();
    //Get a new connection with pooledConnType.getConnection()
    // Isolation level should be reset to READ_COMMITTED
    Connection newconn = pc.getConnection();
    assertIsoLocks(newconn, Connection.TRANSACTION_READ_COMMITTED);
}
 
Example #12
Source File: ConnectionPoolCacheImplTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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
      // + "***********");
    }
 
Example #13
Source File: AbstractPoolCacheTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Test of getPooledConnectionFromPool method, of class
 * com.gemstone.gemfire.internal.datasource.AbstractPoolCache.
 */
public void testGetPooledConnectionFromPool() {
  try {
    Context ctx = cache.getJNDIContext();
    GemFireConnPooledDataSource ds = (GemFireConnPooledDataSource) ctx
        .lookup("java:/PooledDataSource");
    GemFireConnectionPoolManager provider = (GemFireConnectionPoolManager) ds
        .getConnectionProvider();
    ConnectionPoolCacheImpl poolCache = (ConnectionPoolCacheImpl) provider
        .getConnectionPoolCache();
    PooledConnection poolConn = (PooledConnection) poolCache
        .getPooledConnectionFromPool();
    if (poolConn == null)
        fail("getPooledConnectionFromPool failed to get a connection from pool");
  }
  catch (Exception e) {
    fail("Exception occured in testGetPooledConnectionFromPool due to " + e);
    e.printStackTrace();
  }
}
 
Example #14
Source File: J2EEDataSourceTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * check whether commit without statement will flow by checking its transaction id
 * on client. This test is run only for client where commits without an
 * active transactions will not flow to the server.
 * DERBY-4653
 * 
 * @throws SQLException
 **/
public void testConnectionFlowCommit()
        throws SQLException {
    ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();

    PooledConnection pc = ds.getPooledConnection();
    Connection conn = pc.getConnection();

    testConnectionFlowCommitWork(conn, 1);
    conn.close();
    
    //Test for XADataSource
    XADataSource xs = J2EEDataSource.getXADataSource();
    XAConnection xc = xs.getXAConnection();
    conn = xc.getConnection();
    testConnectionFlowCommitWork(conn, 1);
    conn.close();
    
    //Test for DataSource
    DataSource jds = JDBCDataSource.getDataSource();
    conn = jds.getConnection();
    testConnectionFlowCommitWork(conn, 1);
    conn.close();       
}
 
Example #15
Source File: DataSourcePropertiesTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the <code>attributesAsPassword</code> property of a
 * <code>ConnectionPoolDataSource</code> causes an explicitly specified
 * password to be sent as a property string.
 */
public void embeddedTestAttributesAsPasswordWithPassword_pooled()
    throws Exception
{
    ConnectionPoolDataSource ds =
        J2EEDataSource.getConnectionPoolDataSource();
    JDBCDataSource.setBeanProperty(ds, "attributesAsPassword", Boolean.TRUE);
    try {
        PooledConnection pc =
            ds.getPooledConnection("username", "mypassword");
        fail("Expected getPooledConnection to fail.");
    } catch (SQLException e) {
        // expect error because of malformed url
        assertSQLState("XJ028", e);
    }
}
 
Example #16
Source File: StatementPoolingTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Test sequence for testing if the connection holdability is reset.
 *
 * @param closeConnection determines if the logical connection is
 *      explicitly closed before a new one is obtained
 * @throws SQLException if something goes wrong...
 */
private void doTestHoldabilityIsReset(final boolean closeConnection)
        throws SQLException {
    ConnectionPoolDataSource cpDs =
            J2EEDataSource.getConnectionPoolDataSource();
    J2EEDataSource.setBeanProperty(cpDs, "maxStatements", new Integer(7));
    J2EEDataSource.setBeanProperty(cpDs, "createDatabase", "create");
    PooledConnection pc = cpDs.getPooledConnection();
    // Keep track of our own connection, the framework currently creates
    // a new pooled connection and then obtains a connection from that.
    // Statement pooling only works within a single pooled connection.
    Connection con = pc.getConnection();
    assertEquals("Unexpected default holdability",
            ResultSet.HOLD_CURSORS_OVER_COMMIT, con.getHoldability());
    con.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
    assertEquals("Holdability not updated",
            ResultSet.CLOSE_CURSORS_AT_COMMIT, con.getHoldability());
    if (closeConnection) {
        con.close();
    }
    con = pc.getConnection();
    assertEquals("Holdability not reset",
            ResultSet.HOLD_CURSORS_OVER_COMMIT, con.getHoldability());
    pc.close();
}
 
Example #17
Source File: CPDSConnectionFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public synchronized PooledObject<PooledConnectionAndInfo> makeObject() {
    PooledConnectionAndInfo pci;
    try {
        PooledConnection pc = null;
        if (userName == null) {
            pc = cpds.getPooledConnection();
        } else {
            pc = cpds.getPooledConnection(userName, Utils.toString(userPassword));
        }

        if (pc == null) {
            throw new IllegalStateException("Connection pool data source returned null from getPooledConnection");
        }

        // should we add this object as a listener or the pool.
        // consider the validateObject method in decision
        pc.addConnectionEventListener(this);
        pci = new PooledConnectionAndInfo(pc, userName, userPassword);
        pcMap.put(pc, pci);
    } catch (final SQLException e) {
        throw new RuntimeException(e.getMessage());
    }
    return new DefaultPooledObject<>(pci);
}
 
Example #18
Source File: CPDSConnectionFactory.java    From commons-dbcp with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized PooledObject<PooledConnectionAndInfo> makeObject() {
    PooledConnectionAndInfo pci;
    try {
        PooledConnection pc = null;
        if (userName == null) {
            pc = cpds.getPooledConnection();
        } else {
            pc = cpds.getPooledConnection(userName, Utils.toString(userPassword));
        }

        if (pc == null) {
            throw new IllegalStateException("Connection pool data source returned null from getPooledConnection");
        }

        // should we add this object as a listener or the pool.
        // consider the validateObject method in decision
        pc.addConnectionEventListener(this);
        pci = new PooledConnectionAndInfo(pc, userName, userPassword);
        pcMap.put(pc, pci);
    } catch (final SQLException e) {
        throw new RuntimeException(e.getMessage());
    }
    return new DefaultPooledObject<>(pci);
}
 
Example #19
Source File: CPDSConnectionFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * If a fatal error occurs, close the underlying physical connection so as not to be returned in the future
 */
@Override
public void connectionErrorOccurred(final ConnectionEvent event) {
    final PooledConnection pc = (PooledConnection) event.getSource();
    if (null != event.getSQLException()) {
        System.err.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")");
    }
    pc.removeConnectionEventListener(this);

    final PooledConnectionAndInfo pci = pcMap.get(pc);
    if (pci == null) {
        throw new IllegalStateException(NO_KEY_MESSAGE);
    }
    try {
        pool.invalidateObject(pci);
    } catch (final Exception e) {
        System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci);
        e.printStackTrace();
    }
}
 
Example #20
Source File: J2EEDataSourceTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Tests that deleting the current / default schema doesn't cause the next
 * logical connection to fail.
 * <p>
 * Relevant Jira issue: DERBY-3690.
 *
 * @throws SQLException if something goes wrong
 */
public void testSchemaIsResetWhenDeleted()
        throws SQLException {
    final String userSchema = "AUSER";
    ConnectionPoolDataSource cpDs =
            J2EEDataSource.getConnectionPoolDataSource();
    J2EEDataSource.setBeanProperty(cpDs, "createDatabase", "create");
    PooledConnection pc = cpDs.getPooledConnection(userSchema, "secret");
    // Get first connection, create a table, then drop schema.
    Connection con = pc.getConnection();
    JDBC.assertCurrentSchema(con, userSchema);
    Statement stmt = con.createStatement();
    stmt.executeUpdate("create table schematest (id int)");
    stmt.executeUpdate("drop table schematest");
    stmt.executeUpdate("drop schema " + userSchema + " restrict");
    stmt.close();
    con.close();
    // Get second connection.
    con = pc.getConnection();
    JDBC.assertCurrentSchema(con, userSchema);
    stmt = con.createStatement();
    stmt.executeUpdate("create table schematest (id int)");
    stmt.executeUpdate("drop table schematest");
    stmt.close();
    JDBC.assertCurrentSchema(con, userSchema);
    con.close();
    pc.close();
}
 
Example #21
Source File: GemFireConnPooledDataSource.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * gets tha 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.GemFireConnPooledDataSource_GEMFIRECONNPOOLEDDATASOURCEGETCONNFROMCONNPOOLJAVASQLCONNECTION_OBTAINED_IS_INVALID.toLocalizedString());
  }
}
 
Example #22
Source File: EqualsHashCodeTest.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testEquals() throws Exception {
    Connection con1 = datasource.getConnection();
    Connection real1 = ((PooledConnection)con1).getConnection();
    Assert.assertEquals(con1, con1);
    con1.close();
    Assert.assertEquals(con1, con1);
    Connection con2 = datasource.getConnection();
    Connection real2 = ((PooledConnection)con2).getConnection();
    Assert.assertEquals(real1,real2);
    Assert.assertEquals(con2, con2);
    Assert.assertNotSame(con1, con2);
    con2.close();
    Assert.assertEquals(con2, con2);
}
 
Example #23
Source File: GemFireConnPooledDataSource.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Implementation of call back function from ConnectionEventListener
 * interface. This callback will be invoked on connection close event.
 * 
 * @param event
 */
public void connectionClosed(ConnectionEvent event) {
  if (isActive) {
    try {
      PooledConnection conn = (PooledConnection) event.getSource();
      provider.returnConnection(conn);
    }
    catch (Exception ex) {
      String exception = "GemFireConnPooledDataSource::connectionclosed:Exception ="
          + ex;
      LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
      if (writer.fineEnabled()) writer.fine(exception, ex);
    }
  }
}
 
Example #24
Source File: ConnectionRegressionTest.java    From r-course with MIT License 5 votes vote down vote up
private void testBug62452WithConnection(PooledConnection con) throws Exception {
    this.pstmt = con.getConnection().prepareStatement("SELECT 1");
    this.rs = this.pstmt.executeQuery();
    con.close();

    // If PooledConnection is already closed by some reason a NullPointerException was thrown on the next line
    // because the closed connection has nulled out the list that it synchronises on when the closed event is fired.
    this.pstmt.close();
}
 
Example #25
Source File: JDBCPool.java    From evosql with Apache License 2.0 5 votes vote down vote up
public void connectionClosed(ConnectionEvent event) {
    PooledConnection connection = (PooledConnection) event.getSource();

    for (int i = 0; i < connections.length; i++) {
        if (connections[i] == connection) {
            states.set(i, RefState.available);

            break;
        }
    }
}
 
Example #26
Source File: TestPooledConnectionHandler.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Tests toString() of connection (proxy).
 * <p>
 * NOTE: This tests an implementation detail of toString()
 * </p>
 */
@Test
public void testConnectionToString() throws SQLException {
    PooledConnection pc = getPooledConnection();
    Connection con = pc.getConnection();
    
    // Test for implementation detail!
    assertTrue(con.toString().startsWith("Proxy for org.firebirdsql.jdbc.FBConnection"));
}
 
Example #27
Source File: J2EEDataSourceTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Test that a connection to PoolDataSource can be established
 * successfully while creating a database using setDatabaseName()
 * with create=true
 *
 * @throws SQLException
 */

public void testCreateInDatabaseName_Pooled() throws SQLException
{
    //test with PooledConnection
    ConnectionPoolDataSource cpds = J2EEDataSource.getConnectionPoolDataSource();
    PooledConnection pc = cpds.getPooledConnection();
    String dbName = TestConfiguration.getCurrent().getDefaultDatabaseName();
    J2EEDataSource.setBeanProperty(cpds, "databaseName",dbName +";create=true");
    Connection c;
    c = pc.getConnection();
    c.setAutoCommit(false);
    c.close();
    pc.close();
}
 
Example #28
Source File: EmbeddedConnectionPoolDataSource.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Create and return an EmbedPooledConnection from this instance
 * of EmbeddedConnectionPoolDataSource.
 */
protected PooledConnection createPooledConnection (String user,
    String password, boolean requestPassword) throws SQLException
{
    /* This object (EmbeddedConnectionPoolDataSource) is a JDBC 2
     * and JDBC 3 implementation of ConnectionPoolDatSource.  However,
     * it's possible that we are running with a newer driver (esp.
     * JDBC 4) in which case we should return a PooledConnection that
     * implements the newer JDBC interfaces--even if "this" object
     * does not itself satisfy those interfaces.  As an example, if
     * we have a JDK 6 application then even though this specific
     * object doesn't implement JDBC 4 (it only implements JDBC 2
     * and 3), we should still return a PooledConnection object that
     * *does* implement JDBC 4 because that's what a JDK 6 app
     * expects.
     *
     * By calling "findDriver()" here we will get the appropriate
     * driver for the JDK in use (ex. if using JDK 6 then findDriver()
     * will return the JDBC 4 driver).  If we then ask the driver to
     * give us a pooled connection, we will get a connection that
     * corresponds to whatever driver/JDBC implementation is being
     * used--which is what we want.  So for a JDK 6 application we
     * will correctly return a JDBC 4 PooledConnection. DERBY-2488.
     *
     * This type of scenario can occur if an application that was
     * previously running with an older JVM (ex. JDK 1.4/1.5) starts
     * running with a newer JVM (ex. JDK 6), in which case the app
     * is probably still using the "old" data source (ex. is still
     * instantiating EmbeddedConnectionPoolDataSource) instead of
     * the newer one (EmbeddedConnectionPoolDataSource40).
     */
    return ((Driver30) findDriver()).getNewPooledConnection(
        this, user, password, requestPassword);
}
 
Example #29
Source File: JDBCPool.java    From evosql with Apache License 2.0 5 votes vote down vote up
public void connectionErrorOccurred(ConnectionEvent event) {
    PooledConnection connection = (PooledConnection) event.getSource();

    for (int i = 0; i < connections.length; i++) {
        if (connections[i] == connection) {
            states.set(i, RefState.allocated);
            connections[i] = null;
            states.set(i, RefState.empty);
            break;
        }
    }
}
 
Example #30
Source File: J2EEDataSourceTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** 
 * Check the format of a pooled connection
 **/
private static void assertStringFormat(PooledConnection pc) throws Exception
{
    String prefix = assertStringPrefix(pc);
    String connstr = pc.toString();
    String format = prefix + " \\(ID = [0-9]+\\), Physical Connection = " +
        "<none>|" + CONNSTRING_FORMAT;
    assertTrue(connstr.matches(format));
}