List of usage examples for org.apache.commons.dbcp BasicDataSource BasicDataSource
BasicDataSource
From source file:com.consol.citrus.demo.voting.dao.JdbcApplicationConfig.java
@Bean @ConditionalOnProperty(prefix = "voting.persistence", value = "type", havingValue = "jdbc") @DependsOn("database") public DataSource dataSource(JdbcConfigurationProperties configurationProperties) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(configurationProperties.getDriverClassName()); dataSource.setUrl(configurationProperties.getUrl()); dataSource.setUsername(configurationProperties.getUsername()); dataSource.setPassword(configurationProperties.getPassword()); return dataSource; }
From source file:com.kennberg.appenginecpeg.SQLManager.java
public Connection getConnection() throws SQLException { if (!useConnectionPool) { if (username == null) { return DriverManager.getConnection(address); } else {/*w ww .ja v a 2 s. c om*/ return DriverManager.getConnection(address, username, password); } } synchronized (dataSourceLock) { if (dataSource == null) { dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverClassName); dataSource.setUrl(address); if (username != null) { dataSource.setUsername(username); dataSource.setPassword(password); } dataSource.setInitialSize(MIN_CONNECTION_POOL_SIZE); dataSource.setMaxActive(MAX_CONNECTION_POOL_SIZE); dataSource.setMaxIdle(MAX_CONNECTION_POOL_SIZE); dataSource.setMaxWait(MAX_CONNECTION_WAIT_MS); dataSource.setTestOnBorrow(true); dataSource.setValidationQuery("SELECT 1"); // From BasicDataSourceFactory.java, DBCP-215 // Trick to make sure that initialSize connections are created if (dataSource.getInitialSize() > 0) { dataSource.getLogWriter(); } } return dataSource.getConnection(); } // synchronized dataSourceLock }
From source file:it.emacro.extractor.db.ConnectionPool.java
private void setupDataSource() throws SQLException { // String path = "WebContent/WEB-INF/config/database.properties"; String path = it.emacro.services.ApplicationData.getInstance().getWebroot() + "WEB-INF/config/database.properties"; // String path = // "D:\\workspace\\lotto\\WebContent\\WEB-INF\\config\\database.properties"; // properties = PropertyLoader.getPropertiesOrEmpty(path); // path = "D:\\workspace\\lotto\\WebContent\\WEB-INF\\config\\database.properties"; properties = PropertyLoader.getPropertiesOrEmpty(path); String driver = properties.getProperty(DRIVER); String url = properties.getProperty(URL); String username = properties.getProperty(USERNAME); String password = properties.getProperty(PASSWORD); // log.debug("Database username: " + username); // log.debug("Database password: " + password); // log.debug("Database driver: " + driver); // log.debug("Database url: " + url); try {/*from w ww . jav a2 s .com*/ Class.forName(driver); } catch (ClassNotFoundException e) { throw new SQLException("Can not load driver"); } dataSource = new BasicDataSource(); dataSource.setDriverClassName(driver); dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setUrl(url); }
From source file:de.dominikschadow.javasecurity.spring.SecurityConfig.java
@Bean public DataSource dataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl("jdbc:hsqldb:mem:hashing"); dataSource.setUsername("hashing"); dataSource.setPassword("hashing"); return dataSource; }
From source file:com.manpowergroup.cn.icloud.util.Case0.java
public void test_1() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);//from w w w .j av a 2 s. co m dataSource.setMinIdle(minIdle); dataSource.setMaxIdle(maxIdle); dataSource.setPoolPreparedStatements(true); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setPoolPreparedStatements(true); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery(validationQuery); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); for (int i = 0; i < LOOP_COUNT; ++i) { p0(dataSource, "dbcp"); } System.out.println(); }
From source file:com.google.gerrit.server.schema.H2AccountPatchReviewStore.java
private static DataSource createDataSource(String url) { BasicDataSource datasource = new BasicDataSource(); datasource.setDriverClassName("org.h2.Driver"); datasource.setUrl(url);/*from w w w .ja v a 2 s . c o m*/ datasource.setMaxActive(50); datasource.setMinIdle(4); datasource.setMaxIdle(16); long evictIdleTimeMs = 1000 * 60; datasource.setMinEvictableIdleTimeMillis(evictIdleTimeMs); datasource.setTimeBetweenEvictionRunsMillis(evictIdleTimeMs / 2); return datasource; }
From source file:genepi.db.h2.H2Connector.java
public void connect() throws SQLException { File file = new File(path + ".h2.db"); File file2 = new File(path + ".mv.db"); exists = file.exists() || file2.exists(); log.debug("Establishing connection to " + user + "@" + path); if (DbUtils.loadDriver("org.h2.Driver")) { try {//from w w w . j a va2s . c o m dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.h2.Driver"); String newPath = path; if (!path.startsWith("/")) { newPath = "./" + path; } else { newPath = path; } if (multiuser) { dataSource.setUrl("jdbc:h2:" + newPath + ";AUTO_SERVER=TRUE"); } else { dataSource.setUrl("jdbc:h2:" + newPath); } dataSource.setUsername(user); dataSource.setPassword(password); // dataSource.setMaxActive(1000); // dataSource.setMaxWait(10000); dataSource.setMaxIdle(10000); dataSource.setDefaultAutoCommit(true); } catch (Exception e) { e.printStackTrace(); } } else { log.error("H2 Driver Class not found"); } }
From source file:com.dangdang.ddframe.rdb.sharding.config.common.api.ShardingRuleBuilderTest.java
@Test(expected = IllegalArgumentException.class) public void testClassNotFound() { Yaml yaml = new Yaml(new Constructor(ShardingRuleConfig.class)); Map<String, DataSource> dsMap = new HashMap<>(); dsMap.put("ds", new BasicDataSource()); ShardingRuleConfig config = (ShardingRuleConfig) yaml .load(ShardingRuleBuilderTest.class.getResourceAsStream("/config/config-classNotFound.yaml")); new ShardingRuleBuilder("config-classNotFound.yaml", dsMap, config).build(); }
From source file:com.alibaba.druid.benckmark.pool.Case_Concurrent_50.java
public void test_1() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);// w w w . ja va 2 s .c o m dataSource.setMinIdle(minIdle); dataSource.setMaxIdle(maxIdle); dataSource.setPoolPreparedStatements(true); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setPoolPreparedStatements(true); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery(validationQuery); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); for (int i = 0; i < LOOP_COUNT; ++i) { p0(dataSource, "dbcp"); } System.out.println(); }
From source file:com.dynamobi.ws.util.ConnectionManager.java
/** * Constructor sets up the dataSource manager for the connections which * validate other connections and starts the garbage collector for * user connections./*from w w w. j av a 2 s . c o m*/ */ public ConnectionManager() throws ClassNotFoundException, SQLException, IOException { super(); Properties pro = new Properties(); InputStream user_props = this.getClass().getResourceAsStream("/luciddb-jdbc.properties"); if (user_props != null) { pro.load(user_props); } else { pro.load(this.getClass().getResourceAsStream("/luciddb-jdbc-default.properties")); } jdbc_driver = pro.getProperty("jdbc.driver"); Class.forName(jdbc_driver); String username = pro.getProperty("jdbc.username"); String password = pro.getProperty("jdbc.password"); jdbc_url = pro.getProperty("jdbc.url"); // this sets up the connection to validate other connections. data_source = new BasicDataSource(); data_source.setDriverClassName(jdbc_driver); data_source.setUrl(jdbc_url); data_source.setUsername(username); data_source.setPassword(password); setDataSource(data_source); conns = new HashMap<String, ConnectionInfo>(); GC = new ConnectionGC(60 * 5, 60 * 60); // check to close stuff every 5 mins, invalidation time is 1 hr }