Search in sources :

Example 21 with ComboPooledDataSource

use of com.mchange.v2.c3p0.ComboPooledDataSource in project adempiere by adempiere.

the class DB_MariaDB method getDataSource.

/**
	 * Create DataSource (Client)
	 * 
	 * @param connection connection
	 * @return data source
	 */
public DataSource getDataSource(CConnection connection) {
    if (m_ds != null)
        return m_ds;
    try {
        System.setProperty("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
        // System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL",
        // "ALL");
        ComboPooledDataSource cpds = new ComboPooledDataSource();
        cpds.setDataSourceName("AdempiereDS");
        cpds.setDriverClass(DRIVER);
        // loads the jdbc driver
        cpds.setJdbcUrl(getConnectionURL(connection));
        cpds.setUser(connection.getDbUid());
        cpds.setPassword(connection.getDbPwd());
        cpds.setPreferredTestQuery(DEFAULT_CONN_TEST_SQL);
        cpds.setIdleConnectionTestPeriod(1200);
        // cpds.setTestConnectionOnCheckin(true);
        // cpds.setTestConnectionOnCheckout(true);
        cpds.setAcquireRetryAttempts(2);
        if (Ini.isClient()) {
            cpds.setInitialPoolSize(1);
            cpds.setMinPoolSize(1);
            cpds.setMaxPoolSize(15);
            cpds.setMaxIdleTimeExcessConnections(1200);
            cpds.setMaxIdleTime(900);
            m_maxbusyconnections = 10;
        } else {
            cpds.setInitialPoolSize(10);
            cpds.setMinPoolSize(5);
            cpds.setMaxPoolSize(150);
            cpds.setMaxIdleTimeExcessConnections(1200);
            cpds.setMaxIdleTime(1200);
            m_maxbusyconnections = 120;
        }
        // the following sometimes kill active connection!
        // cpds.setUnreturnedConnectionTimeout(1200);
        // cpds.setDebugUnreturnedConnectionStackTraces(true);
        m_ds = cpds;
    } catch (Exception ex) {
        m_ds = null;
        log.log(Level.SEVERE, "Could not initialise C3P0 Datasource", ex);
    }
    return m_ds;
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) SQLException(java.sql.SQLException)

Example 22 with ComboPooledDataSource

use of com.mchange.v2.c3p0.ComboPooledDataSource in project adempiere by adempiere.

the class DB_MySQL method getDataSource.

/**
	 * Create DataSource (Client)
	 * 
	 * @param connection connection
	 * @return data source
	 */
public DataSource getDataSource(CConnection connection) {
    if (m_ds != null)
        return m_ds;
    try {
        System.setProperty("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
        // System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL",
        // "ALL");
        ComboPooledDataSource cpds = new ComboPooledDataSource();
        cpds.setDataSourceName("AdempiereDS");
        cpds.setDriverClass(DRIVER);
        // loads the jdbc driver
        cpds.setJdbcUrl(getConnectionURL(connection));
        cpds.setUser(connection.getDbUid());
        cpds.setPassword(connection.getDbPwd());
        cpds.setPreferredTestQuery(DEFAULT_CONN_TEST_SQL);
        cpds.setIdleConnectionTestPeriod(1200);
        // cpds.setTestConnectionOnCheckin(true);
        // cpds.setTestConnectionOnCheckout(true);
        cpds.setAcquireRetryAttempts(2);
        if (Ini.isClient()) {
            cpds.setInitialPoolSize(1);
            cpds.setMinPoolSize(1);
            cpds.setMaxPoolSize(15);
            cpds.setMaxIdleTimeExcessConnections(1200);
            cpds.setMaxIdleTime(900);
            m_maxbusyconnections = 10;
        } else {
            cpds.setInitialPoolSize(10);
            cpds.setMinPoolSize(5);
            cpds.setMaxPoolSize(150);
            cpds.setMaxIdleTimeExcessConnections(1200);
            cpds.setMaxIdleTime(1200);
            m_maxbusyconnections = 120;
        }
        // the following sometimes kill active connection!
        // cpds.setUnreturnedConnectionTimeout(1200);
        // cpds.setDebugUnreturnedConnectionStackTraces(true);
        m_ds = cpds;
    } catch (Exception ex) {
        m_ds = null;
        log.log(Level.SEVERE, "Could not initialise C3P0 Datasource", ex);
    }
    return m_ds;
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) SQLException(java.sql.SQLException)

Example 23 with ComboPooledDataSource

use of com.mchange.v2.c3p0.ComboPooledDataSource in project dhis2-core by dhis2.

the class DefaultDataSourceManager method getReadOnlyDataSources.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private List<DataSource> getReadOnlyDataSources() {
    String mainUser = config.getProperty(ConfigurationKey.CONNECTION_USERNAME);
    String mainPassword = config.getProperty(ConfigurationKey.CONNECTION_PASSWORD);
    String driverClass = config.getProperty(CONNECTION_DRIVER_CLASS);
    String maxPoolSize = config.getPropertyOrDefault(CONNECTION_POOL_MAX_SIZE, DEFAULT_POOL_SIZE);
    Properties props = config.getProperties();
    List<DataSource> dataSources = new ArrayList<>();
    for (int i = 1; i <= MAX_READ_REPLICAS; i++) {
        String jdbcUrl = props.getProperty(String.format(FORMAT_CONNECTION_URL, i));
        String user = props.getProperty(String.format(FORMAT_CONNECTION_USERNAME, i));
        String password = props.getProperty(String.format(FORMAT_CONNECTION_PASSWORD, i));
        user = StringUtils.defaultIfEmpty(user, mainUser);
        password = StringUtils.defaultIfEmpty(password, mainPassword);
        if (ObjectUtils.allNonNull(jdbcUrl, user, password)) {
            try {
                ComboPooledDataSource ds = new ComboPooledDataSource();
                ds.setDriverClass(driverClass);
                ds.setJdbcUrl(jdbcUrl);
                ds.setUser(user);
                ds.setPassword(password);
                ds.setMaxPoolSize(Integer.valueOf(maxPoolSize));
                ds.setAcquireIncrement(VAL_ACQUIRE_INCREMENT);
                ds.setMaxIdleTime(VAL_MAX_IDLE_TIME);
                dataSources.add(ds);
                log.info("Found read replica, connection URL: " + jdbcUrl);
            } catch (PropertyVetoException ex) {
                throw new IllegalArgumentException("Invalid configuration of read replica: " + jdbcUrl, ex);
            }
        }
    }
    log.info("Read only configuration initialized, read replicas found: " + dataSources.size());
    return dataSources;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) ArrayList(java.util.ArrayList) Properties(java.util.Properties) ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) DataSource(javax.sql.DataSource)

Aggregations

ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)23 SQLException (java.sql.SQLException)6 PropertyVetoException (java.beans.PropertyVetoException)4 Properties (java.util.Properties)3 ArrayList (java.util.ArrayList)2 DataSource (javax.sql.DataSource)2 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 MidPointConnectionCustomizer (com.evolveum.midpoint.repo.sql.util.MidPointConnectionCustomizer)1 MidPointConnectionTester (com.evolveum.midpoint.repo.sql.util.MidPointConnectionTester)1 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 BoneCPConfig (com.jolbox.bonecp.BoneCPConfig)1 BoneCPDataSource (com.jolbox.bonecp.BoneCPDataSource)1 DatabusException (com.linkedin.databus2.core.DatabusException)1 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 CallableStatement (java.sql.CallableStatement)1 Connection (java.sql.Connection)1