Example usage for org.apache.commons.dbcp BasicDataSource setPassword

List of usage examples for org.apache.commons.dbcp BasicDataSource setPassword

Introduction

In this page you can find the example usage for org.apache.commons.dbcp BasicDataSource setPassword.

Prototype

public synchronized void setPassword(String password) 

Source Link

Document

Sets the #password .

Note: this method currently has no effect once the pool has been initialized.

Usage

From source file:org.apigw.monitoring.config.PersistenceConfig.java

@Bean
public DataSource dataSource() {
    log.debug("Setting up datasource for with drive: {}, url: {}, username: {}", driver, url, username);
    BasicDataSource bdc = new BasicDataSource();
    bdc.setUsername(username);//www .j  av  a 2 s  .  c o  m
    bdc.setPassword(password);
    bdc.setUrl(url);
    bdc.setDriverClassName(driver);
    bdc.setValidationQuery(validationQuery);

    return bdc;
}

From source file:org.asimba.wa.integrationtest.server.AsimbaWaDerbyDb.java

private AsimbaWaDerbyDb() {
    String driverClassName = RunConfiguration.getInstance().getProperty("db.driverClass");
    String url = RunConfiguration.getInstance().getProperty("db.connectionString");
    String username = RunConfiguration.getInstance().getProperty("db.username");
    String password = RunConfiguration.getInstance().getProperty("db.password");

    BasicDataSource ds = null;
    ds = new BasicDataSource();
    ds.setDriverClassName(driverClassName);
    ds.setUrl(url);//from   w ww . j a  v  a  2s  .c om
    ds.setUsername(username);
    ds.setPassword(password);

    _datasource = ds;
}

From source file:org.blocks4j.reconf.client.setup.DatabaseManager.java

private BasicDataSource createDataSource(DatabaseURL arg) {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(arg.getDriverClassName());
    ds.setUrl(arg.buildRuntimeURL());//  www.ja  va 2 s.  c o  m
    ds.setUsername(arg.getLogin());
    ds.setPassword(arg.getPass());
    ds.setMaxActive(30);
    ds.setMinIdle(5);
    ds.setTestOnBorrow(true);
    ds.setMaxWait(5000);
    return ds;
}

From source file:org.bpmscript.test.hibernate.SpringSessionFactoryTestSupport.java

public void execute(ITestCallback<IServiceLookup> callback) throws Exception {

    //         final BasicDataSource dataSource = new BasicDataSource();
    //         dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    //         dataSource.setUrl("jdbc:mysql://localhost:3306/bpmscript");
    //         dataSource.setUsername("bpmscript");
    //         dataSource.setPassword("sa");
    //        /* w ww .  jav  a  2  s  . co m*/
    //         Properties properties = new Properties();
    //         properties.setProperty("hibernate.hbm2ddl.auto", "create");
    //         properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
    //         properties.setProperty("hibernate.show_sql", "false");

    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.h2.Driver");
    dataSource.setUrl("jdbc:h2:~/bpmscript");
    dataSource.setUsername("sa");
    dataSource.setPassword("");

    Properties properties = new Properties();
    properties.setProperty("hibernate.hbm2ddl.auto", "create");
    properties.setProperty("hibernate.dialect", H2Dialect.class.getName());
    properties.setProperty("hibernate.show_sql", "false");

    //        final BasicDataSource dataSource = new BasicDataSource();
    //        dataSource.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
    //        dataSource.setUrl("jdbc:derby:test;create=true");
    //        dataSource.setUsername("sa");
    //        dataSource.setPassword("sa");
    //
    //        Properties properties = new Properties();
    //        properties.setProperty("hibernate.hbm2ddl.auto", "update");
    //        properties.setProperty("hibernate.dialect", "org.hibernate.dialect.DerbyDialect");
    //        properties.setProperty("hibernate.query.substitutions", "true 1, false 0");
    //        properties.setProperty("hibernate.show_sql", "false");

    ServiceLookup lookup = new ServiceLookup();
    final AnnotationSessionFactoryBean sessionFactoryBean = new AnnotationSessionFactoryBean();
    sessionFactoryBean.setLobHandler(new DefaultLobHandler());
    sessionFactoryBean.setHibernateProperties(properties);
    sessionFactoryBean.setAnnotatedClasses(classes);
    sessionFactoryBean.setDataSource(dataSource);
    sessionFactoryBean.afterPropertiesSet();

    SessionFactory sessionFactory = (SessionFactory) sessionFactoryBean.getObject();
    lookup.addService("sessionFactory", sessionFactory);

    try {
        callback.execute(lookup);
    } finally {
        sessionFactory.close();
        sessionFactoryBean.destroy();
    }
}

From source file:org.bzewdu.tools.perftrend.data.oracledalHelper.java

/**
 *
 * @param connectURI//ww w.j a  v a  2s.c o m
 * @return
 */
public static DataSource setupDataSource(final String connectURI) {
    final BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
    ds.setUsername(oracledalHelper.username);
    ds.setPassword(oracledalHelper.passwd);
    ds.setUrl(connectURI);
    return ds;
}

From source file:org.cambillaum.jpapersistor.persistence.configuration.PersistenceConfiguration.java

@Bean
public BasicDataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    dataSource.setUrl("jdbc:hsqldb:mem:testdb");
    dataSource.setUsername("sa");
    dataSource.setPassword("");
    dataSource.setInitialSize(0);//from   w  w  w  . j  a v  a2 s .  c  o m
    dataSource.setMaxActive(15);
    dataSource.setMaxIdle(0);
    dataSource.setMinEvictableIdleTimeMillis(60000);
    return dataSource;
}

From source file:org.cbioportal.database.annotator.DataSourceConfiguration.java

public BasicDataSource dataSource() throws SQLException {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUsername(username);/*from ww  w  .j  av a 2  s . c o m*/
    dataSource.setPassword(password);
    dataSource.setDriverClassName(driver);
    dataSource.setUrl(connection_string);
    return dataSource;
}

From source file:org.compass.core.lucene.engine.store.jdbc.DbcpDataSourceProvider.java

protected DataSource doCreateDataSource(String url, CompassSettings settings) throws CompassException {
    BasicDataSource dataSource = new BasicDataSource();
    if (!externalAutoCommit) {
        dataSource.setDefaultAutoCommit(autoCommit);
    }//w w w .  j a  va2 s .  c  om
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(url);
    dataSource.setUsername(username);
    dataSource.setPassword(password);

    if (settings.getSetting(
            LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.DEFAULT_TRANSACTION_ISOLATION) != null) {
        dataSource.setDefaultTransactionIsolation(settings.getSettingAsInt(
                LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.DEFAULT_TRANSACTION_ISOLATION, 0));
    }

    if (settings.getSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.INITIAL_SIZE) != null) {
        dataSource.setInitialSize(
                settings.getSettingAsInt(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.INITIAL_SIZE, 0));
    }

    if (settings.getSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_ACTIVE) != null) {
        dataSource.setMaxActive(
                settings.getSettingAsInt(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_ACTIVE, 0));
    }

    if (settings.getSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_IDLE) != null) {
        dataSource.setMaxIdle(
                settings.getSettingAsInt(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_IDLE, 0));
    }

    if (settings.getSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MIN_IDLE) != null) {
        dataSource.setMinIdle(
                settings.getSettingAsInt(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MIN_IDLE, 0));
    }

    if (settings.getSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_WAIT) != null) {
        dataSource.setMaxWait(
                settings.getSettingAsLong(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_WAIT, 0));
    }

    if (settings.getSetting(
            LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_OPEN_PREPARED_STATEMENTS) != null) {
        dataSource.setMaxOpenPreparedStatements(settings.getSettingAsInt(
                LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_OPEN_PREPARED_STATEMENTS, 0));
    }

    if (settings
            .getSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.POOL_PREPARED_STATEMENTS) != null) {
        dataSource.setPoolPreparedStatements(settings.getSettingAsBoolean(
                LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.POOL_PREPARED_STATEMENTS, false));
    }

    return dataSource;
}

From source file:org.danann.cernunnos.sql.BasicDataSourceTemplate.java

public final void perform(TaskRequest req, TaskResponse res) {
    //Get the JDBC properties
    final String driverClassName = (String) this.driverPhrase.evaluate(req, res);
    final String url = (String) this.urlPhrase.evaluate(req, res);
    final String username = (String) this.usernamePhrase.evaluate(req, res);
    final String password = (String) this.passwordPhrase.evaluate(req, res);

    final String dataSourceInfo = "driverClassName='" + driverClassName + "', url='" + url + "', username='"
            + username + "'";
    this.logger.debug("Creating DataSource for " + dataSourceInfo + ".");

    final BasicDataSource dataSource = new BasicDataSource();
    try {//from w  w w  .  j  a  v  a  2  s.c  o  m
        //Configure the pooling DataSource
        dataSource.setUrl(url);
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        dataSource.setPoolPreparedStatements(true);
        dataSource.setMaxActive(-1);
        dataSource.setMaxIdle(32);

        //Provide the DataSource on the response environment
        final String dataSourceAttrName = (String) this.attributeNamePhrase.evaluate(req, res);
        res.setAttribute(dataSourceAttrName, dataSource);
        this.logger.debug("Attached DataSource '" + dataSource + "' for " + dataSourceInfo
                + " to response under attribute '" + dataSourceAttrName + "'.");

        //Execute subtasks
        this.performWithDataSource(req, res, dataSource);
    } finally {
        try {
            //Cleanup after the subtasks
            dataSource.close();
            this.logger.debug("Closed DataSource '" + dataSource + "' for " + dataSourceInfo + ".");
        } catch (SQLException e) {
            throw new RuntimeException(
                    "Failed to close BasicDataSource '" + dataSource + "' for " + dataSourceInfo + ".", e);
        }
    }
}

From source file:org.datacleaner.connection.JdbcDatastore.java

public DataSource createDataSource() {
    initializeDriver();/*from  w  w  w.jav a 2 s. c o m*/

    BasicDataSource ds = new BasicDataSource();
    ds.setDefaultAutoCommit(false);
    ds.setUrl(_jdbcUrl);

    ds.setMaxActive(getSystemPropertyValue(SYSTEM_PROPERTY_CONNECTION_POOL_MAX_SIZE, -1));
    ds.setMinEvictableIdleTimeMillis(
            getSystemPropertyValue(SYSTEM_PROPERTY_CONNECTION_POOL_MIN_EVICTABLE_IDLE_TIME_MILLIS, 500));
    ds.setTimeBetweenEvictionRunsMillis(
            getSystemPropertyValue(SYSTEM_PROPERTY_CONNECTION_POOL_TIME_BETWEEN_EVICTION_RUNS_MILLIS, 1000));

    if (_username != null && _password != null) {
        ds.setUsername(_username);
        ds.setPassword(_password);
    }
    return ds;
}