List of usage examples for org.apache.commons.dbcp BasicDataSource setUsername
public synchronized void setUsername(String username)
Sets the #username .
Note: this method currently has no effect once the pool has been initialized.
From source file:hoot.services.HootServicesSpringConfig.java
@Bean(name = "dataSource") public DataSource dataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.postgresql.Driver"); dataSource.setUrl("jdbc:postgresql://" + env.getProperty("DB_HOST") + ":" + env.getProperty("DB_PORT") + "/" + env.getProperty("DB_NAME")); dataSource.setUsername(env.getProperty("DB_USER")); dataSource.setPassword(env.getProperty("DB_PASSWORD")); dataSource.setInitialSize(25);/*from w w w . j a va 2s . c o m*/ dataSource.setMaxActive(90); dataSource.setMaxIdle(30); dataSource.setDefaultAutoCommit(false); dataSource.setRemoveAbandoned(true); dataSource.setLogAbandoned(true); return dataSource; }
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:com.tedexis.commons.db.DBSinglePool.java
/** * Crea el pool de conexiones//from w ww .j av a2 s .c om * * @param configurationDB * @return * @throws ClassNotFoundException */ private BasicDataSource getBasicDataSource(ConfigurationDB configurationDB) throws ClassNotFoundException { BasicDataSource ds = null; if (dataSource == null) { ds = new BasicDataSource(); Class.forName(configurationDB.driverClass); ds.setUrl(configurationDB.url); ds.setDriverClassName(configurationDB.driverClass); ds.setUsername(configurationDB.user); ds.setPassword(configurationDB.password); ds.setInitialSize(configurationDB.poolSize); ds.setMaxActive(configurationDB.poolMaxAct); ds.setMaxIdle(configurationDB.poolMaxIdle); ds.setMaxWait(configurationDB.poolWait); return ds; } return dataSource; }
From source file:com.google.gerrit.server.schema.DataSourceProvider.java
private DataSource open(final SitePaths site, final Config cfg, final Context context, final DataSourceType dst) { ConfigSection dbs = new ConfigSection(cfg, "database"); String driver = dbs.optional("driver"); if (Strings.isNullOrEmpty(driver)) { driver = dst.getDriver();//from ww w. j av a 2 s . c o m } String url = dbs.optional("url"); if (Strings.isNullOrEmpty(url)) { url = dst.getUrl(); } String username = dbs.optional("username"); String password = dbs.optional("password"); boolean usePool; if (context == Context.SINGLE_USER) { usePool = false; } else { usePool = cfg.getBoolean("database", "connectionpool", dst.usePool()); } if (usePool) { final BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driver); ds.setUrl(url); if (username != null && !username.isEmpty()) { ds.setUsername(username); } if (password != null && !password.isEmpty()) { ds.setPassword(password); } ds.setMaxActive(cfg.getInt("database", "poollimit", 8)); ds.setMinIdle(cfg.getInt("database", "poolminidle", 4)); ds.setMaxIdle(cfg.getInt("database", "poolmaxidle", 4)); ds.setMaxWait(ConfigUtil.getTimeUnit(cfg, "database", null, "poolmaxwait", MILLISECONDS.convert(30, SECONDS), MILLISECONDS)); ds.setInitialSize(ds.getMinIdle()); return ds; } else { // Don't use the connection pool. // try { final Properties p = new Properties(); p.setProperty("driver", driver); p.setProperty("url", url); if (username != null) { p.setProperty("user", username); } if (password != null) { p.setProperty("password", password); } return new SimpleDataSource(p); } catch (SQLException se) { throw new ProvisionException("Database unavailable", se); } } }
From source file:com.dangdang.ddframe.job.statistics.rdb.StatisticRdbRepositoryTest.java
@Before public void setup() throws SQLException { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(org.h2.Driver.class.getName()); dataSource.setUrl("jdbc:h2:mem:"); dataSource.setUsername("sa"); dataSource.setPassword(""); repository = new StatisticRdbRepository(dataSource); }
From source file:calculus.backend.JpaConfig.java
@Bean public DataSource dataSource() { loadProperties();/*from w w w . j a va 2 s. co m*/ BasicDataSource driver = new BasicDataSource(); driver.setDriverClassName(this.driver); driver.setUrl(this.url); driver.setUsername(this.user); driver.setPassword(this.pass); driver.setMaxIdle(poolSize); driver.setMaxActive(poolSize); return driver; }
From source file:de.langmi.spring.batch.examples.readers.support.CompositeCursorItemReaderTest.java
/** * Create a HSQLDB in-memory based datasource. * * @param url//from ww w . j av a 2 s.c o m * @return */ private DataSource createDataSource(final String url) { // DataSource Setup with apache commons BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); dataSource.setUrl(url); dataSource.setUsername("sa"); dataSource.setPassword(""); return dataSource; }
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;/*from w w w . ja va2 s .c o m*/ }
From source file:cz.muni.fi.pv168.dressroomAppGui.MainMenuFrame.java
public static DataSource prepareDataSource() throws SQLException { BasicDataSource dataSource = new BasicDataSource(); //dataSource.setUrl("jdbc:derby:memory:dressroom-gui;create=true"); dataSource.setUrl(/*ww w .j a v a2 s . co m*/ java.util.ResourceBundle.getBundle("cz.muni.fi.pv168.dressroomappgui/settings").getString("url")); dataSource.setUsername( java.util.ResourceBundle.getBundle("cz.muni.fi.pv168.dressroomappgui/settings").getString("user")); dataSource.setPassword(java.util.ResourceBundle.getBundle("cz.muni.fi.pv168.dressroomappgui/settings") .getString("password")); return dataSource; }
From source file:fr.cnes.sitools.datasource.jdbc.business.SitoolsDataSourceFactory.java
/** * Local creation of a DataSource//from w w w . ja v a 2s.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 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; }