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:cn.cuizuoli.gotour.config.DataSourceConfig.java
@Bean public DataSource dataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(env.getRequiredProperty("gotour.jdbc.driverClassName")); dataSource.setUrl(env.getRequiredProperty("gotour.jdbc.url")); dataSource.setUsername(env.getRequiredProperty("gotour.jdbc.username")); dataSource.setPassword(env.getRequiredProperty("gotour.jdbc.password")); dataSource.setInitialSize(env.getRequiredProperty("jdbc.initialSize", Integer.class)); dataSource.setMaxActive(env.getRequiredProperty("jdbc.maxActive", Integer.class)); dataSource.setMaxIdle(env.getRequiredProperty("jdbc.maxIdle", Integer.class)); dataSource.setMinIdle(env.getRequiredProperty("jdbc.minIdle", Integer.class)); dataSource.setDefaultAutoCommit(env.getRequiredProperty("jdbc.defaultAutoCommit", Boolean.class)); dataSource.setPoolPreparedStatements(env.getRequiredProperty("jdbc.poolPreparedStatements", Boolean.class)); dataSource.setValidationQuery(env.getRequiredProperty("jdbc.validationQuery")); dataSource.setTestOnBorrow(env.getRequiredProperty("jdbc.testOnBorrow", Boolean.class)); dataSource.setTestOnReturn(env.getRequiredProperty("jdbc.testOnReturn", Boolean.class)); dataSource.setTestWhileIdle(env.getRequiredProperty("jdbc.testWhileIdle", Boolean.class)); dataSource.setTimeBetweenEvictionRunsMillis( env.getRequiredProperty("jdbc.timeBetweenEvictionRunsMillis", Long.class)); dataSource.setNumTestsPerEvictionRun(env.getRequiredProperty("jdbc.numTestsPerEvictionRun", Integer.class)); dataSource.setMinEvictableIdleTimeMillis( env.getRequiredProperty("jdbc.minEvictableIdleTimeMillis", Long.class)); return dataSource; }
From source file:fr.cnes.sitools.datasource.jdbc.business.SitoolsDataSourceFactory.java
/** * Local creation of a DataSource// w w w . j a v a 2s.c o m * * @param driver * the database driver * @param connectURI * the URI to connect * @param userName * the database user name * @param password * the password * @param schemaOnConnection * the schema on connection * @return SitoolsDataSource a standard data source for SITools */ public SitoolsDataSource setupDataSource(String driver, String connectURI, String userName, String password, String schemaOnConnection) { String key = connectURI + "@" + userName; SitoolsDataSource foundDatasource = dataSources.get(key); if (foundDatasource == null) { BasicDataSource ds = new BasicDataSource(); // OSGi ds.setDriverClassLoader(getClass().getClassLoader()); ds.setDriverClassName(driver); ds.setUsername(userName); ds.setPassword(password); ds.setUrl(connectURI); ds.setMaxActive(10); ds.setInitialSize(1); // ds.setDefaultReadOnly(false); // ds.setDefaultAutoCommit(true); JDBCDataSource jdbcDS = new JDBCDataSource(); jdbcDS.setName(key); jdbcDS.setDriverClass(driver); foundDatasource = new SitoolsDataSource(jdbcDS, ds, schemaOnConnection); dataSources.put(key, foundDatasource); } return foundDatasource; }
From source file:com.alibaba.otter.node.etl.common.datasource.AbstractDbDialectTest.java
private DataSource createDataSource(String url, String userName, String password, String driverClassName, DataMediaType dataMediaType, String encoding) { BasicDataSource dbcpDs = new BasicDataSource(); dbcpDs.setRemoveAbandoned(true);//from w w w . j a v a 2s . c o m dbcpDs.setLogAbandoned(true); dbcpDs.setTestOnBorrow(true); dbcpDs.setTestWhileIdle(true); // ?? dbcpDs.setDriverClassName(driverClassName); dbcpDs.setUrl(url); dbcpDs.setUsername(userName); dbcpDs.setPassword(password); if (dataMediaType.isOracle()) { dbcpDs.addConnectionProperty("restrictGetTables", "true"); dbcpDs.setValidationQuery("select 1 from dual"); } else if (dataMediaType.isMysql()) { // open the batch mode for mysql since 5.1.8 dbcpDs.addConnectionProperty("useServerPrepStmts", "true"); dbcpDs.addConnectionProperty("rewriteBatchedStatements", "true"); if (StringUtils.isNotEmpty(encoding)) { dbcpDs.addConnectionProperty("characterEncoding", encoding); } dbcpDs.setValidationQuery("select 1"); } return dbcpDs; }
From source file:cn.edu.seu.cose.jellyjolly.model.dao.jdbc.mysql.MysqlConnectionFactory.java
private void initDataSource() throws IOException { BasicDataSource ds = new BasicDataSource(); Properties cfgpp = new Properties(); cfgpp.load(MysqlConnectionFactory.class.getResourceAsStream("dbcp.jdbc.properties")); ds.setDriverClassName(cfgpp.getProperty("jdbc.driverClassName")); ds.setUrl(cfgpp.getProperty("jdbc.url")); ds.setUsername(cfgpp.getProperty("jdbc.username")); ds.setPassword(cfgpp.getProperty("jdbc.password")); dataSource = ds;/* w w w.j a v a 2 s .co m*/ }
From source file:cn.cuizuoli.gotour.config.DataSourceConfig.java
@Bean public DataSource slaveDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(env.getRequiredProperty("gotour.slave.jdbc.driverClassName")); dataSource.setUrl(env.getRequiredProperty("gotour.slave.jdbc.url")); dataSource.setUsername(env.getRequiredProperty("gotour.slave.jdbc.username")); dataSource.setPassword(env.getRequiredProperty("gotour.slave.jdbc.password")); dataSource.setInitialSize(env.getRequiredProperty("jdbc.initialSize", Integer.class)); dataSource.setMaxActive(env.getRequiredProperty("jdbc.maxActive", Integer.class)); dataSource.setMaxIdle(env.getRequiredProperty("jdbc.maxIdle", Integer.class)); dataSource.setMinIdle(env.getRequiredProperty("jdbc.minIdle", Integer.class)); dataSource.setDefaultAutoCommit(env.getRequiredProperty("jdbc.defaultAutoCommit", Boolean.class)); dataSource.setPoolPreparedStatements(env.getRequiredProperty("jdbc.poolPreparedStatements", Boolean.class)); dataSource.setValidationQuery(env.getRequiredProperty("jdbc.validationQuery")); dataSource.setTestOnBorrow(env.getRequiredProperty("jdbc.testOnBorrow", Boolean.class)); dataSource.setTestOnReturn(env.getRequiredProperty("jdbc.testOnReturn", Boolean.class)); dataSource.setTestWhileIdle(env.getRequiredProperty("jdbc.testWhileIdle", Boolean.class)); dataSource.setTimeBetweenEvictionRunsMillis( env.getRequiredProperty("jdbc.timeBetweenEvictionRunsMillis", Long.class)); dataSource.setNumTestsPerEvictionRun(env.getRequiredProperty("jdbc.numTestsPerEvictionRun", Integer.class)); dataSource.setMinEvictableIdleTimeMillis( env.getRequiredProperty("jdbc.minEvictableIdleTimeMillis", Long.class)); return dataSource; }
From source file:jetsennet.orm.datasource.DbcpDataSourceCreator.java
@Override public DataSource createDatasource(ConnectionInfo conn, DbPoolInfo props) throws SQLException { org.apache.commons.dbcp.BasicDataSource dataSource = new org.apache.commons.dbcp.BasicDataSource(); dataSource.setDriverClassName(conn.driver); dataSource.setUrl(conn.url);/*from w w w . ja v a2s .c om*/ dataSource.setUsername(conn.user); dataSource.setPassword(conn.pwd); String connectionProperties = props.get("connectionProperties"); if (connectionProperties != null && connectionProperties.trim().length() > 0) { dataSource.setConnectionProperties(connectionProperties); } Boolean defaultAutoCommit = Utils.str2Boolean(props.get("defaultAutoCommit")); if (defaultAutoCommit != null) { dataSource.setDefaultAutoCommit(defaultAutoCommit); } Boolean defaultReadOnly = Utils.str2Boolean(props.get("defaultReadOnly")); if (defaultReadOnly != null) { dataSource.setDefaultReadOnly(defaultReadOnly); } Integer defaultTransactionIsolation = Utils.strToInteger(props.get("defaultTransactionIsolation")); if (defaultTransactionIsolation != null) { dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation); } String defaultCatalog = props.get("defaultCatalog"); if (defaultCatalog != null && defaultCatalog.trim().length() > 0) { dataSource.setDefaultCatalog(defaultCatalog); } int initialSize = Utils.strToInt(props.get("initialSize")); if (initialSize > 0) { dataSource.setInitialSize(initialSize); } int maxActive = Utils.strToInt(props.get("maxActive")); if (maxActive > 0) { dataSource.setMaxActive(maxActive); } int maxIdle = Utils.strToInt(props.get("maxIdle")); if (maxIdle > 0) { dataSource.setMaxIdle(maxIdle); } int minIdle = Utils.strToInt(props.get("minIdle")); if (minIdle > 0) { dataSource.setMinIdle(minIdle); } int maxWait = Utils.strToInt(props.get("maxWait")); if (maxWait > 0) { dataSource.setMaxWait(maxWait); } String validationQuery = props.get("validationQuery"); if (validationQuery != null && validationQuery.trim().length() > 0) { dataSource.setValidationQuery(validationQuery); } Integer validationQueryTimeout = Utils.strToInteger(props.get("validationQueryTimeout")); if (validationQueryTimeout != null) { dataSource.setValidationQueryTimeout(validationQueryTimeout); } Boolean testOnBorrow = Utils.str2Boolean(props.get("testOnBorrow")); if (testOnBorrow != null) { dataSource.setTestOnBorrow(testOnBorrow); } Boolean testOnReturn = Utils.str2Boolean(props.get("testOnReturn")); if (testOnReturn != null) { dataSource.setTestOnReturn(testOnReturn); } Boolean testWhileIdle = Utils.str2Boolean(props.get("testWhileIdle")); if (testWhileIdle != null) { dataSource.setTestWhileIdle(testWhileIdle); } Integer timeBetweenEvictionRunsMillis = Utils.strToInteger(props.get("timeBetweenEvictionRunsMillis")); if (timeBetweenEvictionRunsMillis != null) { dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); } Integer numTestsPerEvictionRun = Utils.strToInteger(props.get("numTestsPerEvictionRun")); if (numTestsPerEvictionRun != null) { dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun); } int minEvictableIdleTimeMillis = Utils.strToInt(props.get("minEvictableIdleTimeMillis")); if (minEvictableIdleTimeMillis > 0) { dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); } Boolean removeAbandoned = Utils.str2Boolean(props.get("removeAbandoned")); if (removeAbandoned != null) { dataSource.setRemoveAbandoned(removeAbandoned); } int removeAbandonedTimeout = Utils.strToInt(props.get("removeAbandonedTimeout")); if (removeAbandonedTimeout > 0) { dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout); } Boolean logAbandoned = Utils.str2Boolean(props.get("logAbandoned")); if (logAbandoned != null) { dataSource.setLogAbandoned(logAbandoned); } return dataSource; }
From source file:fr.cnes.sitools.datasource.jdbc.business.SitoolsSQLDataSourceFactory.java
/** * Local creation of a DataSource/* ww w . j av a 2 s . c om*/ * * @param driver * the database driver * @param connectURI * the URI to connect * @param userName * the database user name * @param password * the password * @param schemaOnConnection * the schema on connection * @return SitoolsDataSource a standard data source for SITools */ public SitoolsSQLDataSource setupDataSource(String driver, String connectURI, String userName, String password, String schemaOnConnection) { String key = connectURI + "@" + userName; SitoolsSQLDataSource foundDatasource = dataSources.get(key); if (foundDatasource == null) { BasicDataSource ds = new BasicDataSource(); // OSGi ds.setDriverClassLoader(getClass().getClassLoader()); ds.setDriverClassName(driver); ds.setUsername(userName); ds.setPassword(password); ds.setUrl(connectURI); ds.setMaxActive(10); ds.setInitialSize(1); // test that the connection is alive on each request. If not It will be dropped from the pool and another // connection will be created if (!"org.hsqldb.jdbcDriver".equals(driver)) { ds.setTestOnBorrow(true); ds.setValidationQuery("SELECT 1"); } // ds.setDefaultReadOnly(false); // ds.setDefaultAutoCommit(true); JDBCDataSource jdbcDS = new JDBCDataSource(); jdbcDS.setName(key); jdbcDS.setDriverClass(driver); foundDatasource = new SitoolsSQLDataSource(jdbcDS, ds, schemaOnConnection); dataSources.put(key, foundDatasource); } return foundDatasource; }
From source file:com.btmatthews.maven.plugins.inmemdb.db.derby.DerbyDatabase.java
/** * Get the data source that describes the connection to the in-memory Apache * Derby database.//from w w w .ja v a 2s. com * * @param attributes Additional attributes for the data source connection string. * @return Returns {@code dataSource} which was initialised by the * constructor. */ @Override public DataSource getDataSource() { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl(getUrl(getAttributes())); dataSource.setUsername(getUsername()); if (StringUtils.isNotEmpty(getPassword())) { dataSource.setPassword(getPassword()); } dataSource.setDriverClassName(DRIVER_CLASS); return dataSource; }
From source file:com.uber.hoodie.utilities.HiveIncrementalPuller.java
private DataSource getDatasource() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driverName);/*from ww w . j a v a2 s. co m*/ ds.setUrl(config.hiveJDBCUrl); ds.setUsername(config.hiveUsername); ds.setPassword(config.hivePassword); return ds; }
From source file:fr.cnes.sitools.datasource.jdbc.business.SitoolsDataSourceFactory.java
/** * Setup a dataSource for "users". Usage is for all users for consultation functions. * //from ww w .jav a 2 s . c om * @param dataSource * the DataSource to update * @return SitoolsDataSource the new DataSource */ public SitoolsDataSource setupDataSourceForUsers(JDBCDataSource dataSource) { String key = dataSource.getId(); SitoolsDataSource foundDatasource = dataSources.get(key); if (foundDatasource == null) { BasicDataSource ds = new BasicDataSource(); // OSGi ds.setDriverClassLoader(getClass().getClassLoader()); ds.setDriverClassName(dataSource.getDriverClass()); ds.setUsername(dataSource.getUserLogin()); ds.setPassword(dataSource.getUserPassword()); ds.setUrl(dataSource.getUrl()); ds.setMaxActive(dataSource.getMaxActive()); ds.setInitialSize(dataSource.getInitialSize()); ds.setDefaultReadOnly(true); if ((dataSource.getSchemaOnConnection() != null) && !dataSource.getSchemaOnConnection().equals("")) { ds.setDefaultCatalog(dataSource.getSchemaOnConnection()); } foundDatasource = new SitoolsDataSource(dataSource, ds, dataSource.getSchemaOnConnection()); dataSources.put(key, foundDatasource); } return foundDatasource; }