当前位置: 首页>>代码示例>>Java>>正文


Java PoolableConnection类代码示例

本文整理汇总了Java中org.apache.commons.dbcp2.PoolableConnection的典型用法代码示例。如果您正苦于以下问题:Java PoolableConnection类的具体用法?Java PoolableConnection怎么用?Java PoolableConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PoolableConnection类属于org.apache.commons.dbcp2包,在下文中一共展示了PoolableConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPool

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
private ObjectPool<PoolableConnection> createPool(String connectionString) {
    // A ConnectionFactory that the pool will use to create Connections.
    ConnectionFactory connectionFactory =
            new DriverManagerConnectionFactory(connectionString, null);
    // PoolableConnectionFactory wraps the real Connections with the
    // classes that implement the pooling functionality.
    PoolableConnectionFactory poolableConnectionFactory =
            new PoolableConnectionFactory(connectionFactory, null);
    poolableConnectionFactory.setValidationQuery("SELECT 1");

    // Actual pool of connections.
    GenericObjectPool<PoolableConnection> connectionPool =
            new GenericObjectPool<>(poolableConnectionFactory);
    int connMax = getConfig()
            .getInt(OctopusConfiguration.MASTER_CONNECTION_POOL_MAX, 8);
    connectionPool.setMaxTotal(connMax);
    connectionPool.setTestOnBorrow(true);
    // Set the factory's pool property to the owning pool.
    poolableConnectionFactory.setPool(connectionPool);

    return connectionPool;
}
 
开发者ID:bitnine-oss,项目名称:octopus,代码行数:23,代码来源:ConnectionManager.java

示例2: check

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
@Override
protected Result check() throws Exception {

	GenericObjectPool<PoolableConnection> pool = (GenericObjectPool<PoolableConnection>) connectionPool;
	if (pool.getNumWaiters() > maxWaitingConnections) {
		return Result.unhealthy("Overloaded connection pool.  name="
				+ poolName + " nbrWaiters=" + pool.getNumWaiters());
	}

	PoolableConnectionFactory poolFactory = (PoolableConnectionFactory) pool
			.getFactory();
	PoolableConnection conn = null;
	try {
		conn = pool.borrowObject();
		poolFactory.validateConnection(conn);
	} catch (Exception e) {
		return Result
				.unhealthy("Database connection validation error.  error="
						+ ExceptionUtils.getStackTrace(e));
	} finally {
		DbUtils.closeQuietly(conn);
	}

	return Result.healthy();
}
 
开发者ID:Derek-Ashmore,项目名称:moneta,代码行数:26,代码来源:DbcpConnectionPoolHealthCheck.java

示例3: setUp

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	org.hsqldb.jdbc.JDBCDriver.class.newInstance();
	Properties connectionProps=new Properties();
	connectionProps.put("user", "SA");
	connectionProps.put("password", "");
	connectionProps.put("create", "true");
	
	ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
			"jdbc:hsqldb:mem:my-sample",connectionProps);
	
	ObjectName poolName= poolName=new ObjectName("org.moneta", "connectionPool", "TestPool");
	poolableConnectionFactory=
			new PoolableConnectionFactory(connectionFactory,poolName);
	poolableConnectionFactory.setDefaultCatalog("PUBLIC");
	poolableConnectionFactory.setValidationQuery(VALIDATION_SQL);
	
	connectionPool = 
			new GenericObjectPool<PoolableConnection>(poolableConnectionFactory);
	poolableConnectionFactory.setPool(connectionPool);
	connectionPool.setMaxTotal(2);
	connectionPool.setMaxWaitMillis(400);
	
	healthCheck = new DbcpConnectionPoolHealthCheck(connectionPool, "mine");
}
 
开发者ID:Derek-Ashmore,项目名称:moneta,代码行数:26,代码来源:DbcpConnectionPoolHealthCheckTest.java

示例4: SqlCache

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
/**
 * Constructor.
 * 
 * @param dataSource
 *        The data source
 * @param maxSize
 *        The max entry count
 * @param poolSize
 *        The number of connections in the pool
 * @param lockSource
 *        The lock source
 */
public SqlCache( DataSource dataSource, int maxSize, int poolSize, LockSource lockSource )
{
	this.maxSize = maxSize;
	this.lockSource = lockSource;

	GenericObjectPoolConfig config = new GenericObjectPoolConfig();
	config.setMaxTotal( poolSize );
	config.setMaxIdle( poolSize );
	config.setMinIdle( poolSize );
	DataSourceConnectionFactory connectionFactory = new DataSourceConnectionFactory( dataSource );
	PoolableConnectionFactory pooledObjectFactory = new PoolableConnectionFactory( connectionFactory, null );
	GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<PoolableConnection>( pooledObjectFactory, config );
	pooledObjectFactory.setPool( pool );
	this.dataSource = new PoolingDataSource<PoolableConnection>( pool );
}
 
开发者ID:tliron,项目名称:prudence,代码行数:28,代码来源:SqlCache.java

示例5: start

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
@Override
public void start() {
    File databaseDir = new File(JiveGlobals.getHomeDirectory(), File.separator + "embedded-db");
    // If the database doesn't exist, create it.
    if (!databaseDir.exists()) {
        databaseDir.mkdirs();
    }

    try {
        serverURL = "jdbc:hsqldb:" + databaseDir.getCanonicalPath() + File.separator + "openfire";
    }
    catch (IOException ioe) {
        Log.error("EmbeddedConnectionProvider: Error starting connection pool: ", ioe);
    }
    final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(serverURL, "sa", "");
    final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
    poolableConnectionFactory.setMaxConnLifetimeMillis((long) (0.5 * JiveConstants.DAY));

    final GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMinIdle(3);
    poolConfig.setMaxTotal(25);
    final GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory, poolConfig);
    poolableConnectionFactory.setPool(connectionPool);
    dataSource = new PoolingDataSource<>(connectionPool);
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:26,代码来源:EmbeddedConnectionProvider.java

示例6: setup

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
private void setup() {
	try {
		Class.forName(driver);
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	}
	ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
			url, username, password);
	PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
			connectionFactory, null);
	ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(
			poolableConnectionFactory);
	poolableConnectionFactory.setPool(connectionPool);
	PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(
			connectionPool);
	this.dataSource = dataSource;
	logger.debug("get DataSource");
}
 
开发者ID:int32bit,项目名称:openstack-java-sdk,代码行数:19,代码来源:DataBaseAccessor.java

示例7: createPool

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
public static DataSource createPool(ConnectionFactory connectionFactory, int isolation) {
 
 
 
   PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
       connectionFactory, null);
   poolableConnectionFactory.setMaxConnLifetimeMillis(3000);
   poolableConnectionFactory.setDefaultAutoCommit(false);
   poolableConnectionFactory.setDefaultReadOnly(true);
   poolableConnectionFactory
       .setDefaultTransactionIsolation(isolation);
   ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(
       poolableConnectionFactory);
   poolableConnectionFactory.setPool(connectionPool);
   PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(
       connectionPool);
   return dataSource;
}
 
开发者ID:objectof-group,项目名称:objectof,代码行数:19,代码来源:ISql.java

示例8: createPool

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
public static DataSource createPool(String aName)
{
  ResourceBundle bundle = ResourceBundle.getBundle(aName);
  String password = bundle.getString("PWD");
  String principal = bundle.getString("PRINCIPAL");
  String conn = bundle.getString("CONNECTION");
  DriverManagerConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
      conn, principal, password);
  PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
      connectionFactory, null);
  ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(
      poolableConnectionFactory);
  poolableConnectionFactory.setPool(connectionPool);
  PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(
      connectionPool);
  return dataSource;
}
 
开发者ID:objectof-group,项目名称:objectof,代码行数:18,代码来源:ISql.java

示例9: create

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
static PoolableDataSource create(ConnectionFactory connectionFactory) {

        // setup our pool config object
        
        GenericObjectPoolConfig config = setupPoolConfig();
        
        PoolableConnectionFactory poolableConnectionFactory =
            new PoolableConnectionFactory(connectionFactory, null);
         
        // Set max lifetime of a connection in milli-secs, after which it will
        // always fail activation, passivation, and validation.
        // Value of -1 means infinite life time. The default value
        // defined in this class is 10 minutes.
        long connTtlMillis = retrieveConfigSetting(ATHENZ_PROP_DBPOOL_MAX_TTL, MAX_TTL_CONN_MS);
        poolableConnectionFactory.setMaxConnLifetimeMillis(connTtlMillis);
        if (LOG.isInfoEnabled()) {
            LOG.info("Setting Time-To-Live interval for live connections (" +
                    connTtlMillis + ") milli-secs");
        }
        
        ObjectPool<PoolableConnection> connectionPool =
                new GenericObjectPool<>(poolableConnectionFactory, config);
        poolableConnectionFactory.setPool(connectionPool);
        
        AthenzDataSource dataSource = new AthenzDataSource(connectionPool);
        return dataSource;
    }
 
开发者ID:yahoo,项目名称:athenz,代码行数:28,代码来源:DataSourceFactory.java

示例10: clearPoolConnections

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
@Override
synchronized public void clearPoolConnections() {
    ObjectPool<PoolableConnection> pool = getPool();
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Clearing all active/idle (" + pool.getNumActive() + "/" +
                    pool.getNumIdle() + ") connections from the pool");
        }
        pool.clear();
    } catch (Exception ex) {
        LOG.error("Unable to clear connections from the pool: " + ex.getMessage());
    }
}
 
开发者ID:yahoo,项目名称:athenz,代码行数:14,代码来源:AthenzDataSource.java

示例11: registerPool

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
public void registerPool(String dataSourceName, String driverName,
                         String connectionString)
        throws ClassNotFoundException {
    LOG.debug("register connection pool of the data source '" + dataSourceName + '"');

    if (!driverName.toLowerCase().equals("metamodel")) {
        Class.forName(driverName);
    }
    ObjectPool<PoolableConnection> connectionPool =
            createPool(connectionString);
    poolingDriver.registerPool(dataSourceName, connectionPool);
}
 
开发者ID:bitnine-oss,项目名称:octopus,代码行数:13,代码来源:ConnectionManager.java

示例12: DbcpConnectionPoolHealthCheck

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
public DbcpConnectionPoolHealthCheck(
		GenericObjectPool<PoolableConnection> pool, String poolName) {
	Validate.notNull(pool, "Null connection pool not allowed.");
	Validate.notEmpty(poolName, "Null or blank poolName not allowed.");
	Validate.isTrue(pool.getFactory() instanceof PoolableConnectionFactory,
			"this check only handles connection pools using PoolableConnectionFactory");
	connectionPool = pool;
	this.poolName = poolName;
	this.setMaxWaitingConnections(3);
}
 
开发者ID:Derek-Ashmore,项目名称:moneta,代码行数:11,代码来源:DbcpConnectionPoolHealthCheck.java

示例13: testBasicHappyPath

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
@Test
public void testBasicHappyPath() throws Exception {
	ObjectPool<PoolableConnection> pool = ConnectionPoolFactory.createConnectionPool(dataSource);
	Assert.assertTrue(pool != null);
	
	Connection conn = pool.borrowObject();
	Assert.assertTrue(conn != null);
	Assert.assertTrue(!conn.isClosed() );
}
 
开发者ID:Derek-Ashmore,项目名称:moneta,代码行数:10,代码来源:ConnectionPoolFactoryTest.java

示例14: getDataSource

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
private DataSource getDataSource() {
    if (dataSource == null) {

        String host = getConfigManager().get().getString(Keys.Db.SERVER);
        int port = getConfigManager().get().getInt(Keys.Db.PORT);
        String dbname = getConfigManager().get().getString(Keys.Db.DB_NAME);
        String user = getConfigManager().get().getString(Keys.Db.USER);
        String password = getConfigManager().get().getString(Keys.Db.PASSWORD);

        Properties props = new Properties();
        props.setProperty("user", user);
        props.setProperty("password", password);
        props.setProperty("defaultTransactionIsolation", "NONE");
        // props.setProperty("validationQuery", "SELECT 1");
        // props.setProperty("testOnBorrow", "true");

        String url = "jdbc:mysql://" + host + ":" + port + "/" + dbname + "?tcpKeepAlive=true";

        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
        poolConfig.setMinIdle(getDbCnxPoolMin());
        poolConfig.setMaxTotal(getDbCnxPoolMax());

        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, props);
        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
                null);
        GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory,
                poolConfig);
        poolableConnectionFactory.setPool(connectionPool);

        dataSource = new PoolingDataSource<>(connectionPool);

        LOG.info("MYSQL[default] connection to {}", url);
    }

    return dataSource;
}
 
开发者ID:AirVantage,项目名称:av-sched,代码行数:37,代码来源:ServiceLocator.java

示例15: setupDataSource

import org.apache.commons.dbcp2.PoolableConnection; //导入依赖的package包/类
public static DataSource setupDataSource(String connectURI, Properties properties) {
    //
    // First, we'll create a ConnectionFactory that the
    // pool will use to create Connections.
    // We'll use the DriverManagerConnectionFactory,
    // using the connect string passed in the command line
    // arguments.
    //
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, properties);

    //
    // Next we'll create the PoolableConnectionFactory, which wraps
    // the "real" Connections created by the ConnectionFactory with
    // the classes that implement the pooling functionality.
    //
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);

    //
    // Now we'll need a ObjectPool that serves as the
    // actual pool of connections.
    //
    // We'll use a GenericObjectPool instance, although
    // any ObjectPool implementation will suffice.
    //
    ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory);

    // Set the factory's pool property to the owning pool
    poolableConnectionFactory.setPool(connectionPool);

    //
    // Finally, we create the PoolingDriver itself,
    // passing in the object pool we created.
    //
    PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(connectionPool);

    return dataSource;
}
 
开发者ID:odelarosa,项目名称:ZkPortal,代码行数:38,代码来源:DB.java


注:本文中的org.apache.commons.dbcp2.PoolableConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。