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;
}
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;
}
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;
}
Aggregations