List of usage examples for org.apache.commons.dbcp BasicDataSource setUrl
public synchronized void setUrl(String url)
Sets the #url .
Note: this method currently has no effect once the pool has been initialized.
From source file:com.alibaba.druid.benckmark.pool.Case3.java
public void dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);/*from ww w . j a v a2 s . c om*/ dataSource.setMaxIdle(maxIdle); dataSource.setMaxWait(maxWait); dataSource.setMinIdle(minIdle); 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.setConnectionProperties(connectionProperties); dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); for (int i = 0; i < TEST_COUNT; ++i) { p0(dataSource, "dbcp", threadCount); } // dataSource.close(); System.out.println(); }
From source file:com.alibaba.druid.benckmark.pool.Oracle_Case4.java
public void test_dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setMaxActive(maxActive);/*from w w w. jav a 2s .c o m*/ dataSource.setMaxIdle(maxIdle); dataSource.setMaxWait(maxWait); dataSource.setPoolPreparedStatements(preparedStatementCache); dataSource.setMaxOpenPreparedStatements(preparedStatementCacheSize); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery(validationQuery); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setConnectionProperties(properties); // printAV_INFO(dataSource); for (int i = 0; i < loopCount; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); }
From source file:com.emc.ecs.sync.source.AtmosSource.java
@Override public void parseCustomOptions(CommandLine line) { AtmosUtil.AtmosUri atmosUri = AtmosUtil.parseUri(sourceUri); endpoints = atmosUri.endpoints;/*from w ww . j a v a 2s. com*/ uid = atmosUri.uid; secret = atmosUri.secret; namespaceRoot = atmosUri.rootPath; if (line.hasOption(SOURCE_OIDLIST_OPTION)) oidFile = line.getOptionValue(SOURCE_OIDLIST_OPTION); if (line.hasOption(SOURCE_NAMELIST_OPTION)) nameFile = line.getOptionValue(SOURCE_NAMELIST_OPTION); if (line.hasOption(SOURCE_SQLQUERY_OPTION)) { query = line.getOptionValue(SOURCE_SQLQUERY_OPTION); // Initialize a connection pool BasicDataSource ds = new BasicDataSource(); ds.setUrl(line.getOptionValue(JDBC_URL_OPT)); if (line.hasOption(JDBC_DRIVER_OPT)) ds.setDriverClassName(line.getOptionValue(JDBC_DRIVER_OPT)); ds.setUsername(line.getOptionValue(JDBC_USER_OPT)); ds.setPassword(line.getOptionValue(JDBC_PASSWORD_OPT)); ds.setMaxActive(200); ds.setMaxOpenPreparedStatements(180); setDataSource(ds); } deleteTags = line.hasOption(DELETE_TAGS_OPT); }
From source file:com.alibaba.druid.benckmark.pool.Case4.java
public void test_dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);//from w ww .ja va 2s. com dataSource.setMinIdle(minPoolSize); dataSource.setMaxIdle(maxPoolSize); dataSource.setPoolPreparedStatements(true); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setPoolPreparedStatements(true); dataSource.setMaxOpenPreparedStatements(maxOpenPreparedStatements); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery("SELECT 1"); dataSource.setTestOnBorrow(false); for (int i = 0; i < loopCount; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); }
From source file:blueprint.sdk.experimental.florist.db.ConnectionListener.java
public void contextInitialized(final ServletContextEvent arg0) { Properties poolProp = new Properties(); try {/*from www .j av a2s.co m*/ Context initContext = new InitialContext(); // load pool properties file (from class path) poolProp.load(ConnectionListener.class.getResourceAsStream("/jdbc_pools.properties")); StringTokenizer stk = new StringTokenizer(poolProp.getProperty("PROP_LIST")); // process all properties files list in pool properties (from class // path) while (stk.hasMoreTokens()) { try { String propName = stk.nextToken(); LOGGER.info(this, "loading jdbc properties - " + propName); Properties prop = new Properties(); prop.load(ConnectionListener.class.getResourceAsStream(propName)); DataSource dsr; if (prop.containsKey("JNDI_NAME")) { // lookup DataSource from JNDI // FIXME JNDI support is not tested yet. SPI or Factory // is needed here. LOGGER.warn(this, "JNDI DataSource support needs more hands on!"); dsr = (DataSource) initContext.lookup(prop.getProperty("JNDI_NAME")); } else { // create new BasicDataSource BasicDataSource bds = new BasicDataSource(); bds.setMaxActive(Integer.parseInt(prop.getProperty("MAX_ACTIVE"))); bds.setMaxIdle(Integer.parseInt(prop.getProperty("MAX_IDLE"))); bds.setMaxWait(Integer.parseInt(prop.getProperty("MAX_WAIT"))); bds.setInitialSize(Integer.parseInt(prop.getProperty("INITIAL"))); bds.setDriverClassName(prop.getProperty("CLASS_NAME")); bds.setUrl(prop.getProperty("URL")); bds.setUsername(prop.getProperty("USER")); bds.setPassword(prop.getProperty("PASSWORD")); bds.setValidationQuery(prop.getProperty("VALIDATION")); dsr = bds; } boundDsrs.put(prop.getProperty("POOL_NAME"), dsr); initContext.bind(prop.getProperty("POOL_NAME"), dsr); } catch (RuntimeException e) { LOGGER.trace(e); } } } catch (IOException | NamingException e) { LOGGER.trace(e); } }
From source file:com.alibaba.druid.benckmark.pool.Case1.java
public void test_dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);/* ww w. j a v a2 s . co m*/ dataSource.setMinIdle(minPoolSize); dataSource.setMaxIdle(maxPoolSize); dataSource.setPoolPreparedStatements(true); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setPoolPreparedStatements(true); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery("SELECT 1"); dataSource.setTestOnBorrow(false); for (int i = 0; i < loopCount; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); }
From source file:com.mirth.connect.connectors.jdbc.JdbcConnector.java
private void setupDataSource(String address, String driver, String username, String password) { BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(driver); basicDataSource.setUsername(username); basicDataSource.setPassword(password); basicDataSource.setUrl(address); dataSource = basicDataSource;// w ww.j a v a 2s . c o m }
From source file:com.uber.hoodie.hive.HoodieHiveClient.java
private void createHiveConnection() { if (connection == null) { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driverName); ds.setUrl(getHiveJdbcUrlWithDefaultDBName()); ds.setUsername(syncConfig.hiveUser); ds.setPassword(syncConfig.hivePass); LOG.info("Getting Hive Connection from Datasource " + ds); try {/* www . j av a 2 s. c o m*/ this.connection = ds.getConnection(); } catch (SQLException e) { throw new HoodieHiveSyncException( "Cannot create hive connection " + getHiveJdbcUrlWithDefaultDBName(), e); } } }
From source file:com.amazon.carbonado.repo.jdbc.TestH2.java
private RepositoryBuilder jdbcBuilder(boolean isMaster) throws RepositoryException { JDBCRepositoryBuilder builder = new JDBCRepositoryBuilder(); builder.setName("jdbc"); builder.setAutoVersioningEnabled(true, null); builder.setMaster(isMaster);//ww w .ja v a 2s . co m BasicDataSource ds = new BasicDataSource(); builder.setDataSource(ds); builder.setSchemaResolver(new H2SchemaResolver()); File dir = new File(TestUtilities.makeTestDirectory("jdbc"), "/h2"); String url = "jdbc:h2:" + dir.getPath(); ds.setDriverClassName("org.h2.Driver"); ds.setUrl(url); ds.setUsername("sa"); ds.setPassword(""); return builder; }
From source file:com.headstrong.fusion.services.dbpool.impl.DbPool.java
/** * package level constructor to create new dbpool instance. * //from w w w. j av a 2 s .co m * @param props * properties that needs to be set for creating the pool. * @throws FusionException * Error initializing dbpool */ /* package */ DbPool(Map<String, String> props, String dbcp) throws FusionException { BasicDataSource basicDataSource = new BasicDataSource(); if (dbProps == null) { dbProps = new HashMap<String, String>(props); } if (checkMandatoryProperties(props)) { basicDataSource.setDriverClassName(props.get(FusionConstants.DATABASE_CLASSNAME)); basicDataSource.setUsername(props.get(FusionConstants.DATABASE_USERNAME)); basicDataSource.setPassword(props.get(FusionConstants.DATABASE_PASSWORD)); basicDataSource.setUrl(props.get(FusionConstants.DATABASE_URL)); basicDataSource.setMinEvictableIdleTimeMillis(this.MINEVICTABLEIDLETIMEMILLIS); basicDataSource.setTimeBetweenEvictionRunsMillis(this.TIMEBETWEENEVICTIONRUNSMILLIS); String JDBCINITIALSIZE = props.get(FusionConstants.JDBCINITIALSIZE) != null ? props.get(FusionConstants.JDBCINITIALSIZE) : dbProps.get(FusionConstants.JDBCINITIALSIZE); basicDataSource.setInitialSize(Integer.parseInt(JDBCINITIALSIZE)); String JDBCMAXACTIVE = props.get(FusionConstants.JDBCMAXACTIVE) != null ? props.get(FusionConstants.JDBCMAXACTIVE) : dbProps.get(FusionConstants.JDBCMAXACTIVE); basicDataSource.setMaxActive(Integer.parseInt(JDBCMAXACTIVE)); String JDBCMAXOPENACTIVEPREP = props.get(FusionConstants.JDBCMAXOPENACTIVEPREP) != null ? props.get(FusionConstants.JDBCMAXOPENACTIVEPREP) : dbProps.get(FusionConstants.JDBCMAXOPENACTIVEPREP); basicDataSource.setMaxOpenPreparedStatements(Integer.parseInt(JDBCMAXOPENACTIVEPREP)); String MINEVICTABLEIDLETIMEMILLIS = props.get(FusionConstants.MINEVICTABLEIDLETIMEMILLIS) != null ? props.get(FusionConstants.MINEVICTABLEIDLETIMEMILLIS) : dbProps.get(FusionConstants.MINEVICTABLEIDLETIMEMILLIS); basicDataSource.setMinEvictableIdleTimeMillis(Integer.parseInt(MINEVICTABLEIDLETIMEMILLIS)); String TIMEBETWEENEVICTIONRUNSMILLIS = props.get(FusionConstants.TIMEBETWEENEVICTIONRUNSMILLIS) != null ? props.get(FusionConstants.TIMEBETWEENEVICTIONRUNSMILLIS) : dbProps.get(FusionConstants.TIMEBETWEENEVICTIONRUNSMILLIS); basicDataSource.setTimeBetweenEvictionRunsMillis(Long.parseLong(TIMEBETWEENEVICTIONRUNSMILLIS)); /* * if (props.get(FusionConstants.JDBCINITIALSIZE) == null) { * basicDataSource.setInitialSize(Integer.parseInt(dbProps * .get(FusionConstants.JDBCINITIALSIZE))); } else { * basicDataSource.setInitialSize(Integer.parseInt(props * .get(FusionConstants.JDBCINITIALSIZE))); } if * (props.get(FusionConstants.JDBCMAXACTIVE) == null) { * basicDataSource.setInitialSize(Integer.parseInt(dbProps * .get(FusionConstants.JDBCMAXACTIVE))); } else { * basicDataSource.setInitialSize(Integer.parseInt(props * .get(FusionConstants.JDBCMAXACTIVE))); } if * (props.get(FusionConstants.JDBCMAXOPENACTIVEPREP) == null) { * basicDataSource.setInitialSize(Integer.parseInt(dbProps * .get(FusionConstants.JDBCMAXOPENACTIVEPREP))); } else { * basicDataSource.setInitialSize(Integer.parseInt(props * .get(FusionConstants.JDBCMAXOPENACTIVEPREP))); } * * if (props.get(FusionConstants.MINEVICTABLEIDLETIMEMILLIS) == * null) { basicDataSource.setInitialSize(Integer.parseInt(dbProps * .get(FusionConstants.MINEVICTABLEIDLETIMEMILLIS))); } else { * basicDataSource.setInitialSize(Integer.parseInt(props * .get(FusionConstants.MINEVICTABLEIDLETIMEMILLIS))); } if * (props.get(FusionConstants.TIMEBETWEENEVICTIONRUNSMILLIS) == * null) { basicDataSource.setInitialSize(Integer.parseInt(dbProps * .get(FusionConstants.TIMEBETWEENEVICTIONRUNSMILLIS))); } else { * basicDataSource.setInitialSize(Integer.parseInt(props * .get(FusionConstants.TIMEBETWEENEVICTIONRUNSMILLIS))); } */ dataSource = basicDataSource; } else { throw new FusionException("Error initializing dbpool"); } }