当前位置: 首页>>代码示例>>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;未经允许,请勿转载。