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


Java PoolableConnectionFactory類代碼示例

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


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

示例1: DBManager

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
public DBManager() {
 ResourceBundle rb = PropertyResourceBundle.getBundle(
    "com.gint.app.bisisadmin.Config");
 String driver     = rb.getString("driver");
 String URL        = rb.getString("url");
 String username   = rb.getString("username");
 String password   = rb.getString("password");
	
 try {
   Class.forName(driver);
   GenericObjectPool connectionPool = new GenericObjectPool(null);
   DriverManagerConnectionFactory connectionFactory = 
     new DriverManagerConnectionFactory(URL, username, password);
   PoolableConnectionFactory poolableConnectionFactory =
     new PoolableConnectionFactory(connectionFactory, connectionPool, null, 
         null, false, false);
   poolingDataSource = new PoolingDataSource(connectionPool);
 } catch (Exception ex) {
   ex.printStackTrace();
 }  
}
 
開發者ID:unsftn,項目名稱:bisis-v4,代碼行數:22,代碼來源:DBManager.java

示例2: main

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
  Class.forName("com.mysql.jdbc.Driver");
  GenericObjectPool connectionPool = new GenericObjectPool(null);
  DriverManagerConnectionFactory connectionFactory = 
    new DriverManagerConnectionFactory("jdbc:mysql://localhost/bisis35?characterEncoding=UTF-8", 
        "bisis35", "bisis35");
  PoolableConnectionFactory poolableConnectionFactory =
    new PoolableConnectionFactory(connectionFactory, connectionPool, null, 
        null, false, true);
  PoolingDataSource poolingDataSource = new PoolingDataSource(connectionPool);
  
  RecordManagerImpl recMgr = new RecordManagerImpl();
  recMgr.setDataSource(poolingDataSource);
  
  Record rec1 = recMgr.getRecord(1);
  
  System.out.println(rec1);
}
 
開發者ID:unsftn,項目名稱:bisis-v4,代碼行數:19,代碼來源:RetrieverTest.java

示例3: ConnectionPooling

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
/**
 * Constructor 
 *
 * Params:
 *
 *
 */
public ConnectionPooling(String connectionURL, String userName, String password, String driverName) throws ClassNotFoundException, SQLException{
	Class.forName(driverName);
	
	Properties props = new Properties();
	props.setProperty("user", userName);
	props.setProperty("password", password);
	
	ObjectPool connectionPool = new GenericObjectPool(null);
	
	ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectionURL, props);
	
	PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, 
			connectionPool, null, null, false, true);
	
	
	Class.forName("org.apache.commons.dbcp.PoolingDriver");
       PoolingDriver driver = (PoolingDriver) DriverManager.getDriver(myPoolingDriverName);
       driver.registerPool(myPoolName,connectionPool);
}
 
開發者ID:claresco,項目名稱:Tinman,代碼行數:27,代碼來源:ConnectionPooling.java

示例4: createManagedDataSource

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
private DataSource createManagedDataSource(DataSource ds) {

        // wrap it with a LocalXAConnectionFactory
        XAConnectionFactory xaConnectionFactory = new LocalXAConnectionFactory(
                transactionManager, new DataSourceConnectionFactory(ds));

        GenericObjectPool pool = new GenericObjectPool();

        // create the pool object factory
        PoolableConnectionFactory factory = new PoolableConnectionFactory(
                xaConnectionFactory, pool, null, "SELECT DUMMY FROM DUAL",
                false, false);
        pool.setFactory(factory);

        ManagedDataSource managedDs = new ManagedDataSource(pool,
                xaConnectionFactory.getTransactionRegistry());
        managedDs.setAccessToUnderlyingConnectionAllowed(true);
        return managedDs;
    }
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:20,代碼來源:TestPersistence.java

示例5: init

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
public void init(ApplicationContext context) {
    DriverManagerResource driverManagerResource = (DriverManagerResource) getBindResource();
    String userName = driverManagerResource.getUsername();
    String password = driverManagerResource.getPassword();
    String url = driverManagerResource.getUrl();
    String driverClassName = driverManagerResource.getDriverClassName();

    DataSource springDS =
        new org.springframework.jdbc.datasource.DriverManagerDataSource(url, userName, password);
    ((org.springframework.jdbc.datasource.DriverManagerDataSource) springDS)
        .setDriverClassName(driverClassName);

    GenericObjectPool pool = new GenericObjectPool();
    pool.setMinEvictableIdleTimeMillis(300000);
    pool.setTimeBetweenEvictionRunsMillis(60000);
    PoolableConnectionFactory connectionFactory =
        new PoolableConnectionFactory(new DataSourceConnectionFactory(springDS), pool, null, null, false,
                true);

    PoolingDataSource poolingDataSource = new PoolingDataSource(pool);
    poolingDataSource.setAccessToUnderlyingConnectionAllowed(true);
    setDataSource(poolingDataSource);

    postInit(context);
}
 
開發者ID:qafedev,項目名稱:qafe-platform,代碼行數:26,代碼來源:DriverManagerDataSource.java

示例6: buildDataSource

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
public synchronized DataSource buildDataSource(DataSourceConfiguration cfg) {
	init();
	Pair<GenericObjectPool, DataSource> poolInfo = pools.get(cfg.getId());
	if (poolInfo != null) {
		return poolInfo.getSecond();
	}

	GenericObjectPool connectionPool = applicationContext.getBean(GenericObjectPool.class);
	DataSource simpleDataSource = buildSimpleDataSource(cfg);

	ConnectionFactory connectionFactory = new DataSourceConnectionFactory(simpleDataSource);

	// ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(cfg.getUrl().replace(
	// NETXILIA_HOME_VAR, path), cfg.getUsername(), cfg.getPassword());

	new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
	PoolingDataSource poolingDataSource = new PoolingDataSource(connectionPool);

	log.info("Creating a new datasource " + poolingDataSource + " for config:" + cfg.getId());
	pools.put(cfg.getId(), new Pair<GenericObjectPool, DataSource>(connectionPool, poolingDataSource));

	return poolingDataSource;
}
 
開發者ID:netxilia,項目名稱:netxilia,代碼行數:24,代碼來源:DataSourceConfigurationServiceImpl.java

示例7: buildDataSource

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
public static DataSource buildDataSource(String user, String pass,
        String driver, String url) {

    DataSource ds;

    try {
        Class.forName(driver);
    } catch (ClassNotFoundException ignore) {
    }

    GenericObjectPool connectionPool = new GenericObjectPool(null);
  ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
                      url, user, pass);
          PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
                      connectionFactory, connectionPool, null, null, false, true);

  return new PoolingDataSource(connectionPool);
}
 
開發者ID:apache,項目名稱:oodt,代碼行數:19,代碼來源:DatabaseConnectionBuilder.java

示例8: getDataSource

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
private DataSource getDataSource(LinkDataSource lds){
	try{
		String driver, url, user, passwd;
		String[] access = lds.getAccess().split(",");
		driver = access[0];
		url = access[1];
		user = access[2];
		passwd = access[3];
		
		Class.forName(driver);
		
		ObjectPool connectionPool = new GenericObjectPool(null);
        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, user, passwd);
        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
        PoolingDataSource data_source = new PoolingDataSource(connectionPool);
        
        return data_source;
	}
	catch(Exception e){
		
	}
	
	return null;
}
 
開發者ID:openmrs,項目名稱:openmrs-module-patientmatching,代碼行數:25,代碼來源:ReaderProvider.java

示例9: setup

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
public void setup( Properties prop ) {
	this.prop=prop;

       GenericObjectPool.Config conPoolCfg = new GenericObjectPool.Config();
       conPoolCfg.maxActive = Integer.parseInt( prop.getProperty( "connectionPoolMaxSize", "15" ) );
       conPoolCfg.maxIdle = Integer.parseInt( prop.getProperty( "connectionPoolMaxIdle", "8" ) );
       conPoolCfg.maxWait = Integer.parseInt( prop.getProperty( "connectionPoolMaxWait", "60000" ) );
       conPoolCfg.minIdle = Integer.parseInt( prop.getProperty( "connectionPoolMinSize", "2" ) );


       ObjectPool connectionPool = new GenericObjectPool( null, conPoolCfg );
       try {
		Class.forName( prop.getProperty( "jdbcDriver" ) );
	} catch( ClassNotFoundException e ) {
		e.printStackTrace();
		throw new RuntimeException();
	}

       ConnectionFactory connectionFactory = new
           DriverManagerConnectionFactory( prop.getProperty( "jdbcUrl" ),
                                          prop.getProperty( "jdbcUser" ), 
                                          prop.getProperty( "jdbcPassword" ) );


       new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);

       PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
       
       ds = dataSource;
}
 
開發者ID:yswang0927,項目名稱:ralasafe,代碼行數:31,代碼來源:DataSourceProviderDbcpImpl.java

示例10: validateConnectionFactory

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
private static void validateConnectionFactory(PoolableConnectionFactory connectionFactory) throws Exception {
    Connection conn = null;
    try {
        conn = (Connection) connectionFactory.makeObject();
        connectionFactory.activateObject(conn);
        connectionFactory.validateConnection(conn);
        connectionFactory.passivateObject(conn);
    }
    finally {
        connectionFactory.destroyObject(conn);
    }
}
 
開發者ID:Gigaspaces,項目名稱:xap-openspaces,代碼行數:13,代碼來源:DbcpBasicDataSource.java

示例11: ReportDatasource

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
/**
 * Construct with configuration.
 *
 * @param configuration - app configuration
 */
public ReportDatasource (final Configuration configuration) {
    Optional<String> optConnectionURI = configuration.getJDBCConnectionString();
    if (!optConnectionURI.isPresent()) {
        dataSource = Optional.empty();
        return;
    }
    String connectionURI = optConnectionURI.get();
    ConnectionFactory cf = new DriverManagerConnectionFactory(connectionURI, null);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(cf, new GenericObjectPool(),
                    null, null, true, false);
    GenericObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory);
    dataSource = Optional.of(new PoolingDataSource(connectionPool));
}
 
開發者ID:jonmbake,項目名稱:reports-micro-service,代碼行數:19,代碼來源:ReportDatasource.java

示例12: initializeDataSource

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
/**
    * @param config
    * @throws SQLException
    */
private void initializeDataSource(Config config) {
       String user = config.getString(CONFIG_KEY_DB_USER);
       String password = config.getString(CONFIG_KEY_DB_PASSWORD);

       Properties params = new Properties();

       if (isNotEmpty(user) && isNotEmpty(password)) {
           params.put("user", user);
           params.put("password", password);
       }

       // ドライバのロード
       String driver = config.getString(CONFIG_KEY_DB_DRIVER);
       boolean loadSuccess = DbUtils.loadDriver(driver);
       if (!loadSuccess) {
           String message = "failed to load driver.";
           throw new RuntimeException(message);
       }

       // コネクションをプールするDataSource を作成する
       @SuppressWarnings("rawtypes")
	GenericObjectPool pool = new GenericObjectPool();
       // コネクションプールの設定を行う
       int  maxActive = config.getInt(CONFIG_KEY_DB_MAX_ACTIVE_CONN, 100);
       long maxWait   = Long.parseLong(config.getString(CONFIG_KEY_DB_WAIT, "-1"));
       pool.setMaxActive(maxActive);
       pool.setMaxIdle(maxActive);
       pool.setMaxWait(maxWait);

       driverUrl = config.getString(CONFIG_KEY_DB_URL);
       ConnectionFactory connFactory = new DriverManagerConnectionFactory(driverUrl, params);
       new PoolableConnectionFactory(connFactory, pool, null,
               null, // validationQuery
               false, // defaultReadOnly
               false); // defaultAutoCommit
       dataSource = new PoolingDataSource(pool);
   }
 
開發者ID:okinawaopenlabs,項目名稱:of-patch-manager,代碼行數:42,代碼來源:ConnectionManagerJdbc.java

示例13: setUp

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
/**
 *
 * @return @throws Exception
 */
public DataSource setUp() throws Exception {
    /**
     * Load JDBC Driver class.
     */
    Class.forName(ConnectionPool.DRIVER).newInstance();

    /**
     * Creates an instance of GenericObjectPool that holds our pool of
     * connections object.
     */
    connectionPool = new GenericObjectPool();
    // set the max number of connections
    connectionPool.setMaxActive(connections);
    // if the pool is exhausted (i.e., the maximum number of active objects has been reached), the borrowObject() method should simply create a new object anyway
    connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);

    /**
     * Creates a connection factory object which will be used by the pool to
     * create the connection object. We pass the JDBC url info, username
     * and password.
     */
    ConnectionFactory cf = new DriverManagerConnectionFactory(
            ConnectionPool.URL,
            ConnectionPool.USERNAME,
            ConnectionPool.PASSWORD);

    /**
     * Creates a PoolableConnectionFactory that will wrap the connection
     * object created by the ConnectionFactory to add object pooling
     * functionality.
     */
    PoolableConnectionFactory pcf
            = new PoolableConnectionFactory(cf, connectionPool,
                    null, null, false, true);
    return new PoolingDataSource(connectionPool);
}
 
開發者ID:disit,項目名稱:sce-backend,代碼行數:41,代碼來源:ConnectionPool.java

示例14: initConnection

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
public final static void initConnection(String address, String user, String password) throws ClassNotFoundException {
	Class.forName("com.mysql.jdbc.Driver");
	GenericObjectPool connectionPool = new GenericObjectPool(null);
	ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(address, user, password);
	KeyedObjectPoolFactory keyed_factory = new StackKeyedObjectPoolFactory();
	new PoolableConnectionFactory(connectionFactory, connectionPool, keyed_factory, null, false, true);
	ds = new PoolingDataSource(connectionPool);
}
 
開發者ID:sunenielsen,項目名稱:tribaltrouble,代碼行數:9,代碼來源:DBUtils.java

示例15: setUp

import org.apache.commons.dbcp.PoolableConnectionFactory; //導入依賴的package包/類
public DataSource setUp() throws Exception {
	Class.forName(DBPool.DRIVER).newInstance(); //Load driver
	//Create pool
	connectionPool = new GenericObjectPool();
       connectionPool.setMaxActive(DBPool.POOL_SIZE);
       //Create factor
       ConnectionFactory cf = new DriverManagerConnectionFactory(DBPool.URL,DBPool.USER,DBPool.PASSWORD);
       //Create PoolableConnectionFactory
       PoolableConnectionFactory pcf =
               new PoolableConnectionFactory(cf, connectionPool,
                       null, null, false, true);
       return new PoolingDataSource(connectionPool);
}
 
開發者ID:curi0us,項目名稱:mgops,代碼行數:14,代碼來源:DBPool.java


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