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

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

Introduction

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

Prototype

BasicDataSource

Source Link

Usage

From source file:io.syndesis.connector.sql.stored.springboot.DataSourceStartCustomizer.java

@Override
public void customize(SqlStoredStartConnectorComponent component) {
    if (configuration.getDataSource() == null) {
        BasicDataSource ds = new BasicDataSource();
        ObjectHelper.ifNotEmpty(configuration.getUser(), ds::setUsername);
        ObjectHelper.ifNotEmpty(configuration.getPassword(), ds::setPassword);
        ObjectHelper.ifNotEmpty(configuration.getUrl(), ds::setUrl);

        component.addOption("dataSource", ds);
    }//from  w  ww.  j  a v  a 2s  .  c o  m
}

From source file:com.lawulu.bdc.etl.batch.config.DatabaseConfiguration.java

@Bean(destroyMethod = "close")
public DataSource dbcpDataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/test");
    dataSource.setUsername("root");
    dataSource.setPassword("root");
    dataSource.setMaxActive(20);//from ww  w .  ja v a  2s .  c  om
    dataSource.setMaxIdle(20);
    dataSource.setMaxWait(10000);
    dataSource.setInitialSize(5);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    return dataSource;
}

From source file:com.abixen.platform.module.configuration.PlatformModuleDataSourceConfiguration.java

@Profile("dev")
@Bean(destroyMethod = "close")
public DataSource devDataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driverClassName);
    dataSource.setUrl(databaseUrl);//from   w  w  w  . j  av  a2 s .c  o m
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    return dataSource;
}

From source file:com.bt.aloha.sipstone.MaintenanceDao.java

public MaintenanceDao() throws Exception {
    InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("sip.properties");
    Properties dbProps = new Properties();
    dbProps.load(is);//  w w  w.j  a va 2 s.  c o  m
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(dbProps.getProperty("database.driverClassName", "org.postgresql.Driver"));
    ds.setUrl(dbProps.getProperty("database.url", "jdbc:postgresql://localhost:5432/springring"));
    ds.setUsername(dbProps.getProperty("database.username", "springringuser"));
    ds.setPassword(dbProps.getProperty("database.password", "springringuser"));
    this.jdbcTemplate = new JdbcTemplate(ds);
}

From source file:net.slipp.config.MainConfig.java

@Bean(destroyMethod = "close")
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(environment.getProperty("jdbc.driverClassName"));
    dataSource.setUrl(environment.getProperty("jdbc.url"));
    dataSource.setUsername(environment.getProperty("jdbc.username"));
    dataSource.setPassword(environment.getProperty("jdbc.password"));
    return dataSource;
}

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

private synchronized BasicDataSource createConnectionPool() {
    BasicDataSource source;/*from   ww  w  .j a  va 2 s  .c  o  m*/
    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);
    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:com.emergya.utils.DataSourceUtils.java

/**
 * Genera un nuevo data source con las propiedades
 * {@link DataSourceUtils#dataSourceProperties}
 * /*w w w. ja  v a 2  s.com*/
 * @return {@link BasicDataSource}
 */
public DataSource getDataSource() {
    DataSource dataSource = new BasicDataSource();

    // Se escriben las propiedades por reflexion
    for (Object key : dataSourceProperties.keySet()) {
        if (key instanceof String) {
            try {
                String property = (String) key;
                String setter = "set" + property.substring(0, 1).toUpperCase() + property.substring(1);
                Method setterMethod = ReflectionUtils.findMethod(BasicDataSource.class, setter, String.class);
                ReflectionUtils.makeAccessible(setterMethod);
                ReflectionUtils.invokeMethod(setterMethod, dataSource,
                        dataSourceProperties.getProperty(property));
            } catch (Exception e) {
                // Error al poner la propiedad
            }
        }
    }

    return dataSource;
}

From source file:com.gs.obevo.db.impl.core.jdbc.JdbcDataSourceFactory.java

private static DataSource createFromJdbcUrl(Class<? extends Driver> driverClass, String url,
        Credential credential, int numThreads, ImmutableList<String> initSqls,
        Properties extraConnectionProperties) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driverClass.getName());
    dataSource.setUrl(url);//from w  w w  .  ja  v  a  2s .co  m
    dataSource.setUsername(credential.getUsername());
    dataSource.setPassword(credential.getPassword());

    // connection pool settings
    dataSource.setInitialSize(numThreads);
    dataSource.setMaxActive(numThreads);
    // keep the connections open if possible; only close them via the removeAbandonedTimeout feature
    dataSource.setMaxIdle(numThreads);
    dataSource.setMinIdle(0);
    dataSource.setRemoveAbandonedTimeout(300);

    dataSource.setConnectionInitSqls(initSqls.castToList());
    if (extraConnectionProperties != null) {
        for (String key : extraConnectionProperties.stringPropertyNames()) {
            dataSource.addConnectionProperty(key, extraConnectionProperties.getProperty(key));
        }
    }

    return dataSource;
}

From source file:com.alibaba.cobar.manager.dao.delegate.DataSourceCreator.java

@Override
public DataSource createDataSource(String ip, int port, String user, String password) {
    BasicDataSource ds = new BasicDataSource();
    ds.setUsername(user);//from w ww .ja  v  a 2  s. c  o m
    ds.setPassword(password);
    ds.setUrl(new StringBuilder().append("jdbc:mysql://").append(ip).append(":").append(port).append("/")
            .toString());
    ds.setDriverClassName(driverClassName);
    ds.setMaxActive(maxActive);
    ds.setMinIdle(minIdle);
    ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    ds.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    ds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    return ds;
}

From source file:com.esspl.datagen.common.DatabaseSessionManager.java

public void connect(ConnectionProfile profile) throws Exception {
    test(profile.getDriver(), profile.getUrl(), profile.getUser(), profile.getPassword());
    disconnect();//from w w w .j a v  a2 s  . c o m

    dataSource = new BasicDataSource();
    dataSource.setDriverClassName(profile.getDriver());
    dataSource.setUrl(profile.getUrl());
    dataSource.setUsername(profile.getUser());
    dataSource.setPassword(profile.getPassword());

    dataSource.setMaxActive(32);
    dataSource.setMaxIdle(4);
    dataSource.setMaxWait(20 * 1000);
    dataSource.setMaxOpenPreparedStatements(8);

    connectionProfile = profile;
}