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


Java ConnectionFactory类代码示例

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


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

示例1: ConnectionPooling

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的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

示例2: buildDataSource

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的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

示例3: buildDataSource

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的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

示例4: getDataSource

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的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

示例5: setup

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的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

示例6: StatementClosingPoolableConnectionFactory

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的package包/类
/**
 * Default superclass constructor.
 *
 * @throws Exception When there is an error in the PoolableConnectionFactory constructor.
 */
public StatementClosingPoolableConnectionFactory(ConnectionFactory factory,
												 ObjectPool pool,
												 KeyedObjectPoolFactory stmtPoolFactory,
												 String validationQuery,
												 boolean defaultReadOnly,
												 boolean defaultAutoCommit)
	throws Exception {

	super(factory, pool, stmtPoolFactory, validationQuery,
		  defaultReadOnly, defaultAutoCommit);
}
 
开发者ID:SQLPower,项目名称:sqlpower-library,代码行数:17,代码来源:StatementClosingPoolableConnectionFactory.java

示例7: ReportDatasource

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的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

示例8: initializeDataSource

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的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

示例9: setUp

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的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

示例10: initConnection

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的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

示例11: setUp

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的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

示例12: getDefaultDataSource

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
private static DataSource getDefaultDataSource(final String database) {
    final GenericObjectPool connectionPool = new GenericObjectPool(null, 5);
    final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/" + database, "cloud", "cloud");
    final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
    return new PoolingDataSource(
            /* connectionPool */poolableConnectionFactory.getPool());
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:9,代码来源:TransactionLegacy.java

示例13: DataSourceWorkflowRepositoryFactory

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的package包/类
/**
 * <p>
 * Default Constructor
 * </p>.
 */
public DataSourceWorkflowRepositoryFactory() throws WorkflowException {
    String jdbcUrl, user, pass, driver;

    jdbcUrl = System
            .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.url");
    user = System
            .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.user");
    pass = System
            .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.pass");
    driver = System
            .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.driver");

    try {
        Class.forName(driver);
    } catch (ClassNotFoundException e) {
        throw new WorkflowException("Cannot load driver: " + driver);
    }

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

    dataSource = new PoolingDataSource(connectionPool);
}
 
开发者ID:apache,项目名称:oodt,代码行数:32,代码来源:DataSourceWorkflowRepositoryFactory.java

示例14: LocalXAConnectionFactory

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的package包/类
/**
 * Creates an LocalXAConnectionFactory which uses the specified connection factory to create database
 * connections.  The connections are enlisted into transactions using the specified transaction manager.
 *
 * @param transactionManager the transaction manager in which connections will be enlisted
 * @param connectionFactory  the connection factory from which connections will be retrieved
 */
public LocalXAConnectionFactory(TransactionManager transactionManager, ConnectionFactory connectionFactory) {
    if (transactionManager == null) throw new NullPointerException("transactionManager is null");
    if (connectionFactory == null) throw new NullPointerException("connectionFactory is null");

    this.transactionRegistry = new TransactionRegistry(transactionManager);
    this.connectionFactory = connectionFactory;
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:15,代码来源:LocalXAConnectionFactory.java

示例15: setUp

import org.apache.commons.dbcp.ConnectionFactory; //导入依赖的package包/类
public void setUp() throws Exception {
    super.setUp();

    // create a GeronimoTransactionManager for testing
    transactionManager = new TransactionManagerImpl();

    // create a driver connection factory
    Properties properties = new Properties();
    properties.setProperty("user", "username");
    properties.setProperty("password", "password");
    ConnectionFactory connectionFactory = new DriverConnectionFactory(new TesterDriver(), "jdbc:apache:commons:testdriver", properties);

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

    // create the pool
    pool = new GenericObjectPool();
    pool.setMaxActive(getMaxActive());
    pool.setMaxWait(getMaxWait());

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

    // finally create the datasource
    ds = new ManagedDataSource(pool, xaConnectionFactory.getTransactionRegistry());
    ds.setAccessToUnderlyingConnectionAllowed(true);
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:29,代码来源:TestManagedDataSource.java


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