Java 类javax.sql.ConnectionPoolDataSource 实例源码

项目:kafka-connect-cdc-mssql    文件:MsSqlConnectionPoolDataSourceFactory.java   
@Override
public ConnectionPoolDataSource connectionPool(ConnectionKey connectionKey) throws SQLException {
  SQLServerConnectionPoolDataSource dataSource = new SQLServerConnectionPoolDataSource();
  dataSource.setServerName(this.config.serverName);
  dataSource.setPortNumber(this.config.serverPort);
  dataSource.setUser(this.config.jdbcUsername);
  dataSource.setPassword(this.config.jdbcPassword);
  dataSource.setMultiSubnetFailover(this.config.multiSubnetFailover);

  if (Strings.isNullOrEmpty(connectionKey.databaseName)) {
    dataSource.setDatabaseName(this.config.initialDatabase);
  } else {
    dataSource.setDatabaseName(connectionKey.databaseName);
  }

  return dataSource;
}
项目:drd    文件:MiniConnectionPoolManager.java   
/**
 * 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();
}
项目:monarch    文件:GemFireConnPooledDataSource.java   
public GemFireConnPooledDataSource(ConnectionPoolDataSource connPoolDS,
    ConfiguredDataSourceProperties configs) throws SQLException {
  super(configs);
  if ((connPoolDS == null) || (configs == null))
    throw new SQLException(
        LocalizedStrings.GemFireConnPooledDataSource_GEMFIRECONNPOOLEDDATASOURCECONNECTIONPOOLDATASOURCE_CLASS_OBJECT_IS_NULL_OR_CONFIGUREDDATASOURCEPROPERTIES_OBJECT_IS_NULL
            .toLocalizedString());
  try {
    provider = new GemFireConnectionPoolManager(connPoolDS, configs, this);
  } catch (Exception ex) {
    StringId exception =
        LocalizedStrings.GemFireConnPooledDataSource_EXCEPTION_CREATING_GEMFIRECONNECTIONPOOLMANAGER;
    logger.error(LocalizedMessage.create(exception, ex.getLocalizedMessage()), ex);
    throw new SQLException(exception.toLocalizedString(ex));
  }
}
项目:kafka-connect-cdc-oracle    文件:OracleConnectionPoolDataSourceFactory.java   
@Override
public ConnectionPoolDataSource connectionPool(ConnectionKey connectionKey) throws SQLException {
  OracleConnectionPoolDataSource a = new OracleConnectionPoolDataSource();
  a.setUser(this.config.jdbcUsername);
  a.setDriverType("oci");
  a.setPassword(this.config.jdbcPassword);
  a.setServerName(this.config.serverName);
  a.setPortNumber(this.config.serverPort);

  if (!Strings.isNullOrEmpty(connectionKey.databaseName)) {
    a.setServiceName(connectionKey.databaseName);
  } else {
    a.setServiceName(this.config.initialDatabase);
  }

  log.trace("{}: Computed JdbcUrl {}", connectionKey, a.getURL());

  return a;
}
项目:fresco_floodlight    文件:JavaDBStorageEngine.java   
/**
 * Construct a new storage engine that will use the provided engine
 * as a delegate and provide persistence for its data.  Note that
 * the delegate engine must be empty when this object is constructed
 * @param delegate the delegate engine to persist
 * @throws SyncException 
 */
public JavaDBStorageEngine(String name, 
                           ConnectionPoolDataSource dataSource)
        throws PersistException {
    super();

    this.name = name;
    this.dbTableName = name.replace('.', '_');
    this.dataSource = dataSource;

    try {
        initTable();
    } catch (SQLException sqle) {
        throw new PersistException("Could not initialize persistent storage",
                                   sqle);
    }
}
项目:iTAP-controller    文件:JavaDBStorageEngine.java   
/**
 * Construct a new storage engine that will use the provided engine
 * as a delegate and provide persistence for its data.  Note that
 * the delegate engine must be empty when this object is constructed
 * @param delegate the delegate engine to persist
 * @throws SyncException 
 */
public JavaDBStorageEngine(String name, 
                           ConnectionPoolDataSource dataSource)
        throws PersistException {
    super();

    this.name = name;
    this.dbTableName = name.replace('.', '_');
    this.dataSource = dataSource;

    try {
        initTable();
    } catch (SQLException sqle) {
        throw new PersistException("Could not initialize persistent storage",
                                   sqle);
    }
}
项目:ThriftyPaxos    文件:OsgiDataSourceFactory.java   
/**
 * Creates a pooled data source.
 *
 * @param properties the properties for the data source.
 * @throws SQLException if unsupported properties are supplied, or if data
 *             source can not be created.
 * @return a new data source.
 */
@Override
public ConnectionPoolDataSource createConnectionPoolDataSource(
        Properties properties) throws SQLException {
    // Make copy of properties
    Properties propertiesCopy = new Properties();
    if (properties != null) {
        propertiesCopy.putAll(properties);
    }

    // Verify that no unsupported standard options are used
    rejectUnsupportedOptions(propertiesCopy);

    // The integrated connection pool is H2 is not configurable
    rejectPoolingOptions(propertiesCopy);

    JdbcDataSource dataSource = new JdbcDataSource();

    setupH2DataSource(dataSource, propertiesCopy);

    return dataSource;
}
项目:SDN-Multicast    文件:JavaDBStorageEngine.java   
/**
 * Construct a new storage engine that will use the provided engine
 * as a delegate and provide persistence for its data.  Note that
 * the delegate engine must be empty when this object is constructed
 * @param delegate the delegate engine to persist
 * @throws SyncException 
 */
public JavaDBStorageEngine(String name, 
                           ConnectionPoolDataSource dataSource)
        throws PersistException {
    super();

    this.name = name;
    this.dbTableName = name.replace('.', '_');
    this.dataSource = dataSource;

    try {
        initTable();
    } catch (SQLException sqle) {
        throw new PersistException("Could not initialize persistent storage",
                                   sqle);
    }
}
项目:SDN-Multicast    文件:JavaDBStorageEngine.java   
/**
 * Get a connection pool data source for use by Java DB storage engines
 * @param dbPath The path where the db will be located
 * @param memory whether to actually use a memory database
 * @return the {@link ConnectionPoolDataSource}
 */
public static ConnectionPoolDataSource getDataSource(String dbPath, 
                                                     boolean memory) {

    EmbeddedConnectionPoolDataSource40 ds = 
            new EmbeddedConnectionPoolDataSource40();
    if (memory) {
        ds.setDatabaseName("memory:SyncDB");                
    } else {
        String path = "SyncDB";
        if (dbPath != null) {
            File f = new File(dbPath);
            f = new File(dbPath,"SyncDB");
            path = f.getAbsolutePath();
        }            

        ds.setDatabaseName(path);
    }
    ds.setCreateDatabase("create");
    ds.setUser("floodlight");
    ds.setPassword("floodlight");
    return ds;
}
项目:arscheduler    文件:JavaDBStorageEngine.java   
/**
 * Construct a new storage engine that will use the provided engine
 * as a delegate and provide persistence for its data.  Note that
 * the delegate engine must be empty when this object is constructed
 * @param delegate the delegate engine to persist
 * @throws SyncException 
 */
public JavaDBStorageEngine(String name, 
                           ConnectionPoolDataSource dataSource)
        throws PersistException {
    super();

    this.name = name;
    this.dbTableName = name.replace('.', '_');
    this.dataSource = dataSource;

    try {
        initTable();
    } catch (SQLException sqle) {
        throw new PersistException("Could not initialize persistent storage",
                                   sqle);
    }
}
项目:arscheduler    文件:JavaDBStorageEngine.java   
/**
 * Get a connection pool data source for use by Java DB storage engines
 * @param dbPath The path where the db will be located
 * @param memory whether to actually use a memory database
 * @return the {@link ConnectionPoolDataSource}
 */
public static ConnectionPoolDataSource getDataSource(String dbPath, 
                                                     boolean memory) {

    EmbeddedConnectionPoolDataSource40 ds = 
            new EmbeddedConnectionPoolDataSource40();
    if (memory) {
        ds.setDatabaseName("memory:SyncDB");                
    } else {
        String path = "SyncDB";
        if (dbPath != null) {
            File f = new File(dbPath);
            f = new File(dbPath,"SyncDB");
            path = f.getAbsolutePath();
        }            

        ds.setDatabaseName(path);
    }
    ds.setCreateDatabase("create");
    ds.setUser("floodlight");
    ds.setPassword("floodlight");
    return ds;
}
项目:gemfirexd-oss    文件:ConnectionPoolDataSourceConnector.java   
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();
   }
}
项目:gemfirexd-oss    文件:ConnectionPoolDataSourceConnector.java   
public Connection openConnection(String databaseName,
                                 String user,
                                 String password)
        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;
        ConnectionPoolDataSource tmpDs =
                singleUseDS("createDatabase", "create");
        JDBCDataSource.setBeanProperty(tmpDs, "databaseName", databaseName);
        return tmpDs.getPooledConnection(user, password).getConnection(); 
   }
}
项目:gemfirexd-oss    文件:PoolXADSCreateShutdownDBTest.java   
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");
}
项目:gemfirexd-oss    文件:PoolXADSCreateShutdownDBTest.java   
protected void assertSetConOK(Object ds, String expectedSQLState, 
    String dbName, String connAttrValue, String setter, String setValue) 
throws SQLException {
    JDBCDataSource.setBeanProperty(ds, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(
        ds, "ConnectionAttributes", connAttrValue);
    JDBCDataSource.setBeanProperty(ds, setter, setValue);
    // 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, "ConnectionAttributes");
    JDBCDataSource.clearStringBeanProperty(ds, setter);
}
项目:gemfirexd-oss    文件:DataSourcePropertiesTest.java   
/**
 * 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);
    }
}
项目:gemfirexd-oss    文件:PoolDSAuthenticationTest.java   
protected void assertConnectionWOUPFail(
    String expectedSqlState, 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);
    try {
        pds.getPooledConnection();
        fail("Connection should've been refused/failed");
    }
    catch (SQLException e) {
            assertSQLState(expectedSqlState, e);
    }
}
项目:gemfirexd-oss    文件:PoolDSAuthenticationTest.java   
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);
    }
}
项目:gemfirexd-oss    文件:PoolDSAuthenticationTest.java   
protected void assertShutdownWOUPFail(
    String expectedSqlState, String dbName, String user, String password) 
throws SQLException
{
    ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
    JDBCDataSource.setBeanProperty(pds, "shutdownDatabase", "shutdown");
    JDBCDataSource.setBeanProperty(pds, "user", user);
    JDBCDataSource.setBeanProperty(pds, "password", password);
    JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
    try {
        pds.getPooledConnection();
        fail("expected failed shutdown");
    } catch (SQLException e) {
        assertSQLState(expectedSqlState, e);
    }
}
项目:gemfirexd-oss    文件:PoolDSAuthenticationTest.java   
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);
    }
}
项目:gemfirexd-oss    文件:PoolDSAuthenticationTest.java   
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);
    }
}
项目:gemfirexd-oss    文件:PoolDSAuthenticationTest.java   
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);
    }
}
项目:gemfirexd-oss    文件:J2EEDataSourceTest.java   
/**
 * 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());
}
项目:gemfirexd-oss    文件:J2EEDataSourceTest.java   
/**
 * 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);
    }
}
项目:gemfirexd-oss    文件:J2EEDataSourceTest.java   
/**
 * 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();       
}
项目:gemfirexd-oss    文件:J2EEDataSourceTest.java   
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) {
        // DERBY-2498 - when fixed, remove if
        if (usingEmbedded())
            assertSQLState("XCY00", sqle);
    } catch (Exception e) {
        // DERBY-2498 - when fixed, remove if
        if (usingEmbedded())
            throw e;
    }
}
项目:gemfirexd-oss    文件:J2EEDataSourceTest.java   
/**
 * 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();
}
项目:gemfirexd-oss    文件:J2EEDataSourceTest.java   
/**
 * 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();
}
项目:gemfirexd-oss    文件:J2EEDataSourceTest.java   
private static void dsConnectionRequests(
    String[] expectedValues, ConnectionPoolDataSource ds) {
    try {
        ds.getPooledConnection();
        if (!expectedValues[0].equals("OK"))
            fail (" expected connection to fail, but was OK");
    } catch (SQLException sqle) {
        assertSQLState(expectedValues[0], sqle);
    }

    dsConnectionRequest(expectedValues[1], ds, null, null);
    dsConnectionRequest(expectedValues[2], ds, "fred", null);
    dsConnectionRequest(expectedValues[3], ds, "fred", "wilma");
    dsConnectionRequest(expectedValues[4], ds, null, "wilma");
    dsConnectionRequest(
        expectedValues[5], ds, null, "databaseName=wombat");
    dsConnectionRequest(
        expectedValues[6], ds, "fred", "databaseName=wombat");
    dsConnectionRequest(expectedValues[7], 
        ds, "fred", "databaseName=wombat;password=wilma");
    dsConnectionRequest(expectedValues[8], 
        ds, "fred", "databaseName=wombat;password=betty");
}
项目:gemfirexd-oss    文件:StatementPoolingTest.java   
/**
 * 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();
}
项目:gemfirexd-oss    文件:StatementPoolingTest.java   
/**
 * 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();
}
项目:gemfirexd-oss    文件:NSSecurityMechanismTest.java   
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;
}
项目:QoS-floodlight    文件:JavaDBStorageEngine.java   
/**
 * Construct a new storage engine that will use the provided engine
 * as a delegate and provide persistence for its data.  Note that
 * the delegate engine must be empty when this object is constructed
 * @param delegate the delegate engine to persist
 * @throws SyncException 
 */
public JavaDBStorageEngine(String name, 
                           ConnectionPoolDataSource dataSource)
        throws PersistException {
    super();

    this.name = name;
    this.dbTableName = name.replace('.', '_');
    this.dataSource = dataSource;

    try {
        initTable();
    } catch (SQLException sqle) {
        throw new PersistException("Could not initialize persistent storage",
                                   sqle);
    }
}
项目:QoS-floodlight    文件:JavaDBStorageEngine.java   
/**
 * Get a connection pool data source for use by Java DB storage engines
 * @param dbPath The path where the db will be located
 * @param memory whether to actually use a memory database
 * @return the {@link ConnectionPoolDataSource}
 */
public static ConnectionPoolDataSource getDataSource(String dbPath, 
                                                     boolean memory) {

    EmbeddedConnectionPoolDataSource40 ds = 
            new EmbeddedConnectionPoolDataSource40();
    if (memory) {
        ds.setDatabaseName("memory:SyncDB");                
    } else {
        String path = "SyncDB";
        if (dbPath != null) {
            File f = new File(dbPath);
            f = new File(dbPath,"SyncDB");
            path = f.getAbsolutePath();
        }            

        ds.setDatabaseName(path);
    }
    ds.setCreateDatabase("create");
    ds.setUser("floodlight");
    ds.setPassword("floodlight");
    return ds;
}
项目:floodlight1.2-delay    文件:JavaDBStorageEngine.java   
/**
 * Construct a new storage engine that will use the provided engine
 * as a delegate and provide persistence for its data.  Note that
 * the delegate engine must be empty when this object is constructed
 * @param delegate the delegate engine to persist
 * @throws SyncException 
 */
public JavaDBStorageEngine(String name, 
                           ConnectionPoolDataSource dataSource)
        throws PersistException {
    super();

    this.name = name;
    this.dbTableName = name.replace('.', '_');
    this.dataSource = dataSource;

    try {
        initTable();
    } catch (SQLException sqle) {
        throw new PersistException("Could not initialize persistent storage",
                                   sqle);
    }
}
项目:floodlight1.2-delay    文件:JavaDBStorageEngine.java   
/**
 * Get a connection pool data source for use by Java DB storage engines
 * @param dbPath The path where the db will be located
 * @param memory whether to actually use a memory database
 * @return the {@link ConnectionPoolDataSource}
 */
public static ConnectionPoolDataSource getDataSource(String dbPath, 
                                                     boolean memory) {

    EmbeddedConnectionPoolDataSource40 ds = 
            new EmbeddedConnectionPoolDataSource40();
    if (memory) {
        ds.setDatabaseName("memory:SyncDB");                
    } else {
        String path = "SyncDB";
        if (dbPath != null) {
            File f = new File(dbPath);
            f = new File(dbPath,"SyncDB");
            path = f.getAbsolutePath();
        }            

        ds.setDatabaseName(path);
    }
    ds.setCreateDatabase("create");
    ds.setUser("floodlight");
    ds.setPassword("floodlight");
    return ds;
}
项目:floodlight-hardware    文件:JavaDBStorageEngine.java   
/**
 * Construct a new storage engine that will use the provided engine
 * as a delegate and provide persistence for its data.  Note that
 * the delegate engine must be empty when this object is constructed
 * @param delegate the delegate engine to persist
 * @throws SyncException
 */
public JavaDBStorageEngine(String name,
                           ConnectionPoolDataSource dataSource)
        throws PersistException {
    super();

    this.name = name;
    this.dbTableName = name.replace('.', '_');
    this.dataSource = dataSource;

    try {
        initTable();
    } catch (SQLException sqle) {
        throw new PersistException("Could not initialize persistent storage",
                                   sqle);
    }
}
项目:floodlight-hardware    文件:JavaDBStorageEngine.java   
/**
 * Get a connection pool data source for use by Java DB storage engines
 * @param dbPath The path where the db will be located
 * @param memory whether to actually use a memory database
 * @return the {@link ConnectionPoolDataSource}
 */
public static ConnectionPoolDataSource getDataSource(String dbPath,
                                                     boolean memory) {

    EmbeddedConnectionPoolDataSource40 ds =
            new EmbeddedConnectionPoolDataSource40();
    if (memory) {
        ds.setDatabaseName("memory:SyncDB");
    } else {
        String path = "SyncDB";
        if (dbPath != null) {
            File f = new File(dbPath);
            f = new File(dbPath,"SyncDB");
            path = f.getAbsolutePath();
        }

        ds.setDatabaseName(path);
    }
    ds.setCreateDatabase("create");
    ds.setUser("floodlight");
    ds.setPassword("floodlight");
    return ds;
}
项目:ACAMPController    文件:JavaDBStorageEngine.java   
/**
 * Construct a new storage engine that will use the provided engine
 * as a delegate and provide persistence for its data.  Note that
 * the delegate engine must be empty when this object is constructed
 * @param delegate the delegate engine to persist
 * @throws SyncException 
 */
public JavaDBStorageEngine(String name, 
                           ConnectionPoolDataSource dataSource)
        throws PersistException {
    super();

    this.name = name;
    this.dbTableName = name.replace('.', '_');
    this.dataSource = dataSource;

    try {
        initTable();
    } catch (SQLException sqle) {
        throw new PersistException("Could not initialize persistent storage",
                                   sqle);
    }
}
项目:ACAMPController    文件:JavaDBStorageEngine.java   
/**
 * Get a connection pool data source for use by Java DB storage engines
 * @param dbPath The path where the db will be located
 * @param memory whether to actually use a memory database
 * @return the {@link ConnectionPoolDataSource}
 */
public static ConnectionPoolDataSource getDataSource(String dbPath, 
                                                     boolean memory) {

    EmbeddedConnectionPoolDataSource40 ds = 
            new EmbeddedConnectionPoolDataSource40();
    if (memory) {
        ds.setDatabaseName("memory:SyncDB");                
    } else {
        String path = "SyncDB";
        if (dbPath != null) {
            File f = new File(dbPath);
            f = new File(dbPath,"SyncDB");
            path = f.getAbsolutePath();
        }            

        ds.setDatabaseName(path);
    }
    ds.setCreateDatabase("create");
    ds.setUser("floodlight");
    ds.setPassword("floodlight");
    return ds;
}