List of usage examples for org.apache.commons.dbcp BasicDataSource setPassword
public synchronized void setPassword(String password)
Sets the #password .
Note: this method currently has no effect once the pool has been initialized.
From source file:org.apache.airavata.common.utils.DBUtil.java
/** * Gets a new DBCP data source./*from ww w . j a va2 s .c o m*/ * * @return A new data source. */ public DataSource getDataSource() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(this.driverName); ds.setUsername(this.databaseUserName); ds.setPassword(this.databasePassword); ds.setUrl(this.jdbcUrl); return ds; }
From source file:org.apache.drill.exec.store.http.InsertTestData.java
public static DataSource createDataSource(String driver, String url, String userName, String password) { BasicDataSource source = new BasicDataSource(); source.setDriverClassName(driver);/*from w ww . j a v a2 s .com*/ source.setUrl(url); if (userName != null) { source.setUsername(userName); } if (password != null) { source.setPassword(password); } source.setInitialSize(1); source.setPoolPreparedStatements(true); try { // initial a connection source.getConnection(); } catch (SQLException sqlE) { logger.error("db connection error: ", sqlE); } return source; }
From source file:org.apache.drill.exec.store.http.util.DBUtil.java
public static DataSource createDataSource(String driver, String url, String userName, String password) { BasicDataSource source = new BasicDataSource(); source.setDriverClassName(driver);/*from w w w . j ava 2 s. co m*/ source.setUrl(url); if (userName != null) { source.setUsername(userName); } if (password != null) { source.setPassword(password); } source.setPoolPreparedStatements(true); source.setInitialSize(1); try { // initial a connection Connection conn = source.getConnection(); conn.close(); } catch (SQLException sqlE) { logger.error("db connection error: ", sqlE); } return source; }
From source file:org.apache.drill.exec.store.jdbc.JdbcStoragePlugin.java
public JdbcStoragePlugin(JdbcStorageConfig config, DrillbitContext context, String name) { this.context = context; this.config = config; this.name = name; BasicDataSource source = new BasicDataSource(); source.setDriverClassName(config.getDriver()); source.setUrl(config.getUrl());/*from w w w . j a va2 s.c om*/ if (config.getUsername() != null) { source.setUsername(config.getUsername()); } if (config.getPassword() != null) { source.setPassword(config.getPassword()); } this.source = source; this.dialect = JdbcSchema.createDialect(source); this.convention = new DrillJdbcConvention(dialect, name); }
From source file:org.apache.eagle.alert.metadata.impl.JdbcMetadataHandler.java
public JdbcMetadataHandler(Config config) { try {/*from www. ja va 2s. c o m*/ //JdbcSchemaManager.getInstance().init(config); BasicDataSource bDatasource = new BasicDataSource(); bDatasource.setDriverClassName(config.getString(MetadataUtils.JDBC_DRIVER_PATH)); if (config.hasPath(MetadataUtils.JDBC_USERNAME_PATH)) { bDatasource.setUsername(config.getString(MetadataUtils.JDBC_USERNAME_PATH)); bDatasource.setPassword(config.getString(MetadataUtils.JDBC_PASSWORD_PATH)); } bDatasource.setUrl(config.getString(MetadataUtils.JDBC_CONNECTION_PATH)); if (config.hasPath(MetadataUtils.JDBC_CONNECTION_PROPERTIES_PATH)) { bDatasource .setConnectionProperties(config.getString(MetadataUtils.JDBC_CONNECTION_PROPERTIES_PATH)); } this.dataSource = bDatasource; } catch (Exception e) { LOG.error(e.getMessage(), e); } }
From source file:org.apache.eagle.metadata.store.jdbc.provider.JDBCDataSourceProvider.java
@Override public DataSource get() { BasicDataSource datasource = new BasicDataSource(); datasource.setDriverClassName(config.getDriverClassName()); datasource.setUsername(config.getUsername()); datasource.setPassword(config.getPassword()); datasource.setUrl(config.getConnection()); datasource.setConnectionProperties(config.getConnectionProperties()); LOGGER.info("Register JDBCDataSourceShutdownHook"); Runtime.getRuntime().addShutdownHook(new Thread("JDBCDataSourceShutdownHook") { @Override/* w w w . j av a2s . c o m*/ public void run() { try { LOGGER.info("Shutting down data fromStream"); datasource.close(); } catch (SQLException e) { LOGGER.error("SQLException: {}", e.getMessage(), e); throw new IllegalStateException("Failed to close datasource", e); } } }); return datasource; }
From source file:org.apache.gobblin.data.management.retention.CleanableMysqlDatasetStoreDatasetTest.java
@BeforeClass public void setUp() throws Exception { this.testMetastoreDatabase = TestMetastoreDatabaseFactory.get(); String jdbcUrl = this.testMetastoreDatabase.getJdbcUrl(); ConfigBuilder configBuilder = ConfigBuilder.create(); BasicDataSource mySqlDs = new BasicDataSource(); mySqlDs.setDriverClassName(ConfigurationKeys.DEFAULT_STATE_STORE_DB_JDBC_DRIVER); mySqlDs.setDefaultAutoCommit(false); mySqlDs.setUrl(jdbcUrl);//from w w w . j av a2 s.c om mySqlDs.setUsername(TEST_USER); mySqlDs.setPassword(TEST_PASSWORD); this.dbJobStateStore = new MysqlStateStore<>(mySqlDs, TEST_STATE_STORE, false, JobState.class); configBuilder.addPrimitive("selection.timeBased.lookbackTime", "10m"); configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_TYPE_KEY, "mysql"); configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_TABLE_KEY, TEST_STATE_STORE); configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_URL_KEY, jdbcUrl); configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_USER_KEY, TEST_USER); configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_PASSWORD_KEY, TEST_PASSWORD); ClassAliasResolver<DatasetStateStore.Factory> resolver = new ClassAliasResolver<>( DatasetStateStore.Factory.class); DatasetStateStore.Factory stateStoreFactory = resolver.resolveClass("mysql").newInstance(); this.config = configBuilder.build(); this.dbDatasetStateStore = stateStoreFactory.createStateStore(configBuilder.build()); // clear data that may have been left behind by a prior test run this.dbJobStateStore.delete(TEST_JOB_NAME1); this.dbDatasetStateStore.delete(TEST_JOB_NAME1); this.dbJobStateStore.delete(TEST_JOB_NAME2); this.dbDatasetStateStore.delete(TEST_JOB_NAME2); }
From source file:org.apache.gobblin.runtime.MysqlDatasetStateStoreTest.java
@BeforeClass public void setUp() throws Exception { testMetastoreDatabase = TestMetastoreDatabaseFactory.get(); String jdbcUrl = testMetastoreDatabase.getJdbcUrl(); ConfigBuilder configBuilder = ConfigBuilder.create(); BasicDataSource mySqlDs = new BasicDataSource(); mySqlDs.setDriverClassName(ConfigurationKeys.DEFAULT_STATE_STORE_DB_JDBC_DRIVER); mySqlDs.setDefaultAutoCommit(false); mySqlDs.setUrl(jdbcUrl);/*from ww w.j av a 2 s . c o m*/ mySqlDs.setUsername(TEST_USER); mySqlDs.setPassword(TEST_PASSWORD); dbJobStateStore = new MysqlStateStore<>(mySqlDs, TEST_STATE_STORE, false, JobState.class); configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_URL_KEY, jdbcUrl); configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_USER_KEY, TEST_USER); configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_PASSWORD_KEY, TEST_PASSWORD); ClassAliasResolver<DatasetStateStore.Factory> resolver = new ClassAliasResolver<>( DatasetStateStore.Factory.class); DatasetStateStore.Factory stateStoreFactory = resolver.resolveClass("mysql").newInstance(); dbDatasetStateStore = stateStoreFactory.createStateStore(configBuilder.build()); // clear data that may have been left behind by a prior test run dbJobStateStore.delete(TEST_JOB_NAME); dbDatasetStateStore.delete(TEST_JOB_NAME); dbJobStateStore.delete(TEST_JOB_NAME2); dbDatasetStateStore.delete(TEST_JOB_NAME2); }
From source file:org.apache.jackrabbit.core.util.db.ConnectionFactory.java
/** * Creates and returns a pooling JDBC {@link DataSource} for accessing * the database identified by the given driver class and JDBC * connection URL. The driver class can be <code>null</code> if * a specific driver has not been configured. * * @param driverClass the JDBC driver class, or <code>null</code> * @param url the JDBC connection URL/*from w w w . ja v a2 s. co m*/ * @return pooling DataSource for accessing the specified database */ private BasicDataSource getDriverDataSource(Class<?> driverClass, String url, String user, String password) { BasicDataSource ds = new BasicDataSource(); created.add(ds); if (driverClass != null) { Driver instance = null; try { // Workaround for Apache Derby: // The JDBC specification recommends the Class.forName // method without the .newInstance() method call, // but it is required after a Derby 'shutdown' instance = (Driver) driverClass.newInstance(); } catch (Throwable e) { // Ignore exceptions as there's no requirement for // a JDBC driver class to have a public default constructor } if (instance != null) { if (instance.jdbcCompliant()) { // JCR-3445 At the moment the PostgreSQL isn't compliant because it doesn't implement this method... ds.setValidationQueryTimeout(3); } } ds.setDriverClassName(driverClass.getName()); } ds.setUrl(url); ds.setUsername(user); ds.setPassword(password); ds.setDefaultAutoCommit(true); ds.setTestOnBorrow(false); ds.setTestWhileIdle(true); ds.setTimeBetweenEvictionRunsMillis(600000); // 10 Minutes ds.setMinEvictableIdleTimeMillis(60000); // 1 Minute ds.setMaxActive(-1); // unlimited ds.setMaxIdle(GenericObjectPool.DEFAULT_MAX_IDLE + 10); ds.setValidationQuery(guessValidationQuery(url)); ds.setAccessToUnderlyingConnectionAllowed(true); ds.setPoolPreparedStatements(true); ds.setMaxOpenPreparedStatements(-1); // unlimited return ds; }
From source file:org.apache.james.mailrepository.jdbc.JDBCMailRepositoryTest.java
private BasicDataSource getDataSource() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(EmbeddedDriver.class.getName()); ds.setUrl("jdbc:derby:target/testdb;create=true"); ds.setUsername("james"); ds.setPassword("james"); return ds;// w w w.j a va 2 s .c o m }