Search in sources :

Example 51 with ComboPooledDataSource

use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project RecordManager2 by moravianlibrary.

the class WebAppConfig method dataSource.

@Bean
public DataSource dataSource(@Value("${jdbc.driverClassName}") String driverClassName, @Value("${jdbc.url}") String url, @Value("${jdbc.username}") String username, @Value("${jdbc.password}") String password) throws PropertyVetoException {
    ComboPooledDataSource dataSource = new ComboPooledDataSource();
    dataSource.setDriverClass(driverClassName);
    dataSource.setJdbcUrl(url);
    dataSource.setUser(username);
    dataSource.setPassword(password);
    return dataSource;
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) Bean(org.springframework.context.annotation.Bean)

Example 52 with ComboPooledDataSource

use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project netxms by netxms.

the class DaoContextConfig method dataSource.

@Bean
@Qualifier("systemDataSource")
public DataSource dataSource() throws PropertyVetoException {
    ComboPooledDataSource dataSource = new ComboPooledDataSource();
    ServerSettings.DataSourceConfig dataSourceConfig = settings.getDataSourceConfig(ServerSettings.DC_ID_SYSTEM);
    dataSource.setDriverClass(dataSourceConfig.getDriver());
    dataSource.setJdbcUrl(dataSourceConfig.getUrl());
    dataSource.setUser(dataSourceConfig.getUsername());
    dataSource.setPassword(dataSourceConfig.getPassword());
    dataSource.setTestConnectionOnCheckout(true);
    dataSource.setCheckoutTimeout(3000);
    dataSource.setIdleConnectionTestPeriod(300);
    return dataSource;
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) ServerSettings(com.radensolutions.reporting.service.ServerSettings) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Bean(org.springframework.context.annotation.Bean)

Example 53 with ComboPooledDataSource

use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project opencast by opencast.

the class PersistenceUtil method newEntityManagerFactory.

public static EntityManagerFactory newEntityManagerFactory(String emName, String vendor, String driver, String url, String user, String pwd, Map<String, ?> persistenceProps, PersistenceProvider pp) {
    // Set up the database
    final ComboPooledDataSource pooledDataSource = new ComboPooledDataSource();
    try {
        pooledDataSource.setDriverClass(driver);
    } catch (PropertyVetoException e) {
        throw new RuntimeException(e);
    }
    pooledDataSource.setJdbcUrl(url);
    pooledDataSource.setUser(user);
    pooledDataSource.setPassword(pwd);
    // Set up the persistence properties
    final Map<String, Object> props = Immutables.<String, Object>map(persistenceProps, tuple("javax.persistence.nonJtaDataSource", pooledDataSource), tuple("eclipselink.target-database", vendor));
    final EntityManagerFactory emf = pp.createEntityManagerFactory(emName, props);
    if (emf == null) {
        throw new Error("Cannot create entity manager factory for persistence unit " + emName + ". Maybe you misspelled the name of the persistence unit?");
    }
    return emf;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 54 with ComboPooledDataSource

use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project opencast by opencast.

the class PersistenceUtil method mkEntityManagerFactory.

public static EntityManagerFactory mkEntityManagerFactory(String emName, String vendor, String driver, String url, String user, String pwd, Map<String, ?> persistenceProps, PersistenceProvider pp) {
    // Set up the database
    final ComboPooledDataSource pooledDataSource = new ComboPooledDataSource();
    try {
        pooledDataSource.setDriverClass(driver);
    } catch (PropertyVetoException e) {
        throw new RuntimeException(e);
    }
    pooledDataSource.setJdbcUrl(url);
    pooledDataSource.setUser(user);
    pooledDataSource.setPassword(pwd);
    // Set up the persistence properties
    final Map<String, Object> props = Immutables.<String, Object>map(persistenceProps, tuple("javax.persistence.nonJtaDataSource", pooledDataSource), tuple("eclipselink.target-database", vendor));
    final EntityManagerFactory emf = pp.createEntityManagerFactory(emName, props);
    if (emf == null) {
        throw new Error("Cannot create entity manager factory for persistence unit " + emName + ". Maybe you misspelled the name of the persistence unit?");
    }
    return emf;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 55 with ComboPooledDataSource

use of com.mchange.v2.c3p0.jacksonTest.ComboPooledDataSource in project opencast by opencast.

the class SchedulerMigrationServiceTest method createDataSource.

private DataSource createDataSource(String databaseUrl, String databaseUser, String databasePassword) {
    final Map<String, String> testEntityManagerProps = new HashMap<>();
    testEntityManagerProps.put("eclipselink.ddl-generation", "none");
    testEntityManagerProps.put("eclipselink.ddl-generation.output-mode", "database");
    final ComboPooledDataSource pooledDataSource = new ComboPooledDataSource();
    try {
        pooledDataSource.setDriverClass("com.mysql.jdbc.Driver");
    } catch (PropertyVetoException e) {
        throw new RuntimeException(e);
    }
    pooledDataSource.setJdbcUrl(databaseUrl);
    pooledDataSource.setUser(databaseUser);
    pooledDataSource.setPassword(databasePassword);
    return pooledDataSource;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) HashMap(java.util.HashMap) EasyMock.anyString(org.easymock.EasyMock.anyString)

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