use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project databus by linkedin.
the class MysqlMaxSCNHandler method create.
public static MysqlMaxSCNHandler create(StaticConfig config) throws DatabusException {
ComboPooledDataSource cpds = createConnectionPool(config);
MysqlMaxSCNHandler handler = new MysqlMaxSCNHandler(config, cpds);
handler.loadInitialValue(cpds);
return handler;
}
use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project musiccabinet by hakko.
the class JdbcDatabaseAdministrationDao method parseJDBCURL.
/*
* We know for sure that the DataSource is a ComboPooledDataSource,
* since we specified it in applicationContext.xml.
*
* Use that fact to parse host name and port number out of jdbc url,
* which is on form jdbc:postgresql://localhost:5432/musiccabinet.
*/
private void parseJDBCURL() {
ComboPooledDataSource ds = getDataSource();
String url = ds.getJdbcUrl();
int i1 = url.indexOf("://") + 3;
int i2 = url.indexOf(":", i1);
int i3 = url.indexOf("/", i2);
host = url.substring(i1, i2);
port = toInt(url.substring(i2 + 1, i3));
database = url.substring(i3 + 1);
}
use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project musiccabinet by hakko.
the class JdbcDatabaseAdministrationDao method forcePasswordUpdate.
@Override
public void forcePasswordUpdate(String password) throws ApplicationException {
// we know it's ComboPooledDataSource, as we define it in applicationContext.xml
// this is the primary reason for using C3P0 rather than Apache DBCP, since it
// doesn't support password updates.
ComboPooledDataSource dataSource = getDataSource();
ComboPooledDataSource initialDataSource = (ComboPooledDataSource) initialJdbcTemplate.getDataSource();
dataSource.setPassword(password);
initialDataSource.setPassword(password);
try {
dataSource.softResetDefaultUser();
initialDataSource.softResetDefaultUser();
} catch (SQLException e) {
throw new ApplicationException("Password update failed!", e);
}
try {
initialJdbcTemplate.execute("select 1");
} catch (DataAccessException e) {
throw new ApplicationException("Password update failed!", e);
}
}
use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project Asqatasun by Asqatasun.
the class PersistenceCommonConfig method setUpComboPooledDataSource.
/**
* @param url
* @param username
* @param password
* @return
* @throws PropertyVetoException
*/
public DataSource setUpComboPooledDataSource(String url, String username, String password) throws PropertyVetoException {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setDriverClass(PersistenceCommonConfig.getDriverClassNameFromUrl(url));
dataSource.setUser(username);
dataSource.setPassword(password);
dataSource.setJdbcUrl(url);
dataSource.setIdleConnectionTestPeriod(idleConnectionTestPeriod);
dataSource.setInitialPoolSize(initialPoolSize);
dataSource.setMaxPoolSize(maxPoolSize);
dataSource.setMinPoolSize(minPoolSize);
dataSource.setAcquireIncrement(acquireIncrement);
dataSource.setDebugUnreturnedConnectionStackTraces(true);
return dataSource;
}
use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project dhis2-core by dhis2.
the class DatabasePoolUtils method createC3p0DbPool.
public static DataSource createC3p0DbPool(PoolConfig config) throws PropertyVetoException, SQLException {
DhisConfigurationProvider dhisConfig = config.getDhisConfig();
final String driverClassName = dhisConfig.getProperty(ConfigurationKey.CONNECTION_DRIVER_CLASS);
final String jdbcUrl = MoreObjects.firstNonNull(config.getJdbcUrl(), dhisConfig.getProperty(ConfigurationKey.CONNECTION_URL));
final String username = MoreObjects.firstNonNull(config.getUsername(), dhisConfig.getProperty(ConfigurationKey.CONNECTION_USERNAME));
final String password = MoreObjects.firstNonNull(config.getPassword(), dhisConfig.getProperty(ConfigurationKey.CONNECTION_PASSWORD));
final int maxPoolSize = Integer.parseInt(MoreObjects.firstNonNull(config.getMaxPoolSize(), dhisConfig.getProperty(ConfigurationKey.CONNECTION_POOL_MAX_SIZE)));
final int acquireIncrement = Integer.parseInt(MoreObjects.firstNonNull(config.getAcquireIncrement(), dhisConfig.getProperty(ConfigurationKey.CONNECTION_POOL_ACQUIRE_INCR)));
final int maxIdleTime = Integer.parseInt(MoreObjects.firstNonNull(config.maxIdleTime, dhisConfig.getProperty(ConfigurationKey.CONNECTION_POOL_MAX_IDLE_TIME)));
final int minPoolSize = Integer.parseInt(dhisConfig.getProperty(ConfigurationKey.CONNECTION_POOL_MIN_SIZE));
final int initialSize = Integer.parseInt(dhisConfig.getProperty(ConfigurationKey.CONNECTION_POOL_INITIAL_SIZE));
boolean testOnCheckIn = dhisConfig.isEnabled(ConfigurationKey.CONNECTION_POOL_TEST_ON_CHECKIN);
boolean testOnCheckOut = dhisConfig.isEnabled(ConfigurationKey.CONNECTION_POOL_TEST_ON_CHECKOUT);
final int maxIdleTimeExcessConnections = Integer.parseInt(dhisConfig.getProperty(ConfigurationKey.CONNECTION_POOL_MAX_IDLE_TIME_EXCESS_CON));
final int idleConnectionTestPeriod = Integer.parseInt(dhisConfig.getProperty(ConfigurationKey.CONNECTION_POOL_IDLE_CON_TEST_PERIOD));
final String preferredTestQuery = dhisConfig.getProperty(ConfigurationKey.CONNECTION_POOL_TEST_QUERY);
final int numHelperThreads = Integer.parseInt(dhisConfig.getProperty(ConfigurationKey.CONNECTION_POOL_NUM_THREADS));
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setDriverClass(driverClassName);
dataSource.setJdbcUrl(jdbcUrl);
dataSource.setUser(username);
dataSource.setPassword(password);
dataSource.setMaxPoolSize(maxPoolSize);
dataSource.setMinPoolSize(minPoolSize);
dataSource.setInitialPoolSize(initialSize);
dataSource.setAcquireIncrement(acquireIncrement);
dataSource.setMaxIdleTime(maxIdleTime);
dataSource.setTestConnectionOnCheckin(testOnCheckIn);
dataSource.setTestConnectionOnCheckout(testOnCheckOut);
dataSource.setMaxIdleTimeExcessConnections(maxIdleTimeExcessConnections);
dataSource.setIdleConnectionTestPeriod(idleConnectionTestPeriod);
dataSource.setPreferredTestQuery(preferredTestQuery);
dataSource.setNumHelperThreads(numHelperThreads);
testConnection(dataSource);
return dataSource;
}
Aggregations