use of javax.sql.ConnectionPoolDataSource in project derby by apache.
the class DataSourcePropertiesTest method embeddedTestAttributesAsPasswordWithPassword_pooled.
/**
* 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);
}
}
use of javax.sql.ConnectionPoolDataSource in project derby by apache.
the class PoolDSAuthenticationTest method assertConnectionFail.
public void assertConnectionFail(String dbName) throws SQLException {
ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
// 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);
}
}
use of javax.sql.ConnectionPoolDataSource in project derby by apache.
the class DeclareGlobalTempTableJavaJDBC30Test method testPooledConnectionClosed.
/**
* Temporary tables declared in a pooled connection should get dropped
* when that pooled connection is closed.
*
* @throws SQLException
*/
public void testPooledConnectionClosed() throws SQLException {
ConnectionPoolDataSource dscsp = J2EEDataSource.getConnectionPoolDataSource();
// In the first connection handle to the pooled connection, create
// physical session schema, create table t1 in it
PooledConnection pc = dscsp.getPooledConnection();
Connection pcon = pc.getConnection();
Statement s = pcon.createStatement();
try {
s.executeUpdate("CREATE schema SESSION");
} catch (SQLException e) {
assertSQLState("X0Y68", e);
}
s.executeUpdate("CREATE TABLE SESSION.tx(c21 int)");
s.executeUpdate("insert into SESSION.tx values(11)");
s.executeUpdate("insert into SESSION.tx values(12)");
s.executeUpdate("insert into SESSION.tx values(13)");
JDBC.assertSingleValueResultSet(s.executeQuery("select count(*) from SESSION.tx"), "3");
// Declare temp table with same name as physical table in SESSION schema
s.executeUpdate("declare global temporary table SESSION.tx(" + "c11 int, c12 int) on commit preserve rows not logged");
s.executeUpdate("insert into SESSION.tx values(11,1)");
JDBC.assertSingleValueResultSet(s.executeQuery("select count(*) from SESSION.tx"), "1");
commit();
// Now close the connection handle to the pooled connection
getConnection().close();
// Do another getConnection() to get a new connection handle to the
// pooled connection
s = getConnection().createStatement();
// In this new handle, a select * from SESSION.tx should be looking at
// the physical session table
JDBC.assertSingleValueResultSet(s.executeQuery("select count(*) from SESSION.tx"), "3");
s.executeUpdate("drop table SESSION.tx");
}
use of javax.sql.ConnectionPoolDataSource in project mssql-jdbc by Microsoft.
the class DataFactoryTest method verifyFactoryPooledConnection.
private void verifyFactoryPooledConnection(DataSourceFactory dsFactory) throws SQLException {
Properties props = new Properties();
props.setProperty(DataSourceFactory.JDBC_URL, connectionString);
ConnectionPoolDataSource ds = dsFactory.createConnectionPoolDataSource(props);
PooledConnection c = ds.getPooledConnection();
try (Statement s = c.getConnection().createStatement()) {
try (ResultSet rs = s.executeQuery("SELECT 1")) {
assertTrue("Resultset is empty.", rs.next());
}
} finally {
c.close();
}
}
use of javax.sql.ConnectionPoolDataSource in project commons-dbcp 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);
}
}
Aggregations