本文整理汇总了Java中org.apache.tomcat.dbcp.dbcp.BasicDataSource类的典型用法代码示例。如果您正苦于以下问题:Java BasicDataSource类的具体用法?Java BasicDataSource怎么用?Java BasicDataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicDataSource类属于org.apache.tomcat.dbcp.dbcp包,在下文中一共展示了BasicDataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRewrapDataSource
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
/** Test.
* @throws Exception e */
@Test
public void testRewrapDataSource() throws Exception {
final BasicDataSource tomcatDataSource = new BasicDataSource();
tomcatDataSource.setUrl(H2_DATABASE_URL);
rewrapDataSource(tomcatDataSource);
final org.apache.commons.dbcp.BasicDataSource dbcpDataSource = new org.apache.commons.dbcp.BasicDataSource();
dbcpDataSource.setUrl(H2_DATABASE_URL);
rewrapDataSource(dbcpDataSource);
final org.apache.tomcat.dbcp.dbcp2.BasicDataSource tomcat2DataSource = new org.apache.tomcat.dbcp.dbcp2.BasicDataSource();
tomcat2DataSource.setUrl(H2_DATABASE_URL);
rewrapDataSource(tomcat2DataSource);
final org.apache.commons.dbcp2.BasicDataSource dbcp2DataSource = new org.apache.commons.dbcp2.BasicDataSource();
dbcp2DataSource.setUrl(H2_DATABASE_URL);
rewrapDataSource(dbcp2DataSource);
final DataSource dataSource = createNiceMock(DataSource.class);
rewrapDataSource(dataSource);
}
示例2: getInfo
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
@Override
public DataSourceInfo getInfo(Object resource) throws Exception {
DataSourceInfo dataSourceInfo = null;
if (canMap(resource)) {
BasicDataSource source = (BasicDataSource) resource;
dataSourceInfo = new DataSourceInfo();
dataSourceInfo.setBusyConnections(source.getNumActive());
dataSourceInfo.setEstablishedConnections(source.getNumIdle() + source.getNumActive());
dataSourceInfo.setMaxConnections(source.getMaxActive());
dataSourceInfo.setJdbcUrl(source.getUrl());
dataSourceInfo.setUsername(source.getUsername());
dataSourceInfo.setResettable(false);
dataSourceInfo.setType("tomcat-dbcp");
}
return dataSourceInfo;
}
示例3: pullDataSourceProperties
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
static void pullDataSourceProperties(String name, DataSource dataSource) {
// CHECKSTYLE:ON
final String dataSourceClassName = dataSource.getClass().getName();
if ("org.apache.tomcat.dbcp.dbcp.BasicDataSource".equals(dataSourceClassName)
&& dataSource instanceof BasicDataSource) {
pullTomcatDbcpDataSourceProperties(name, dataSource);
} else if ("org.apache.tomcat.dbcp.dbcp2.BasicDataSource".equals(dataSourceClassName)
&& dataSource instanceof org.apache.tomcat.dbcp.dbcp2.BasicDataSource) {
pullTomcatDbcp2DataSourceProperties(name, dataSource);
} else if ("org.apache.commons.dbcp.BasicDataSource".equals(dataSourceClassName)
&& dataSource instanceof org.apache.commons.dbcp.BasicDataSource) {
pullCommonsDbcpDataSourceProperties(name, dataSource);
} else if ("org.apache.commons.dbcp2.BasicDataSource".equals(dataSourceClassName)
&& dataSource instanceof org.apache.commons.dbcp2.BasicDataSource) {
pullCommonsDbcp2DataSourceProperties(name, dataSource);
} else if ("org.apache.tomcat.jdbc.pool.DataSource".equals(dataSourceClassName)
&& dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource) {
pullTomcatJdbcDataSourceProperties(name, dataSource);
}
}
示例4: getConnection
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
/**
* Get the connection from the database.
* @return
*/
public Connection getConnection() {
Connection con = null;
Context initCtx;
try {
initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
BasicDataSource ds = (BasicDataSource) envCtx.lookup("jdbc/jathenaeum");
con = ds.getConnection();
System.out.println("##db## - 'Pooled Connection' acquisita.");
} catch (NamingException e1) {
e1.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
示例5: destroy
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
public void destroy() throws EngineException {
Enumeration<String> keysEnum = Collections.enumeration(databasePools.keySet());
while(keysEnum.hasMoreElements()) {
String poolKey = (String)keysEnum.nextElement();
Engine.logEngine.debug("[SqlConnectionManager] Closing datasource '" + poolKey + "'...");
try {
((BasicDataSource)databasePools.get(poolKey)).close();
Engine.logEngine.debug("[SqlConnectionManager] Datasource '" + poolKey + "' closed.");
} catch (SQLException e) {
Engine.logEngine.debug("[SqlConnectionManager] Datasource '" + poolKey + "' close failure ! ");
}
databasePools.remove(poolKey);
}
databasePools = null;
}
示例6: removeDatabasePool
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
public void removeDatabasePool(SqlConnector connector) {
String poolKey = getKey(connector);
if (databasePools.containsKey(poolKey)) {
Engine.logEngine.debug("[SqlConnectionManager] Closing datasource '" + poolKey + "'...");
try {
((BasicDataSource)databasePools.get(poolKey)).close();
Engine.logEngine.debug("[SqlConnectionManager] Datasource '" + poolKey + "' closed.");
} catch (SQLException e) {
Engine.logEngine.debug("[SqlConnectionManager] Datasource '" + poolKey + "' close failure ! ");
}
databasePools.remove(poolKey);
}
}
示例7: getDatabasePool
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
private synchronized BasicDataSource getDatabasePool (SqlConnector connector) {
if (databasePools.containsKey(getKey(connector))) {
Engine.logEngine.debug("(JdbcConnectionManager) getDatabasePool() returning existing pool");
return (BasicDataSource) databasePools.get(getKey(connector));
}
else {
Engine.logEngine.debug("(JdbcConnectionManager) getDatabasePool() returning new pool");
return addDatabasePool(connector);
}
}
示例8: pullTomcatDbcpDataSourceProperties
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
private static void pullTomcatDbcpDataSourceProperties(String name, DataSource dataSource) {
// si tomcat et si dataSource standard, alors on récupère des infos
final BasicDataSource tomcatDbcpDataSource = (BasicDataSource) dataSource;
final BasicDataSourcesProperties properties = TOMCAT_BASIC_DATASOURCES_PROPERTIES;
// basicDataSource.getNumActive() est en théorie égale à USED_CONNECTION_COUNT à un instant t,
// numIdle + numActive est le nombre de connexions ouvertes dans la bdd pour ce serveur à un instant t
// les propriétés généralement importantes en premier (se méfier aussi de testOnBorrow)
properties.put(name, MAX_ACTIVE_PROPERTY_NAME, tomcatDbcpDataSource.getMaxActive());
properties.put(name, "poolPreparedStatements",
tomcatDbcpDataSource.isPoolPreparedStatements());
properties.put(name, "defaultCatalog", tomcatDbcpDataSource.getDefaultCatalog());
properties.put(name, "defaultAutoCommit", tomcatDbcpDataSource.getDefaultAutoCommit());
properties.put(name, "defaultReadOnly", tomcatDbcpDataSource.getDefaultReadOnly());
properties.put(name, "defaultTransactionIsolation",
tomcatDbcpDataSource.getDefaultTransactionIsolation());
properties.put(name, "driverClassName", tomcatDbcpDataSource.getDriverClassName());
properties.put(name, "initialSize", tomcatDbcpDataSource.getInitialSize());
properties.put(name, "maxIdle", tomcatDbcpDataSource.getMaxIdle());
properties.put(name, "maxOpenPreparedStatements",
tomcatDbcpDataSource.getMaxOpenPreparedStatements());
properties.put(name, "maxWait", tomcatDbcpDataSource.getMaxWait());
properties.put(name, "minEvictableIdleTimeMillis",
tomcatDbcpDataSource.getMinEvictableIdleTimeMillis());
properties.put(name, "minIdle", tomcatDbcpDataSource.getMinIdle());
properties.put(name, "numTestsPerEvictionRun",
tomcatDbcpDataSource.getNumTestsPerEvictionRun());
properties.put(name, "testOnBorrow", tomcatDbcpDataSource.getTestOnBorrow());
properties.put(name, "testOnReturn", tomcatDbcpDataSource.getTestOnReturn());
properties.put(name, "testWhileIdle", tomcatDbcpDataSource.getTestWhileIdle());
properties.put(name, "timeBetweenEvictionRunsMillis",
tomcatDbcpDataSource.getTimeBetweenEvictionRunsMillis());
properties.put(name, "validationQuery", tomcatDbcpDataSource.getValidationQuery());
}
示例9: pullCommonsDbcpDataSourceProperties
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
private static void pullCommonsDbcpDataSourceProperties(String name, DataSource dataSource) {
// si dbcp et si dataSource standard, alors on récupère des infos
final org.apache.commons.dbcp.BasicDataSource dbcpDataSource = (org.apache.commons.dbcp.BasicDataSource) dataSource;
final BasicDataSourcesProperties properties = DBCP_BASIC_DATASOURCES_PROPERTIES;
// basicDataSource.getNumActive() est en théorie égale à USED_CONNECTION_COUNT à un instant t,
// numIdle + numActive est le nombre de connexions ouvertes dans la bdd pour ce serveur à un instant t
// les propriétés généralement importantes en premier (se méfier aussi de testOnBorrow)
properties.put(name, MAX_ACTIVE_PROPERTY_NAME, dbcpDataSource.getMaxActive());
properties.put(name, "poolPreparedStatements", dbcpDataSource.isPoolPreparedStatements());
properties.put(name, "defaultCatalog", dbcpDataSource.getDefaultCatalog());
properties.put(name, "defaultAutoCommit", dbcpDataSource.getDefaultAutoCommit());
properties.put(name, "defaultReadOnly", dbcpDataSource.getDefaultReadOnly());
properties.put(name, "defaultTransactionIsolation",
dbcpDataSource.getDefaultTransactionIsolation());
properties.put(name, "driverClassName", dbcpDataSource.getDriverClassName());
properties.put(name, "initialSize", dbcpDataSource.getInitialSize());
properties.put(name, "maxIdle", dbcpDataSource.getMaxIdle());
properties.put(name, "maxOpenPreparedStatements",
dbcpDataSource.getMaxOpenPreparedStatements());
properties.put(name, "maxWait", dbcpDataSource.getMaxWait());
properties.put(name, "minEvictableIdleTimeMillis",
dbcpDataSource.getMinEvictableIdleTimeMillis());
properties.put(name, "minIdle", dbcpDataSource.getMinIdle());
properties.put(name, "numTestsPerEvictionRun", dbcpDataSource.getNumTestsPerEvictionRun());
properties.put(name, "testOnBorrow", dbcpDataSource.getTestOnBorrow());
properties.put(name, "testOnReturn", dbcpDataSource.getTestOnReturn());
properties.put(name, "testWhileIdle", dbcpDataSource.getTestWhileIdle());
properties.put(name, "timeBetweenEvictionRunsMillis",
dbcpDataSource.getTimeBetweenEvictionRunsMillis());
properties.put(name, "validationQuery", dbcpDataSource.getValidationQuery());
}
示例10: pullTomcatDbcp2DataSourceProperties
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
private static void pullTomcatDbcp2DataSourceProperties(String name, DataSource dataSource) {
// si tomcat et si dataSource standard, alors on récupère des infos
final org.apache.tomcat.dbcp.dbcp2.BasicDataSource tomcatDbcp2DataSource = (org.apache.tomcat.dbcp.dbcp2.BasicDataSource) dataSource;
final BasicDataSourcesProperties properties = TOMCAT_BASIC_DATASOURCES_PROPERTIES;
// basicDataSource.getNumActive() est en théorie égale à USED_CONNECTION_COUNT à un instant t,
// numIdle + numActive est le nombre de connexions ouvertes dans la bdd pour ce serveur à un instant t
// les propriétés généralement importantes en premier (se méfier aussi de testOnBorrow)
properties.put(name, MAX_ACTIVE_PROPERTY_NAME, tomcatDbcp2DataSource.getMaxTotal());
properties.put(name, "poolPreparedStatements",
tomcatDbcp2DataSource.isPoolPreparedStatements());
properties.put(name, "defaultCatalog", tomcatDbcp2DataSource.getDefaultCatalog());
properties.put(name, "defaultAutoCommit", tomcatDbcp2DataSource.getDefaultAutoCommit());
properties.put(name, "defaultReadOnly", tomcatDbcp2DataSource.getDefaultReadOnly());
properties.put(name, "defaultTransactionIsolation",
tomcatDbcp2DataSource.getDefaultTransactionIsolation());
properties.put(name, "driverClassName", tomcatDbcp2DataSource.getDriverClassName());
properties.put(name, "initialSize", tomcatDbcp2DataSource.getInitialSize());
properties.put(name, "maxIdle", tomcatDbcp2DataSource.getMaxIdle());
properties.put(name, "maxOpenPreparedStatements",
tomcatDbcp2DataSource.getMaxOpenPreparedStatements());
properties.put(name, "maxWait", tomcatDbcp2DataSource.getMaxWaitMillis());
properties.put(name, "minEvictableIdleTimeMillis",
tomcatDbcp2DataSource.getMinEvictableIdleTimeMillis());
properties.put(name, "minIdle", tomcatDbcp2DataSource.getMinIdle());
properties.put(name, "numTestsPerEvictionRun",
tomcatDbcp2DataSource.getNumTestsPerEvictionRun());
properties.put(name, "testOnBorrow", tomcatDbcp2DataSource.getTestOnBorrow());
properties.put(name, "testOnReturn", tomcatDbcp2DataSource.getTestOnReturn());
properties.put(name, "testWhileIdle", tomcatDbcp2DataSource.getTestWhileIdle());
properties.put(name, "timeBetweenEvictionRunsMillis",
tomcatDbcp2DataSource.getTimeBetweenEvictionRunsMillis());
properties.put(name, "validationQuery", tomcatDbcp2DataSource.getValidationQuery());
}
示例11: pullCommonsDbcp2DataSourceProperties
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
private static void pullCommonsDbcp2DataSourceProperties(String name, DataSource dataSource) {
// si dbcp et si dataSource standard, alors on récupère des infos
final org.apache.commons.dbcp2.BasicDataSource dbcp2DataSource = (org.apache.commons.dbcp2.BasicDataSource) dataSource;
final BasicDataSourcesProperties properties = DBCP_BASIC_DATASOURCES_PROPERTIES;
// basicDataSource.getNumActive() est en théorie égale à USED_CONNECTION_COUNT à un instant t,
// numIdle + numActive est le nombre de connexions ouvertes dans la bdd pour ce serveur à un instant t
// les propriétés généralement importantes en premier (se méfier aussi de testOnBorrow)
properties.put(name, MAX_ACTIVE_PROPERTY_NAME, dbcp2DataSource.getMaxTotal());
properties.put(name, "poolPreparedStatements", dbcp2DataSource.isPoolPreparedStatements());
properties.put(name, "defaultCatalog", dbcp2DataSource.getDefaultCatalog());
properties.put(name, "defaultAutoCommit", dbcp2DataSource.getDefaultAutoCommit());
properties.put(name, "defaultReadOnly", dbcp2DataSource.getDefaultReadOnly());
properties.put(name, "defaultTransactionIsolation",
dbcp2DataSource.getDefaultTransactionIsolation());
properties.put(name, "driverClassName", dbcp2DataSource.getDriverClassName());
properties.put(name, "initialSize", dbcp2DataSource.getInitialSize());
properties.put(name, "maxIdle", dbcp2DataSource.getMaxIdle());
properties.put(name, "maxOpenPreparedStatements",
dbcp2DataSource.getMaxOpenPreparedStatements());
properties.put(name, "maxWait", dbcp2DataSource.getMaxWaitMillis());
properties.put(name, "minEvictableIdleTimeMillis",
dbcp2DataSource.getMinEvictableIdleTimeMillis());
properties.put(name, "minIdle", dbcp2DataSource.getMinIdle());
properties.put(name, "numTestsPerEvictionRun", dbcp2DataSource.getNumTestsPerEvictionRun());
properties.put(name, "testOnBorrow", dbcp2DataSource.getTestOnBorrow());
properties.put(name, "testOnReturn", dbcp2DataSource.getTestOnReturn());
properties.put(name, "testWhileIdle", dbcp2DataSource.getTestWhileIdle());
properties.put(name, "timeBetweenEvictionRunsMillis",
dbcp2DataSource.getTimeBetweenEvictionRunsMillis());
properties.put(name, "validationQuery", dbcp2DataSource.getValidationQuery());
}
示例12: create
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
@Override
public Object create(DataNodeConfig config) {
if (config.getId() == null) {
return null;
}
BasicDataSource dataSource = new BasicDataSource();
dataSource.setMinEvictableIdleTimeMillis(1000 * 60 * 10);
dataSource.setNumTestsPerEvictionRun(5);
dataSource.setRemoveAbandoned(true);
dataSource.setRemoveAbandonedTimeout(10);
dataSource.setTimeBetweenEvictionRunsMillis(1000 * 60 * 5);
dataSource.setTestOnBorrow(false);
dataSource.setTestOnReturn(false);
dataSource.setTestWhileIdle(true);
dataSource.setValidationQuery("SELECT 1");
Map<String, String> properties=getProperties(config);
if(logger.isDebugEnabled()){
logger.debug("datanode id=["+config.getId()+"] properties="+properties);
}
for (Map.Entry<String, String> entry :properties .entrySet()) {
try {
BeanUtils.setProperty(dataSource,
entry.getKey(), entry.getValue());
} catch (Exception e) {
logger.error("create DataSource error!", e);
}
}
return dataSource;
}
示例13: DataSourceWrapper
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
public DataSourceWrapper(Properties properties){
BasicDataSource dbcpDataSource = new BasicDataSource();
for (Map.Entry<Object, Object> entry : properties .entrySet()) {
try {
BeanUtils.setProperty(dbcpDataSource,
entry.getKey().toString(), entry.getValue().toString());
} catch (Exception e) {
e.printStackTrace();
}
}
this.datasource = dbcpDataSource;
}
示例14: restDataSource
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
@Bean
public DataSource restDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName"));
dataSource.setUrl(env.getProperty("jdbc.url"));
dataSource.setUsername(env.getProperty("jdbc.user"));
dataSource.setPassword(env.getProperty("jdbc.pass"));
return dataSource;
}
示例15: getInfo
import org.apache.tomcat.dbcp.dbcp.BasicDataSource; //导入依赖的package包/类
public DataSourceInfo getInfo(Object resource) throws Exception {
DataSourceInfo dataSourceInfo = null;
if (canMap(resource)) {
BasicDataSource source = (BasicDataSource) resource;
dataSourceInfo = new DataSourceInfo();
dataSourceInfo.setBusyConnections(source.getNumActive());
dataSourceInfo.setEstablishedConnections(source.getNumIdle() + source.getNumActive());
dataSourceInfo.setMaxConnections(source.getMaxActive());
dataSourceInfo.setJdbcURL(source.getUrl());
dataSourceInfo.setUsername(source.getUsername());
dataSourceInfo.setResettable(false);
}
return dataSourceInfo;
}