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

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

Introduction

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

Prototype

public synchronized void setUsername(String username) 

Source Link

Document

Sets the #username .

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

Usage

From source file:architecture.ee.jdbc.datasource.DefaultDataSourceFactory.java

public DataSource getDataSource() {

    String profileTag = "database." + profileName;

    ApplicationProperties config = repository.getSetupApplicationProperties();
    Collection<String> dataSourceProviders = config.getChildrenNames(profileTag);

    log.debug(CommonLogLocalizer.format("003040", profileName));

    if (dataSourceProviders.size() == 0)
        throw new RuntimeError(CommonLogLocalizer.format("003041", profileName));

    for (String dataSourceProvider : dataSourceProviders) {
        String providerTag = profileTag + "." + dataSourceProvider;
        if ("jndiDataSourceProvider".equals(dataSourceProvider)) {
            String jndiNameTag = providerTag + ".jndiName";
            String jndiName = config.get(jndiNameTag + ".jndiName");

            Assert.hasText(jndiName, CommonLogLocalizer.getMessage("003042"));

            JndiDataSourceLookup lookup = new JndiDataSourceLookup();
            return lookup.getDataSource(jndiName);

        } else if ("pooledDataSourceProvider".equals(dataSourceProvider)) {

            String driverClassName = config.get(providerTag + ".driverClassName");
            String url = config.get(providerTag + ".url");
            String username = config.get(providerTag + ".username");
            String password = config.get(providerTag + ".password");

            log.debug(CommonLogLocalizer.format("003043", driverClassName, url));

            org.apache.commons.dbcp.BasicDataSource dbcp = new org.apache.commons.dbcp.BasicDataSource();

            dbcp.setDriverClassName(driverClassName);
            dbcp.setUrl(url);/*  w  w w  . j  a  va2  s.  c o  m*/
            dbcp.setUsername(username);
            dbcp.setPassword(password);
            String propertiesTag = providerTag + ".connectionProperties";
            for (String name : config.getChildrenNames(propertiesTag)) {
                String value = config.get(propertiesTag + "." + name);
                log.debug(CommonLogLocalizer.format("003044", name, value));
                dbcp.addConnectionProperty(name, value);
            }
            return dbcp;
        }
    }
    return null;
}

From source file:net.kamhon.ieagle.dao.DynamicDataSource.java

private void initBasicDataSource() {

    BasicDataSource basicDataSource = new org.apache.commons.dbcp.BasicDataSource();
    basicDataSource.setDriverClassName(driverClassName);
    basicDataSource.setUrl(url);/*w ww.  j  a v  a2s  .  c om*/
    basicDataSource.setUsername(username);
    basicDataSource.setPassword(password);
    dataSource = basicDataSource;
    log.debug("DataSource - " + url);

}

From source file:com.dangdang.ddframe.rdb.sharding.spring.AbstractSpringDBUnitTest.java

private DataSource createDataSource(final String dataSetFile) {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(org.h2.Driver.class.getName());
    result.setUrl(String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL",
            getFileName(dataSetFile)));//from   w w  w .j a v  a 2 s  .c  o m
    result.setUsername("sa");
    result.setPassword("");
    result.setMaxActive(100);
    return result;
}

From source file:com.mycompany.cputauctionnew.app.config.ConnectionConfig.java

@Bean
public DataSource dataSource() {
    BasicDataSource ds = new org.apache.commons.dbcp.BasicDataSource();
    ds.setDriverClassName("org.apache.derby.jdbc.ClientDriver");
    ds.setUrl("jdbc:derby://localhost:1527/sample");
    //ds.setUsername("Jean-Paul");
    //ds.setPassword("password");
    ds.setUsername("app");
    ds.setPassword("app");

    return ds;/*from   www  .j a va2 s . co m*/
}

From source file:com.otterca.persistence.dao.H2Configuration.java

/**
 * Get dataSource for H2 database.//w  w  w. j  a  v  a  2  s . c o m
 * 
 * @return
 */
@Bean
public DataSource getDataSource() {
    if (dataSource == null) {
        synchronized (this) {
            if (dataSource == null) {
                BasicDataSource ds = new BasicDataSource();
                ds.setDriverClassName(bundle.getString("driverClassName"));
                ds.setUrl(bundle.getString("url"));
                ds.setUsername(bundle.getString("username"));
                BasicTextEncryptor encryptor = new BasicTextEncryptor();
                encryptor.setPassword(masterkey.getString("master.password"));
                ds.setPassword(encryptor.decrypt(bundle.getString("password")));
                ds.setValidationQuery(bundle.getString("validationQuery"));
                dataSource = ds;
            }
        }
    }
    return dataSource;
}

From source file:com.dangdang.ddframe.job.cloud.scheduler.boot.env.BootstrapEnvironment.java

/**
 * ???.// w  w w  .ja va2s  . c  om
 *
 * @return ??
 */
public Optional<JobEventRdbConfiguration> getJobEventRdbConfiguration() {
    String driver = getValue(EnvironmentArgument.EVENT_TRACE_RDB_DRIVER);
    String url = getValue(EnvironmentArgument.EVENT_TRACE_RDB_URL);
    String username = getValue(EnvironmentArgument.EVENT_TRACE_RDB_USERNAME);
    String password = getValue(EnvironmentArgument.EVENT_TRACE_RDB_PASSWORD);
    if (!Strings.isNullOrEmpty(driver) && !Strings.isNullOrEmpty(url) && !Strings.isNullOrEmpty(username)) {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName(driver);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return Optional.of(new JobEventRdbConfiguration(dataSource));
    }
    return Optional.absent();
}

From source file:cn.cuizuoli.gotour.config.DataSourceConfig.java

@Bean
public DataSource userDataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(env.getRequiredProperty("user.jdbc.driverClassName"));
    dataSource.setUrl(env.getRequiredProperty("user.jdbc.url"));
    dataSource.setUsername(env.getRequiredProperty("user.jdbc.username"));
    dataSource.setPassword(env.getRequiredProperty("user.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: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:de.iteratec.iteraplan.businesslogic.service.DataSourceServiceImpl.java

/** {@inheritDoc} */
public void initializeDBwithKey(String key) {
    DataSource dataSource = validateKey(key);
    if (dataSource == null) {
        // The key points to the MASTER data source. Nothing todo.
        return;//  www . ja v  a2s . c o m
    }

    // Validation succeeded.
    // Add the data source only if it is not contained already.
    if (!routingDataSource.isKeyContained(key)) {

        // Create a basic data source.
        BasicDataSource ds = new CachableBasicDataSource();
        ds.setDriverClassName(dataSource.getDriver());
        ds.setUrl(dataSource.getUrl());
        ds.setUsername(dataSource.getUser());
        ds.setPassword(dataSource.getPassword());
        ds.setDefaultAutoCommit(false);

        String validationQuery = IteraplanProperties.getProperties()
                .getProperty(IteraplanProperties.DATABASE_VALIDATIONQUERY);
        ds.setValidationQuery(validationQuery);
        ds.setTestOnBorrow(true);
        // basicDataSource.setMaxActive(5);
        // basicDataSource.setMinIdle(1);

        routingDataSource.addCachableBasicDataSource(key, ds);
    }
}

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   ww  w  . j a v a 2  s.co m*/
 *
 * @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;
}