Search in sources :

Example 31 with ComboPooledDataSource

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;
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource)

Example 32 with ComboPooledDataSource

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);
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource)

Example 33 with ComboPooledDataSource

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);
    }
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) SQLException(java.sql.SQLException) DataAccessException(org.springframework.dao.DataAccessException)

Example 34 with ComboPooledDataSource

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;
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource)

Example 35 with ComboPooledDataSource

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;
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) DhisConfigurationProvider(org.hisp.dhis.external.conf.DhisConfigurationProvider)

Aggregations

ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)69 PropertyVetoException (java.beans.PropertyVetoException)16 SQLException (java.sql.SQLException)13 Connection (java.sql.Connection)7 Test (org.junit.Test)7 Bean (org.springframework.context.annotation.Bean)7 Properties (java.util.Properties)5 DataSource (javax.sql.DataSource)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ComboPooledDataSource (com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource)4 ResultSet (java.sql.ResultSet)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 DbRuntimeException (cn.hutool.db.DbRuntimeException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 Duration (de.invesdwin.util.time.duration.Duration)2 PreparedStatement (java.sql.PreparedStatement)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2