Search in sources :

Example 41 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 42 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 43 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 44 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)

Example 45 with ConnectionPoolDataSource

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

the class cdsXid method testJira95pds.

// test jira-derby 95 - a NullPointerException was returned when passing
// an incorrect database name, should now give error XCY00
// with ConnectionPoolDataSource
public void testJira95pds() throws Exception {
    try {
        ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
        JDBCDataSource.setBeanProperty(pds, "databaseName", "jdbc:derby:boo");
        pds.getPooledConnection();
        fail("expected an SQLException!");
    } catch (SQLException sqle) {
        assertSQLState("XCY00", sqle);
    } catch (Exception e) {
        throw e;
    }
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) SQLException(java.sql.SQLException) SQLException(java.sql.SQLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XAException(javax.transaction.xa.XAException)

Aggregations

ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)71 PooledConnection (javax.sql.PooledConnection)33 SQLException (java.sql.SQLException)28 Connection (java.sql.Connection)19 XAConnection (javax.sql.XAConnection)15 XADataSource (javax.sql.XADataSource)12 Statement (java.sql.Statement)8 CallableStatement (java.sql.CallableStatement)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)5 InitialContext (javax.naming.InitialContext)5 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 Savepoint (java.sql.Savepoint)2 Properties (java.util.Properties)2 SQLiteConnectionPoolDataSource (org.sqlite.javax.SQLiteConnectionPoolDataSource)2