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:com.openteach.diamond.repository.client.impl.database.DataSourceFactory.java

/**
 * // w  w  w .ja  v a 2  s  . c  om
 * @return
 */
public DataSource newInstance() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDefaultAutoCommit(true);
    dataSource.setDriverClassName(certificate.getDriverClassName());
    dataSource.setMaxActive(certificate.getMaxActive());
    dataSource.setMaxIdle(certificate.getMaxIdle());
    dataSource.setMaxWait(certificate.getMaxWait());
    dataSource.setMinIdle(certificate.getMinIdle());
    dataSource.setUsername(certificate.getUsername());
    dataSource.setPassword(certificate.getPassword());
    dataSource.setUrl(certificate.getUrl());
    return dataSource;
}

From source file:be.ugent.tiwi.sleroux.newsrec.newsreclib.dao.mysqlImpl.AbstractJDBCBaseDao.java

private synchronized BasicDataSource createConnectionPool() {
    BasicDataSource source;
    logger.debug("creating connectionpool");
    String driver = bundle.getString("dbDriver");
    String user = bundle.getString("dbUser");
    String pass = bundle.getString("dbPass");
    String url = bundle.getString("dbUrl");
    url = url + "?user=" + user + "&password=" + pass;
    source = new BasicDataSource();
    source.setDriverClassName(driver);/*from w w  w  .  ja  v a  2s  .c om*/
    source.setUsername(user);
    source.setPassword(pass);
    source.setUrl(url);
    source.setTestOnReturn(true);
    source.setValidationQuery("SELECT 1");
    logger.debug("connectionpool created");
    return source;
}

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(//from ww  w. j av a 2 s  . com
            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:com.googlesource.gerrit.plugins.verifystatus.server.schema.CiDataSourceProvider.java

private DataSource open(Context context, CiDataSourceType dst) {
    // ConfigSection dbs = new ConfigSection(cfg, "database");
    String driver = config.getString("driver");
    if (Strings.isNullOrEmpty(driver)) {
        driver = dst.getDriver();/*from  ww w.j  ava2  s  . c o m*/
    }

    String url = config.getString("dbUrl");
    if (Strings.isNullOrEmpty(url)) {
        url = dst.getUrl();
    }

    String username = config.getString("username");
    String password = config.getString("password");
    String interceptor = config.getString("dataSourceInterceptorClass");

    boolean usePool;
    if (context == Context.SINGLE_USER) {
        usePool = false;
    } else {
        usePool = config.getBoolean("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(config.getInt("poollimit", DEFAULT_POOL_LIMIT));
        ds.setMinIdle(config.getInt("poolminidle", 4));
        ds.setMaxIdle(config.getInt("poolmaxidle", 4));
        String valueString = config.getString("poolmaxwait");
        if (Strings.isNullOrEmpty(valueString)) {
            ds.setMaxWait(MILLISECONDS.convert(30, SECONDS));
        } else {
            ds.setMaxWait(ConfigUtil.getTimeUnit(valueString, MILLISECONDS.convert(30, SECONDS), MILLISECONDS));
        }
        ds.setInitialSize(ds.getMinIdle());
        exportPoolMetrics(ds);
        return intercept(interceptor, ds);
    }
    // Don't use the connection pool.
    try {
        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 intercept(interceptor, new SimpleDataSource(p));
    } catch (SQLException se) {
        throw new ProvisionException("Database unavailable", se);
    }
}

From source file:com.test.HibernateDerbyLockingTest.java

public void testSpringWithDataSource() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(EmbeddedDriver.class.getName());
    dataSource.setUrl("jdbc:derby:lockingtest;create=true");
    dataSource.setUsername("sa");
    dataSource.setPassword("sa");

    Properties properties = new Properties();
    properties.setProperty("hibernate.hbm2ddl.auto", "create");
    properties.setProperty("hibernate.dialect", "org.bpmscript.hibernate.DerbyDialect");
    properties.setProperty("hibernate.show_sql", "true");

    // properties.setProperty("hibernate.connection.driver_class",
    // EmbeddedDriver.class.getName());
    // properties.setProperty("hibernate.connection.url",
    // "jdbc:derby:lockingtest;create=true");
    // properties.setProperty("hibernate.connection.username", "sa");
    // properties.setProperty("hibernate.connection.password", "sa");
    // properties.setProperty("hibernate.connection.pool_size", "10");

    final AnnotationSessionFactoryBean sessionFactoryBean = new AnnotationSessionFactoryBean();
    sessionFactoryBean.setLobHandler(new DefaultLobHandler());
    sessionFactoryBean.setHibernateProperties(properties);
    sessionFactoryBean.setAnnotatedClasses(new Class[] { Person.class });
    sessionFactoryBean.setDataSource(dataSource);
    sessionFactoryBean.afterPropertiesSet();

    SessionFactory sessionFactory = (SessionFactory) sessionFactoryBean.getObject();
    try {/* w  w w.jav a 2s  .co m*/
        runTest(sessionFactory);
    } finally {
        sessionFactory.close();
    }
}

From source file:com.uber.hoodie.hive.client.HoodieHiveClient.java

private DataSource getDatasource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(driverName);//w  w w.  j  a  v  a2s. co m
    ds.setUrl(getHiveJdbcUrlWithDefaultDBName());
    ds.setUsername(configuration.getHiveUsername());
    ds.setPassword(configuration.getHivePassword());
    return ds;
}

From source file:com.googlesource.gerrit.plugins.ci.server.schema.CiDataSourceProvider.java

private DataSource open(Context context, CiDataSourceType dst) {
    //ConfigSection dbs = new ConfigSection(cfg, "database");
    String driver = config.getString("driver");
    if (Strings.isNullOrEmpty(driver)) {
        driver = dst.getDriver();/*from   w  w w.  ja va  2 s.c om*/
    }

    String url = config.getString("dbUrl");
    if (Strings.isNullOrEmpty(url)) {
        url = dst.getUrl();
    }

    String username = config.getString("username");
    String password = config.getString("password");
    String interceptor = config.getString("dataSourceInterceptorClass");

    boolean usePool;
    if (context == Context.SINGLE_USER) {
        usePool = false;
    } else {
        usePool = config.getBoolean("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(config.getInt("poollimit", DEFAULT_POOL_LIMIT));
        ds.setMinIdle(config.getInt("poolminidle", 4));
        ds.setMaxIdle(config.getInt("poolmaxidle", 4));
        String valueString = config.getString("poolmaxwait");
        if (Strings.isNullOrEmpty(valueString)) {
            ds.setMaxWait(MILLISECONDS.convert(30, SECONDS));
        } else {
            ds.setMaxWait(ConfigUtil.getTimeUnit(valueString, MILLISECONDS.convert(30, SECONDS), MILLISECONDS));
        }
        ds.setInitialSize(ds.getMinIdle());
        exportPoolMetrics(ds);
        return intercept(interceptor, ds);
    } else {
        // Don't use the connection pool.
        //
        try {
            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 intercept(interceptor, new SimpleDataSource(p));
        } catch (SQLException se) {
            throw new ProvisionException("Database unavailable", se);
        }
    }
}

From source file:com.bstek.dorado.core.store.SqlBaseStoreSupport.java

protected synchronized DataSource getDataSource() throws Exception {
    if (dataSource != null) {
        return dataSource;
    }//from   ww  w  .j  a  v  a  2 s.c o  m

    if (StringUtils.isBlank(namespace)) {
        throw new IllegalArgumentException("The namespace of store cannot be empty. ");
    }

    prepareNamespace();

    BasicDataSource pds = new BasicDataSource();
    dataSource = pds;

    pds.setDriverClassName(driverClassName);
    pds.setUrl(getConnectionUrl());
    pds.setUsername(username);
    pds.setPassword(password);
    pds.setDefaultCatalog(defaultCatalog);

    if (defaultAutoCommit != null) {
        pds.setDefaultAutoCommit(defaultAutoCommit.booleanValue());
    }
    if (defaultReadOnly != null) {
        pds.setDefaultReadOnly(defaultReadOnly.booleanValue());
    }
    if (defaultTransactionIsolation != null) {
        pds.setDefaultTransactionIsolation(defaultTransactionIsolation.intValue());
    }
    if (maxActive != null) {
        pds.setMaxActive(maxActive.intValue());
    }
    if (maxIdle != null) {
        pds.setMaxIdle(maxIdle.intValue());
    }
    if (minIdle != null) {
        pds.setMinIdle(minIdle.intValue());
    }
    if (initialSize != null) {
        pds.setInitialSize(initialSize.intValue());
    }
    if (maxWait != null) {
        pds.setMaxWait(maxWait.longValue());
    }
    if (timeBetweenEvictionRunsMillis != null) {
        pds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis.longValue());
    }
    if (minEvictableIdleTimeMillis != null) {
        pds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis.longValue());
    }
    return dataSource;
}

From source file:net.jetrix.DataSourceManager.java

/**
 * Configure a datasource./*from w w  w . j a  va2 s .  com*/
 *
 * @param config      the configuration of the datasource
 * @param environment the environment of the datasource
 */
public void setDataSource(DataSourceConfig config, String environment) {
    try {
        Class.forName(config.getDriver());
    } catch (ClassNotFoundException e) {
        log.warning("Unable to find the database driver (" + config.getDriver()
                + "), put the related jar in the lib directory");
        return;
    }

    try {
        // close the previous datasource if necessary
        if (datasources.containsKey(environment)) {
            BasicDataSource datasource = (BasicDataSource) datasources.get(environment);
            datasource.close();
        }

        BasicDataSource datasource = new BasicDataSource();
        datasource.setDefaultAutoCommit(false);

        datasource.setDriverClassName(config.getDriver());
        datasource.setUrl(config.getUrl());
        datasource.setUsername(config.getUsername());
        datasource.setPassword(config.getPassword());
        datasource.setMinIdle(config.getMinIdle() != 0 ? config.getMinIdle() : DEFAULT_MIN_IDLE);
        datasource.setMaxActive(config.getMaxActive() != 0 ? config.getMaxActive() : DEFAULT_MAX_ACTIVE);

        // attempts to open the connection
        datasource.getConnection().close();

        datasources.put(environment, datasource);
    } catch (Exception e) {
        log.log(Level.SEVERE, "Unable to configure the datasource '" + environment + "'", e);
    }
}

From source file:com.alibaba.druid.benckmark.pool.Oracle_Case3.java

public void test_1() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setMaxActive(maxActive);/*from  w  w  w  . jav a  2 s.  co m*/
    dataSource.setMaxIdle(maxIdle);
    dataSource.setMaxWait(maxWait);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(testOnBorrow);

    for (int i = 0; i < loopCount; ++i) {
        p0(dataSource, "dbcp", threadCount);
    }
    System.out.println();
}