本文整理匯總了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();
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}