Java Code Examples for javax.sql.ConnectionPoolDataSource

The following examples show how to use javax.sql.ConnectionPoolDataSource. These examples are extracted from open source projects. 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 Project: gemfirexd-oss   Source File: StatementPoolingTest.java    License: 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 Project: gemfirexd-oss   Source File: J2EEDataSourceTest.java    License: 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 3
/**
 * Verifies that the current role is reset when creating a new logical
 * connection.
 * <p>
 * The test is run in a non-statement pooling configuration first,
 * and then with statement pooling enabled if the environment supports it.
 * <p>
 * The test pattern is borrowed from the test case in J2EEDataSourceTest.
 *
 * @see com.splicemachine.dbTesting.functionTests.tests.jdbcapi.J2EEDataSourceTest#testSchemaIsReset
 *
 * @throws SQLException if something goes wrong
 */
private void testCurrentRoleIsReset()
        throws SQLException {

    if (_authLevel == SQLAUTHORIZATION && isDbo() /* once is enough */) {
        final String user = "DonaldDuck";
        final String passwd = user.concat(pwSuffix);
        ConnectionPoolDataSource cpDs =
            J2EEDataSource.getConnectionPoolDataSource();
        // Test without statement pooling first.
        doTestCurrentRoleIsReset(cpDs.getPooledConnection(user, passwd),
                                 user);

        // Try to enable statement pooling.
        // This is currently only implemented in the client driver.
        if (usingDerbyNetClient()) {
            J2EEDataSource.setBeanProperty(
                cpDs, "maxStatements",new Integer(7));
            doTestCurrentRoleIsReset(cpDs.getPooledConnection(user, passwd),
                                     user);
        }
    }
}
 
Example 4
Source Project: gemfirexd-oss   Source File: PoolDSAuthenticationTest.java    License: Apache License 2.0 6 votes vote down vote up
protected void assertSystemShutdownOK(
    String dbName, String user, String password)
throws SQLException {
    ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
    JDBCDataSource.clearStringBeanProperty(pds, "databaseName");
    JDBCDataSource.setBeanProperty(pds, "shutdownDatabase", "shutdown");
    JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(pds, "user", user);
    JDBCDataSource.setBeanProperty(pds, "password", password);
    try {
        pds.getPooledConnection();
        fail("expected system shutdown resulting in XJ015 error");
    } catch (SQLException e) {
        // expect XJ015, system shutdown, on successful shutdown
        assertSQLState("XJ015", e);
    }
}
 
Example 5
Source Project: gemfirexd-oss   Source File: DataSourcePropertiesTest.java    License: 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 6
protected void assertSystemShutdownFail(
        String expectedError, String dbName, String user, String password)
throws SQLException {
    ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
    JDBCDataSource.clearStringBeanProperty(pds, "databaseName");
    JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(pds, "shutdownDatabase", "shutdown");
    JDBCDataSource.setBeanProperty(pds, "user", user);
    JDBCDataSource.setBeanProperty(pds, "password", password);
    try {
        pds.getPooledConnection();
        fail("expected shutdown to fail");
    } catch (SQLException e) {
        assertSQLState(expectedError, e);
    }
}
 
Example 7
Source Project: gemfirexd-oss   Source File: PoolDSAuthenticationTest.java    License: Apache License 2.0 6 votes vote down vote up
protected void assertShutdownWOUPOK(
    String dbName, String user, String password)
throws SQLException {
    ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
    JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(pds, "user", user);
    JDBCDataSource.setBeanProperty(pds, "password", password);
    JDBCDataSource.setBeanProperty(pds, "shutdownDatabase","shutdown");
    try {
        pds.getPooledConnection();
        fail ("expected a failed shutdown connection");
    } catch (SQLException e) {
        // expect 08006 on successful shutdown
        assertSQLState("08006", e);
    }
}
 
Example 8
Source Project: gemfirexd-oss   Source File: PoolDSAuthenticationTest.java    License: Apache License 2.0 6 votes vote down vote up
public void assertConnectionFail(String dbName) throws SQLException {
    ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
    // Reset to no user/password though client requires
    // a valid name, so reset to the default
    if (usingDerbyNetClient())
        JDBCDataSource.setBeanProperty(pds, "user", "APP");
    else
        JDBCDataSource.clearStringBeanProperty(pds, "user");
    JDBCDataSource.clearStringBeanProperty(pds, "password");
    JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
    try {
        pds.getPooledConnection();
        fail("expected connection to fail");
    } catch (SQLException e) {
        assertSQLState("08004", e);
    }
}
 
Example 9
Source Project: gemfirexd-oss   Source File: PoolDSAuthenticationTest.java    License: Apache License 2.0 6 votes vote down vote up
protected void assertSystemShutdownFail(
        String expectedError, String dbName, String user, String password)
throws SQLException {
    ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
    JDBCDataSource.clearStringBeanProperty(pds, "databaseName");
    JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(pds, "shutdownDatabase", "shutdown");
    JDBCDataSource.setBeanProperty(pds, "user", user);
    JDBCDataSource.setBeanProperty(pds, "password", password);
    try {
        pds.getPooledConnection();
        fail("expected shutdown to fail");
    } catch (SQLException e) {
        assertSQLState(expectedError, e);
    }
}
 
Example 10
protected void assertShutdownWOUPOK(
    String dbName, String user, String password)
throws SQLException {
    ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
    JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(pds, "user", user);
    JDBCDataSource.setBeanProperty(pds, "password", password);
    JDBCDataSource.setBeanProperty(pds, "shutdownDatabase","shutdown");
    try {
        pds.getPooledConnection();
        fail ("expected a failed shutdown connection");
    } catch (SQLException e) {
        // expect 08006 on successful shutdown
        assertSQLState("08006", e);
    }
}
 
Example 11
Source Project: gemfirexd-oss   Source File: J2EEDataSourceTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that the schema is reset when creating a new logical connection.
 * <p>
 * The test is run in a non-statement pooling configuration first,
 * and then with statement pooling enabled if the environment supports it.
 * <p>
 * Relevant Jira issue: DERBY-3690.
 *
 * @throws SQLException if something goes wrong
 */
public void testSchemaIsReset()
        throws SQLException {
    final String userSchema = "USERSCHEMA";
    ConnectionPoolDataSource cpDs =
            J2EEDataSource.getConnectionPoolDataSource();
    J2EEDataSource.setBeanProperty(cpDs, "createDatabase", "create");
    // Connect with a user specified, which should cause the schema to be
    // set to the user name.
    // Test without statement pooling first.
    doTestSchemaIsReset(cpDs.getPooledConnection(userSchema, "secret"),
            userSchema);

    // Try to enable statement pooling.
    // This is currently only implemented in the client driver.
    if (usingDerbyNetClient()) {
        J2EEDataSource.setBeanProperty(
                cpDs, "maxStatements",new Integer(7));
        doTestSchemaIsReset(cpDs.getPooledConnection(userSchema, "secret"),
                userSchema);
    }
}
 
Example 12
Source Project: gemfirexd-oss   Source File: J2EEDataSourceTest.java    License: 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 13
Source Project: gemfirexd-oss   Source File: J2EEDataSourceTest.java    License: 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 14
Source Project: gemfirexd-oss   Source File: J2EEDataSourceTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests for DERBY-1144
 * 
 * This test tests that holdability, autocomit, and transactionIsolation 
 * are reset on getConnection for PooledConnections obtaind from 
 * connectionPoolDataSources 
 * 
 * DERBY-1134 has been filed for more comprehensive testing of client 
 * connection state. 
 * 
 * @throws SQLException
 */
public void timeoutTestDerby1144PooledDS() throws SQLException {

    PooledConnection pc1 = null;

    // Test holdability   
    ConnectionPoolDataSource ds = 
        J2EEDataSource.getConnectionPoolDataSource();
    pc1 = ds.getPooledConnection();
    assertPooledConnHoldability("PooledConnection", pc1);
    pc1.close();
    
    // Test autocommit
    pc1 = ds.getPooledConnection();
    assertPooledConnAutoCommit("PooledConnection", pc1);
    pc1.close();
    
    // Test pooled connection isolation
    pc1 = ds.getPooledConnection();
    assertPooledConnIso("PooledConnection" , pc1);   
    pc1.close();
}
 
Example 15
Source Project: gemfirexd-oss   Source File: StatementPoolingTest.java    License: 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 16
Source Project: gemfirexd-oss   Source File: StatementPoolingTest.java    License: 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 Project: gemfirexd-oss   Source File: NSSecurityMechanismTest.java    License: Apache License 2.0 6 votes vote down vote up
private javax.sql.ConnectionPoolDataSource getCPDS(
    String user, String password)
{
    HashMap attrs = new HashMap();
    if (user != null)
        attrs.put("user", user);
    if (password != null)
        attrs.put("password", password);
    attrs = addRequiredAttributes(attrs);
    ConnectionPoolDataSource cpds = 
        J2EEDataSource.getConnectionPoolDataSource();
    for (Iterator i = attrs.keySet().iterator(); i.hasNext(); )
    {
        String property = (String) i.next();
        Object value = attrs.get(property);
        JDBCDataSource.setBeanProperty(cpds, property, value);
    }
    return cpds;
}
 
Example 18
Source Project: gemfirexd-oss   Source File: J2EEDataSourceTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test that a PooledConnection can be reused and closed
 * (separately) during the close event raised by the
 * closing of its logical connection.
 * DERBY-2142.
 * @throws SQLException 
 *
 */
public void testPooledReuseOnClose() throws SQLException
{
	// PooledConnection from a ConnectionPoolDataSource
	ConnectionPoolDataSource cpds =
		J2EEDataSource.getConnectionPoolDataSource();
	subtestPooledReuseOnClose(cpds.getPooledConnection());
    subtestPooledCloseOnClose(cpds.getPooledConnection());
    // DERBY-3401 - removing a callback during a close causes problems.
    subtestPooledRemoveListenerOnClose(cpds.getPooledConnection());
    subtestPooledAddListenerOnClose(cpds.getPooledConnection());

	// PooledConnection from an XDataSource
	XADataSource xads = J2EEDataSource.getXADataSource();
	subtestPooledReuseOnClose(xads.getXAConnection());
    subtestPooledCloseOnClose(xads.getXAConnection());
    // DERBY-3401 - removing a callback during a close causes problems.
    subtestPooledRemoveListenerOnClose(xads.getXAConnection());
    subtestPooledAddListenerOnClose(xads.getXAConnection());
}
 
Example 19
public Connection openConnection(String databaseName) throws SQLException {
    JDBCDataSource.setBeanProperty(ds, "databaseName", databaseName);
    try {
        return ds.getPooledConnection().getConnection();
    } catch (SQLException e) {
        // Expected state for database not found.
        // For the client the generic 08004 is returned,
        // will just retry on that.
        String expectedState = 
            config.getJDBCClient().isEmbedded() ? "XJ004" : "08004";

        // If there is a database not found exception
        // then retry the connection request with
        // a new DataSource with the createDtabase property set.
        if (!expectedState.equals(e.getSQLState()))
            throw e;
        ConnectionPoolDataSource tmpDs =
                singleUseDS("createDatabase", "create");
        JDBCDataSource.setBeanProperty(tmpDs, "databaseName", databaseName);
        return tmpDs.getPooledConnection().getConnection();
   }
}
 
Example 20
Source Project: fixflow   Source File: MiniConnectionPoolManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example 21
public  Connection openConnection
    (String databaseName, String user, String password, Properties connectionProperties)
     throws SQLException
{
    JDBCDataSource.setBeanProperty(ds, "databaseName", databaseName);
    try {
        return ds.getPooledConnection(user, password).getConnection();
    } catch (SQLException e) {
        // If there is a database not found exception
        // then retry the connection request with
        // a new DataSource with the createDatabase property set.
        if (!"XJ004".equals(e.getSQLState()))
            throw e;
        HashMap hm = DataSourceConnector.makeCreateDBAttributes( config );
        if ( connectionProperties != null ) { hm.putAll( connectionProperties ); }
        ConnectionPoolDataSource tmpDs = singleUseDS( hm );
        JDBCDataSource.setBeanProperty(tmpDs, "databaseName", databaseName);
        return tmpDs.getPooledConnection(user, password).getConnection(); 
   }
}
 
Example 22
protected void assertConSetOK(Object ds, String expectedSQLState, 
    String dbName, String connAttrValue, String setter, String setValue) 
throws SQLException {
    JDBCDataSource.setBeanProperty(ds, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(ds, setter, setValue);
    JDBCDataSource.setBeanProperty(
        ds, "ConnectionAttributes", connAttrValue);
    // check that the db exists; execute an unnecessary, but harmless, stmt
    try {
        if (ds instanceof javax.sql.ConnectionPoolDataSource)
            ((ConnectionPoolDataSource)ds).getPooledConnection();
        else
            ((XADataSource)ds).getXAConnection();
        fail("expected an sqlexception " + expectedSQLState);
    } catch (SQLException se) {
        assertSQLState(expectedSQLState, se);
    }
    JDBCDataSource.clearStringBeanProperty(ds, setter);
    JDBCDataSource.clearStringBeanProperty(ds, "ConnectionAttributes");
}
 
Example 23
protected void assertConnectionOK(
    String dbName, String user, String password)
throws SQLException
{
    ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
    JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
    pds.getPooledConnection(user, password).close();
}
 
Example 24
Source Project: Tomcat8-Source-Read   Source File: InstanceKeyDataSource.java    License: MIT License 5 votes vote down vote up
/**
 * Sets the backend ConnectionPoolDataSource. This property should not be set if using JNDI to access the
 * data source.
 *
 * @param v
 *            Value to assign to connectionPoolDataSource.
 */
public void setConnectionPoolDataSource(final ConnectionPoolDataSource v) {
    assertInitializationAllowed();
    if (dataSourceName != null) {
        throw new IllegalStateException("Cannot set the DataSource, if JNDI is used.");
    }
    if (dataSource != null) {
        throw new IllegalStateException("The CPDS has already been set. It cannot be altered.");
    }
    dataSource = v;
    instanceKey = InstanceKeyDataSourceFactory.registerNewInstance(this);
}
 
Example 25
Source Project: Tomcat8-Source-Read   Source File: SharedPoolDataSource.java    License: MIT License 5 votes vote down vote up
private void registerPool(final String userName, final String password) throws NamingException, SQLException {

        final ConnectionPoolDataSource cpds = testCPDS(userName, password);

        // Create an object pool to contain our PooledConnections
        factory = new KeyedCPDSConnectionFactory(cpds, getValidationQuery(), getValidationQueryTimeout(),
                isRollbackAfterValidation());
        factory.setMaxConnLifetimeMillis(getMaxConnLifetimeMillis());

        final GenericKeyedObjectPoolConfig<PooledConnectionAndInfo> config = new GenericKeyedObjectPoolConfig<>();
        config.setBlockWhenExhausted(getDefaultBlockWhenExhausted());
        config.setEvictionPolicyClassName(getDefaultEvictionPolicyClassName());
        config.setLifo(getDefaultLifo());
        config.setMaxIdlePerKey(getDefaultMaxIdle());
        config.setMaxTotal(getMaxTotal());
        config.setMaxTotalPerKey(getDefaultMaxTotal());
        config.setMaxWaitMillis(getDefaultMaxWaitMillis());
        config.setMinEvictableIdleTimeMillis(getDefaultMinEvictableIdleTimeMillis());
        config.setMinIdlePerKey(getDefaultMinIdle());
        config.setNumTestsPerEvictionRun(getDefaultNumTestsPerEvictionRun());
        config.setSoftMinEvictableIdleTimeMillis(getDefaultSoftMinEvictableIdleTimeMillis());
        config.setTestOnCreate(getDefaultTestOnCreate());
        config.setTestOnBorrow(getDefaultTestOnBorrow());
        config.setTestOnReturn(getDefaultTestOnReturn());
        config.setTestWhileIdle(getDefaultTestWhileIdle());
        config.setTimeBetweenEvictionRunsMillis(getDefaultTimeBetweenEvictionRunsMillis());

        final KeyedObjectPool<UserPassKey, PooledConnectionAndInfo> tmpPool = new GenericKeyedObjectPool<>(factory,
                config);
        factory.setPool(tmpPool);
        pool = tmpPool;
    }
 
Example 26
/**
 * Check setTransactioIsolation and with four connection in connection pool
 * for DERBY-4343 case
 *
 * @throws SQLException
 */
public void testIsolationWithFourConnections()
        throws SQLException {
    ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();

    PooledConnection pc = ds.getPooledConnection();
    //First connection
    Connection conn = pc.getConnection();
    conn.setAutoCommit(false);
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    Statement s = conn.createStatement();
    ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM SYS.SYSTABLES");
    rs.next();
    int ri = rs.getInt(1);
    rs.close();
    conn.rollback();
    conn.close();

    //Second connection
    conn = pc.getConnection();
    conn.close();

    //Third connection
    conn = pc.getConnection();
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    assertEquals(Connection.TRANSACTION_READ_COMMITTED, conn.getTransactionIsolation());
    conn.close();

    //Fourth connetion
    conn = pc.getConnection();
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
    assertEquals(Connection.TRANSACTION_READ_UNCOMMITTED, conn.getTransactionIsolation());
    conn.close();

}
 
Example 27
Source Project: dremio-oss   Source File: CompatCreator.java    License: Apache License 2.0 5 votes vote down vote up
private static SharedPoolDataSource newSharedDataSource(final ConnectionPoolDataSource source) {
  SharedPoolDataSource ds = new SharedPoolDataSource();
  ds.setConnectionPoolDataSource(source);
  ds.setMaxTotal(Integer.MAX_VALUE);
  ds.setDefaultTestOnBorrow(true);
  ds.setValidationQueryTimeout(1);
  return ds;
}
 
Example 28
/**
 * Create a new DataSource object setup from the passed in TestConfiguration.
 * The getPooledConnection() method is configured
 * to use the user name and password from the configuration.
 */
static ConnectionPoolDataSource getConnectionPoolDataSource(
        TestConfiguration config,
        HashMap beanProperties)
{
    if (beanProperties == null)
         beanProperties = JDBCDataSource.getDataSourceProperties(config);
    
    String dataSourceClass = config.getJDBCClient().getConnectionPoolDataSourceClassName();
    
    return (ConnectionPoolDataSource) JDBCDataSource.getDataSourceObject(
            dataSourceClass, beanProperties);
}
 
Example 29
/**
 * Test that a JDBC 3 data source returns a JDBC 4 PooledConnection
 * when running with a JDBC 4 JDK.
 */
public void testPooledConnection() throws Exception
{
    ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();

    assertNonJDBC4DataSource((DataSource)ds);
    checkJDBC4Interface(ds.getPooledConnection());
}
 
Example 30
/**
 * Get a connection from a single use ConnectionPoolDataSource configured
 * from the configuration but with the passed in property set.
 */
private ConnectionPoolDataSource singleUseDS(String property, String value)
   throws SQLException {
    HashMap hm = JDBCDataSource.getDataSourceProperties(config);
    hm.put(property, value);
    ConnectionPoolDataSource sds =
            J2EEDataSource.getConnectionPoolDataSource(config, hm);
    return sds;
}