Search in sources :

Example 36 with ConnectionPoolDataSource

use of javax.sql.ConnectionPoolDataSource in project tomcat by apache.

the class PerUserPoolDataSource method registerPool.

private synchronized void registerPool(final String userName, final String password) throws NamingException, SQLException {
    final ConnectionPoolDataSource cpds = testCPDS(userName, password);
    // Set up the factory we will use (passing the pool associates
    // the factory with the pool, so we do not have to do so
    // explicitly)
    final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, getValidationQuery(), getValidationQueryTimeoutDuration(), isRollbackAfterValidation(), userName, password);
    factory.setMaxConn(getMaxConnDuration());
    // Create an object pool to contain our PooledConnections
    final GenericObjectPool<PooledConnectionAndInfo> pool = new GenericObjectPool<>(factory);
    factory.setPool(pool);
    pool.setBlockWhenExhausted(getPerUserBlockWhenExhausted(userName));
    pool.setEvictionPolicyClassName(getPerUserEvictionPolicyClassName(userName));
    pool.setLifo(getPerUserLifo(userName));
    pool.setMaxIdle(getPerUserMaxIdle(userName));
    pool.setMaxTotal(getPerUserMaxTotal(userName));
    pool.setMaxWait(Duration.ofMillis(getPerUserMaxWaitMillis(userName)));
    pool.setMinEvictableIdle(getPerUserMinEvictableIdleDuration(userName));
    pool.setMinIdle(getPerUserMinIdle(userName));
    pool.setNumTestsPerEvictionRun(getPerUserNumTestsPerEvictionRun(userName));
    pool.setSoftMinEvictableIdle(getPerUserSoftMinEvictableIdleDuration(userName));
    pool.setTestOnCreate(getPerUserTestOnCreate(userName));
    pool.setTestOnBorrow(getPerUserTestOnBorrow(userName));
    pool.setTestOnReturn(getPerUserTestOnReturn(userName));
    pool.setTestWhileIdle(getPerUserTestWhileIdle(userName));
    pool.setTimeBetweenEvictionRuns(getPerUserDurationBetweenEvictionRuns(userName));
    pool.setSwallowedExceptionListener(new SwallowedExceptionLogger(log));
    final PooledConnectionManager old = managers.put(getPoolKey(userName), factory);
    if (old != null) {
        throw new IllegalStateException("Pool already contains an entry for this user/password: " + userName);
    }
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) SwallowedExceptionLogger(org.apache.tomcat.dbcp.dbcp2.SwallowedExceptionLogger) GenericObjectPool(org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool)

Example 37 with ConnectionPoolDataSource

use of javax.sql.ConnectionPoolDataSource in project mssql-jdbc by Microsoft.

the class JDBC43Test method connectionPoolDataSourceTest.

/**
 * Tests that we are throwing the unsupported exception for createPooledConnectionBuilder()
 * @throws SQLException
 * @throws TestAbortedException
 * @since 1.9
 */
@Test
public void connectionPoolDataSourceTest() throws TestAbortedException, SQLException {
    assumeTrue(Util.supportJDBC43(connection));
    ConnectionPoolDataSource ds = new SQLServerConnectionPoolDataSource();
    try {
        superShardingKey = ds.createShardingKeyBuilder().subkey("EASTERN_REGION", JDBCType.VARCHAR).build();
    } catch (SQLException e) {
        assert (e.getMessage().contains("not implemented"));
    }
    try {
        shardingKey = ds.createShardingKeyBuilder().subkey("PITTSBURGH_BRANCH", JDBCType.VARCHAR).build();
    } catch (SQLException e) {
        assert (e.getMessage().contains("not implemented"));
    }
    try {
        PooledConnection con = ds.createPooledConnectionBuilder().user("rafa").password("tennis").shardingKey(shardingKey).superShardingKey(superShardingKey).build();
    } catch (SQLException e) {
        assert (e.getMessage().contains("not implemented"));
    }
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) PooledConnection(javax.sql.PooledConnection) SQLException(java.sql.SQLException) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 38 with ConnectionPoolDataSource

use of javax.sql.ConnectionPoolDataSource in project derby by apache.

the class NSSecurityMechanismTest method getCPDS.

private javax.sql.ConnectionPoolDataSource getCPDS(String user, String password) {
    HashMap<String, Object> attrs = new HashMap<String, Object>();
    if (user != null)
        attrs.put("user", user);
    if (password != null)
        attrs.put("password", password);
    attrs = addRequiredAttributes(attrs);
    ConnectionPoolDataSource cpds = J2EEDataSource.getConnectionPoolDataSource();
    for (String property : attrs.keySet()) {
        Object value = attrs.get(property);
        JDBCDataSource.setBeanProperty(cpds, property, value);
    }
    return cpds;
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) HashMap(java.util.HashMap)

Example 39 with ConnectionPoolDataSource

use of javax.sql.ConnectionPoolDataSource in project derby by apache.

the class DataSourcePropertiesTest method embeddedTestAttributesAsPasswordWithoutPassword_pooled.

/**
 * Tests that the default password is not sent as an attribute string when
 * <code>attributesAsPassword</code> is <code>true</code>. The test is run
 * with a <code>ConnectionPoolDataSource</code>.
 */
public void embeddedTestAttributesAsPasswordWithoutPassword_pooled() throws Exception {
    ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
    JDBCDataSource.setBeanProperty(ds, "password", "mypassword");
    JDBCDataSource.setBeanProperty(ds, "attributesAsPassword", Boolean.TRUE);
    // DERBY-1586 caused a malformed url error here
    PooledConnection pc = ds.getPooledConnection();
    Connection c = pc.getConnection();
    c.close();
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) PooledConnection(javax.sql.PooledConnection) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection)

Example 40 with ConnectionPoolDataSource

use of javax.sql.ConnectionPoolDataSource in project derby by apache.

the class VerifySignatures method collectClassesFromConnectionPoolDataSource.

/**
 * Obtain a connection from a <code>ConnectionPoolDataSource</code>
 * object and perform JDBC operations on it. Collect the classes
 * of all JDBC objects that are found.
 *
 * @param classes set into which classes are collected
 * @exception SQLException if a database error occurs
 */
private static void collectClassesFromConnectionPoolDataSource(Set<ClassInfo> classes) throws SQLException {
    ConnectionPoolDataSource cpds = J2EEDataSource.getConnectionPoolDataSource();
    addClass(classes, cpds.getClass(), javax.sql.ConnectionPoolDataSource.class);
    PooledConnection pc = cpds.getPooledConnection(TestConfiguration.getCurrent().getUserName(), TestConfiguration.getCurrent().getUserPassword());
    addClass(classes, pc.getClass(), javax.sql.PooledConnection.class);
    collectClassesFromConnection(pc.getConnection(), classes);
    pc.close();
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) PooledConnection(javax.sql.PooledConnection)

Aggregations

ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)63 PooledConnection (javax.sql.PooledConnection)29 SQLException (java.sql.SQLException)25 Connection (java.sql.Connection)17 XAConnection (javax.sql.XAConnection)15 XADataSource (javax.sql.XADataSource)12 CallableStatement (java.sql.CallableStatement)7 Statement (java.sql.Statement)7 DataSource (javax.sql.DataSource)7 PreparedStatement (java.sql.PreparedStatement)6 J2EEDataSource (org.apache.derbyTesting.junit.J2EEDataSource)6 JDBCDataSource (org.apache.derbyTesting.junit.JDBCDataSource)6 ResultSet (java.sql.ResultSet)5 Context (javax.naming.Context)3 InitialContext (javax.naming.InitialContext)3 Test (org.junit.Test)3 Savepoint (java.sql.Savepoint)2 Properties (java.util.Properties)2 JTAEnvironmentBean (com.arjuna.ats.jta.common.JTAEnvironmentBean)1 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)1