當前位置: 首頁>>代碼示例>>Java>>正文


Java ConnectionPoolDataSource類代碼示例

本文整理匯總了Java中javax.sql.ConnectionPoolDataSource的典型用法代碼示例。如果您正苦於以下問題:Java ConnectionPoolDataSource類的具體用法?Java ConnectionPoolDataSource怎麽用?Java ConnectionPoolDataSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConnectionPoolDataSource類屬於javax.sql包,在下文中一共展示了ConnectionPoolDataSource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: connectionPool

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
@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;
}
 
開發者ID:jcustenborder,項目名稱:kafka-connect-cdc-mssql,代碼行數:18,代碼來源:MsSqlConnectionPoolDataSourceFactory.java

示例2: MiniConnectionPoolManager

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:24,代碼來源:MiniConnectionPoolManager.java

示例3: connectionPool

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
@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;
}
 
開發者ID:jcustenborder,項目名稱:kafka-connect-cdc-oracle,代碼行數:20,代碼來源:OracleConnectionPoolDataSourceFactory.java

示例4: JavaDBStorageEngine

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:24,代碼來源:JavaDBStorageEngine.java

示例5: createConnectionPoolDataSource

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:vdr007,項目名稱:ThriftyPaxos,代碼行數:30,代碼來源:OsgiDataSourceFactory.java

示例6: getDataSource

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:hksoni,項目名稱:SDN-Multicast,代碼行數:29,代碼來源:JavaDBStorageEngine.java

示例7: openConnection

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
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();
   }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:23,代碼來源:ConnectionPoolDataSourceConnector.java

示例8: assertConSetOK

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
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");
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:21,代碼來源:PoolXADSCreateShutdownDBTest.java

示例9: assertSetConOK

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
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);
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:22,代碼來源:PoolXADSCreateShutdownDBTest.java

示例10: embeddedTestAttributesAsPasswordWithPassword_pooled

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:21,代碼來源:DataSourcePropertiesTest.java

示例11: assertConnectionWOUPFail

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
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);
    }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:17,代碼來源:PoolDSAuthenticationTest.java

示例12: assertShutdownWOUPOK

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
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);
    }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:17,代碼來源:PoolDSAuthenticationTest.java

示例13: assertShutdownWOUPFail

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
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);
    }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:17,代碼來源:PoolDSAuthenticationTest.java

示例14: assertSystemShutdownOK

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
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);
    }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:18,代碼來源:PoolDSAuthenticationTest.java

示例15: assertSystemShutdownFail

import javax.sql.ConnectionPoolDataSource; //導入依賴的package包/類
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);
    }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:17,代碼來源:PoolDSAuthenticationTest.java


注:本文中的javax.sql.ConnectionPoolDataSource類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。