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

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

Introduction

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

Prototype

public synchronized void setUrl(String url) 

Source Link

Document

Sets the #url .

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

Usage

From source file:database.DataSourceBase.java

public DataSource initDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(driver);/*from www.j  a va 2  s.com*/
    ds.setUsername(username);
    ds.setPassword(password);
    ds.setUrl(url);
    ds.setMaxActive(maxActive);

    datasource = ds;
    return ds;
}

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);
            dbcp.setUsername(username);//w w w. ja v a  2s .  c  om
            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);
    basicDataSource.setUsername(username);
    basicDataSource.setPassword(password);
    dataSource = basicDataSource;/*  w ww  .  j  a va  2 s  . c  o  m*/
    log.debug("DataSource - " + url);

}

From source file:com.metamx.druid.db.DbConnector.java

private DataSource getDatasource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUsername(config.getDatabaseUser());
    dataSource.setPassword(config.getDatabasePassword());
    dataSource.setUrl(config.getDatabaseConnectURI());

    if (config.useValidationQuery()) {
        dataSource.setValidationQuery(config.getValidationQuery());
        dataSource.setTestOnBorrow(true);
    }/*from w ww .ja  v  a 2s  . c  o  m*/

    return dataSource;
}

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

/**
 * ???./*from w  ww .  ja v a  2 s  .com*/
 *
 * @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: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. 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;
}

From source file:com.musala.testutils.DatabaseTestConfiguration.java

@Bean(name = "dataSource")
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName")));
    dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url")));
    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;//from  w w  w  .ja v  a  2  s  . 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.dangdang.ddframe.job.cloud.executor.TaskExecutor.java

@Override
public void registered(final ExecutorDriver executorDriver, final Protos.ExecutorInfo executorInfo,
        final Protos.FrameworkInfo frameworkInfo, final Protos.SlaveInfo slaveInfo) {
    if (!executorInfo.getData().isEmpty()) {
        Map<String, String> data = SerializationUtils.deserialize(executorInfo.getData().toByteArray());
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName(data.get("event_trace_rdb_driver"));
        dataSource.setUrl(data.get("event_trace_rdb_url"));
        dataSource.setPassword(data.get("event_trace_rdb_password"));
        dataSource.setUsername(data.get("event_trace_rdb_username"));
        jobEventBus = new JobEventBus(new JobEventRdbConfiguration(dataSource));
    }//from  w w w  .j a  va  2s. com
}

From source file:de.siemens.quantarch.bugs.IssueTrackerParser.java

/**
 * Build the database connection//from   w  w w. j a v  a 2s .c o  m
 * 
 * @return
 */
private DataSource buildDataSource() {
    // create the data source for database
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://" + projectConfig.getDbHost() + ":3306/" + projectConfig.getDbName());
    dataSource.setUsername(projectConfig.getDbUser());
    dataSource.setPassword(projectConfig.getDbPassword());
    dataSource.setInitialSize(30);
    return dataSource;
}