List of usage examples for org.apache.commons.dbcp BasicDataSource setDriverClassName
public synchronized void setDriverClassName(String driverClassName)
Sets the jdbc driver class name.
Note: this method currently has no effect once the pool has been initialized.
From source file:org.eclipse.dirigible.repository.datasource.DataSourceFacade.java
private DataSource createDirectDataSource(Properties properties) { String id = properties.getProperty(DataSourceFacade.PARAM_DB_ID); String name = properties.getProperty(DataSourceFacade.PARAM_DB_NAME); String url = properties.getProperty(DataSourceFacade.PARAM_DB_LOC); String driver = properties.getProperty(DataSourceFacade.PARAM_DB_DRIVER); String user = properties.getProperty(DataSourceFacade.PARAM_DB_USER); String password = properties.getProperty(DataSourceFacade.PARAM_DB_PASSWORD); String defaultAutoCommit = properties.getProperty(DataSourceFacade.PARAM_DB_AUTO_COMMIT); String maxActive = properties.getProperty(DataSourceFacade.PARAM_DB_AUTO_MAX_ACTIVE); String maxIdle = properties.getProperty(DataSourceFacade.PARAM_DB_AUTO_MAX_IDLE); String maxWait = properties.getProperty(DataSourceFacade.PARAM_DB_AUTO_MAX_WAIT); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(driver); basicDataSource.setUrl(url);//from ww w . ja v a 2 s . c o m basicDataSource.setUsername(user); basicDataSource.setPassword(password); basicDataSource.setDefaultAutoCommit(Boolean.parseBoolean(defaultAutoCommit)); basicDataSource.setMaxActive(maxActive != null ? Integer.parseInt(maxActive) : 100); basicDataSource.setMaxIdle(maxIdle != null ? Integer.parseInt(maxIdle) : 30); basicDataSource.setMaxWait(maxWait != null ? Integer.parseInt(maxWait) : 10000); return basicDataSource; }
From source file:org.encuestame.test.persistence.config.DBTestConfig.java
@Bean(name = "jdbcDataSource") public BasicDataSource jdbcDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(EnMePlaceHolderConfigurer.getProperty("datasource.classname")); dataSource.setUrl(EnMePlaceHolderConfigurer.getProperty("datasource.urldb")); dataSource.setUsername(EnMePlaceHolderConfigurer.getProperty("datasource.userbd")); dataSource.setPassword(EnMePlaceHolderConfigurer.getProperty("datasource.pass")); return dataSource; }
From source file:org.fao.geonet.arcgis.ArcSDEJdbcConnection.java
/** * * * @param connectionString An example of server string in case of Oracle * is: "jdbc:oracle:thin:@84.123.79.19:1521:orcl". * @param username the username to connect to the database. * @param password the password to connect to the database. *//*from w w w.j a va 2 s .c o m*/ public ArcSDEJdbcConnection(String driverName, String connectionString, String username, String password) { try { Log.debug(ARCSDE_LOG_MODULE_NAME, "Getting ArcSDE connection (via JDBC)"); BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverName); dataSource.setUrl(connectionString); dataSource.setUsername(username); dataSource.setPassword(password); // Test the connection config getting a connection and closing it. dataSource.getConnection().close(); jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); } catch (SQLException x) { Log.error(ARCSDE_LOG_MODULE_NAME, "Error getting ArcSDE connection (via JDBC)", x); throw new ExceptionInInitializerError(new ArcSDEConnectionException( "Exception in ArcSDEConnection using JDBC: can not connect to the database", x)); } }
From source file:org.ff4j.test.utils.JdbcTestHelper.java
/** * Initialize DataSource with a pool of connections to HQL database. * * @return//from w w w . j av a2 s . c om * current data source */ public static DataSource createInMemoryHQLDataSource() { // Init DataSource BasicDataSource dbcpDataSource = new BasicDataSource(); dbcpDataSource.setDriverClassName("org.hsqldb.jdbcDriver"); dbcpDataSource.setUsername("sa"); dbcpDataSource.setPassword(""); dbcpDataSource.setUrl("jdbc:hsqldb:mem:."); dbcpDataSource.setMaxActive(3); dbcpDataSource.setMaxIdle(2); dbcpDataSource.setInitialSize(2); dbcpDataSource.setValidationQuery("select 1 from INFORMATION_SCHEMA.SYSTEM_USERS;"); dbcpDataSource.setPoolPreparedStatements(true); return dbcpDataSource; }
From source file:org.freewheelschedule.freewheel.config.ServerConfig.java
@Bean public BasicDataSource freewheelDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverClass); dataSource.setUrl(hibernateUrl);//from w w w. ja v a 2 s . c om dataSource.setUsername(hibernateUser); dataSource.setPassword(hibernatePassword); return dataSource; }
From source file:org.geosde.core.jdbc.data.datasource.DataSourceUtil.java
/** * Builds up a default DBCP DataSource that easy to use connection factories * can use to setup a connection pool.//www . jav a 2 s. com * * @param url * the jdbc url * @param driverName * the jdbc driver full qualified class name * @param username * @param password * @param maxActive maximum number of concurrent connections in the pool * @param minIdle minimum number of concurrent connections in the pool * @param validationQuery * the validation query to be used for connection liveliness on * borrow, or null, if no check is to be performed * @param cachePreparedStatements * wheter to cache prepared statements or not * @return * @throws DataSourceException */ public static ManageableDataSource buildDefaultDataSource(String url, String driverName, String username, String password, int maxActive, int minIdle, String validationQuery, boolean cachePreparedStatements, int removeAbandonedTimeout) throws DataSourceException { // basics BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverName); dataSource.setUrl(url); dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setAccessToUnderlyingConnectionAllowed(true); // pool size dataSource.setMaxActive(maxActive); dataSource.setMinIdle(minIdle); // pool eviction settings dataSource.setMinEvictableIdleTimeMillis(1000 * 20); dataSource.setTimeBetweenEvictionRunsMillis(1000 * 10); // connection validation if (validationQuery != null) { dataSource.setTestOnBorrow(true); dataSource.setValidationQuery(validationQuery); } // prepared statement cache if (cachePreparedStatements) { dataSource.setPoolPreparedStatements(true); dataSource.setMaxOpenPreparedStatements(10); } // remove abandoned connections (I know it's deprecated, but we do want // something shaving off lost connections. Let's give them 5 minutes of // continuous usage if (removeAbandonedTimeout > 0) { dataSource.setRemoveAbandoned(true); dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout); dataSource.setLogAbandoned(true); } Connection conn = null; try { conn = dataSource.getConnection(); } catch (Exception e) { throw new DataSourceException("Connection test failed ", e); } finally { if (conn != null) try { conn.close(); } catch (SQLException e) { } } return new DBCPDataSource(dataSource); }
From source file:org.geosde.core.jdbc.data.datasource.DBCPDataSourceFactory.java
public DataSource createNewDataSource(Map params) throws IOException { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName((String) DRIVERCLASS.lookUp(params)); dataSource.setUrl((String) JDBC_URL.lookUp(params)); dataSource.setUsername((String) USERNAME.lookUp(params)); dataSource.setPassword((String) PASSWORD.lookUp(params)); dataSource.setAccessToUnderlyingConnectionAllowed(true); dataSource.setMaxActive(((Integer) MAXACTIVE.lookUp(params)).intValue()); dataSource.setMaxIdle(((Integer) MAXIDLE.lookUp(params)).intValue()); // check the data source is properly setup by trying to gather a connection out of it Connection conn = null;/*from w ww . ja va 2 s. com*/ try { conn = dataSource.getConnection(); } catch (SQLException e) { throw new DataSourceException("Connection pool improperly set up: " + e.getMessage(), e); } finally { // close the connection at once if (conn != null) try { conn.close(); } catch (SQLException e) { } } return dataSource; }
From source file:org.geosde.core.jdbc.JDBCDataStoreFactory.java
/** * DataSource access allowing SQL use: intended to allow client code to query available schemas. * <p>/*from w w w . ja v a 2 s. c om*/ * This DataSource is the clients responsibility to close() when they are finished using it. * </p> * @param params Map of connection parameter. * @return DataSource for SQL use * @throws IOException */ public BasicDataSource createDataSource(Map params) throws IOException { //create a datasource BasicDataSource dataSource = new BasicDataSource(); // driver dataSource.setDriverClassName(getDriverClassName()); // url dataSource.setUrl(getJDBCUrl(params)); // username (on embedded dbs it can be optional) String user = (String) USER.lookUp(params); if (user != null) { dataSource.setUsername(user); } // password String passwd = (String) PASSWD.lookUp(params); if (passwd != null) { dataSource.setPassword(passwd); } // max wait Integer maxWait = (Integer) MAXWAIT.lookUp(params); if (maxWait != null && maxWait != -1) { dataSource.setMaxWait(maxWait * 1000); } // connection pooling options Integer minConn = (Integer) MINCONN.lookUp(params); if (minConn != null) { dataSource.setMinIdle(minConn); } Integer maxConn = (Integer) MAXCONN.lookUp(params); if (maxConn != null) { dataSource.setMaxActive(maxConn); } Boolean validate = (Boolean) VALIDATECONN.lookUp(params); if (validate != null && validate && getValidationQuery() != null) { dataSource.setTestOnBorrow(true); dataSource.setValidationQuery(getValidationQuery()); } Boolean testWhileIdle = (Boolean) TEST_WHILE_IDLE.lookUp(params); if (testWhileIdle != null) { dataSource.setTestWhileIdle(testWhileIdle); } Integer timeBetweenEvictorRuns = (Integer) TIME_BETWEEN_EVICTOR_RUNS.lookUp(params); if (timeBetweenEvictorRuns != null && timeBetweenEvictorRuns > 0) { dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictorRuns * 1000l); } Integer minEvictableTime = (Integer) MIN_EVICTABLE_TIME.lookUp(params); if (minEvictableTime != null) { dataSource.setMinEvictableIdleTimeMillis(minEvictableTime * 1000l); } Integer evictorTestsPerRun = (Integer) EVICTOR_TESTS_PER_RUN.lookUp(params); if (evictorTestsPerRun != null) { dataSource.setNumTestsPerEvictionRun(evictorTestsPerRun); } // some datastores might need this dataSource.setAccessToUnderlyingConnectionAllowed(true); return dataSource; }
From source file:org.geoserver.security.jdbc.AbstractJDBCService.java
/** * initialize a {@link DataSource} form a * {@link JdbcSecurityServiceConfig} object * //from www. j a v a 2 s . c om * @param config * @throws IOException */ public void initializeDSFromConfig(SecurityNamedServiceConfig namedConfig) throws IOException { JDBCSecurityServiceConfig config = (JDBCSecurityServiceConfig) namedConfig; if (config.isJndi()) { String jndiName = config.getJndiName(); try { Context initialContext = new InitialContext(); datasource = (DataSource) initialContext.lookup(jndiName); } catch (NamingException e) { throw new IOException(e); } } else { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName(config.getDriverClassName()); bds.setUrl(config.getConnectURL()); bds.setUsername(config.getUserName()); bds.setPassword(config.getPassword()); bds.setDefaultAutoCommit(false); bds.setDefaultTransactionIsolation(DEFAULT_ISOLATION_LEVEL); bds.setMaxActive(10); datasource = bds; } }
From source file:org.geoserver.spatialite.SpatiaLiteDataStoreFactory.java
@Override public BasicDataSource createDataSource(Map params) throws IOException { //create a datasource BasicDataSource dataSource = new BasicDataSource(); // driver// ww w . j a v a 2 s . c o m dataSource.setDriverClassName(getDriverClassName()); // url dataSource.setUrl(getJDBCUrl(params)); addConnectionProperties(dataSource); initializeDataSource(dataSource); return dataSource; }