Search in sources :

Example 1 with Param

use of org.opennms.netmgt.config.opennmsDataSources.Param in project opennms by OpenNMS.

the class C3P0ConnectionFactory method initializePool.

@Override
protected void initializePool(final JdbcDataSource dataSource) throws SQLException {
    m_pool = new ComboPooledDataSource();
    m_pool.setPassword(dataSource.getPassword());
    m_pool.setUser(dataSource.getUserName());
    m_pool.setJdbcUrl(dataSource.getUrl());
    try {
        m_pool.setDriverClass(dataSource.getClassName());
    } catch (final PropertyVetoException e) {
        throw new SQLException("Unable to set driver class.", e);
    }
    final Properties properties = new Properties();
    for (final Param parameter : dataSource.getParamCollection()) {
        properties.put(parameter.getName(), parameter.getValue());
    }
    if (!properties.isEmpty()) {
        m_pool.setProperties(properties);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) SQLException(java.sql.SQLException) Param(org.opennms.netmgt.config.opennmsDataSources.Param) Properties(java.util.Properties)

Example 2 with Param

use of org.opennms.netmgt.config.opennmsDataSources.Param in project opennms by OpenNMS.

the class HikariCPConnectionFactory method initializePool.

/* (non-Javadoc)
     * @see org.opennms.core.db.BaseConnectionFactory#initializePool(org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource)
     */
// TODO Enable and configure MetricRegistry
@Override
protected void initializePool(final JdbcDataSource dataSource) throws SQLException {
    final Properties properties = new Properties();
    for (final Param parameter : dataSource.getParamCollection()) {
        properties.setProperty(parameter.getName(), parameter.getValue());
    }
    final HikariConfig config = new HikariConfig(properties);
    config.setPoolName(dataSource.getName());
    config.setJdbcUrl(dataSource.getUrl());
    config.setUsername(dataSource.getUserName());
    config.setPassword(dataSource.getPassword());
    config.setDriverClassName(dataSource.getClassName());
    // NMS-9387: Block indefinitely when waiting for a connection
    config.setConnectionTimeout(0);
    // For JMX Monitoring
    config.setRegisterMbeans(true);
    config.validate();
    m_pool = new HikariDataSource(config);
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) Param(org.opennms.netmgt.config.opennmsDataSources.Param) Properties(java.util.Properties) HikariConfig(com.zaxxer.hikari.HikariConfig)

Example 3 with Param

use of org.opennms.netmgt.config.opennmsDataSources.Param in project opennms by OpenNMS.

the class DataSourceConfigurationTest method data.

@Parameters
public static Collection<Object[]> data() throws Exception {
    DataSourceConfiguration config = new DataSourceConfiguration();
    ConnectionPool connectionPool = new ConnectionPool();
    connectionPool.setFactory("org.opennms.core.db.HikariCPConnectionFactory");
    connectionPool.setIdleTimeout(600);
    connectionPool.setLoginTimeout(3);
    connectionPool.setMinPool(50);
    connectionPool.setMaxPool(50);
    connectionPool.setMaxSize(50);
    config.setConnectionPool(connectionPool);
    JdbcDataSource opennmsDs = new JdbcDataSource();
    opennmsDs.setName("opennms");
    opennmsDs.setClassName("org.postgresql.Driver");
    opennmsDs.setUrl("jdbc:postgresql://localhost:5432/template1");
    opennmsDs.setUserName("opennms");
    opennmsDs.setPassword("opennms");
    config.addJdbcDataSource(opennmsDs);
    JdbcDataSource opennmsDeuceDs = new JdbcDataSource();
    opennmsDeuceDs.setName("opennms2");
    opennmsDeuceDs.setClassName("org.postgresql.Driver");
    opennmsDeuceDs.setUrl("jdbc:postgresql://localhost:5432/template1");
    opennmsDeuceDs.addParam(new Param("user", "opennms"));
    opennmsDeuceDs.addParam(new Param("password", "opennms"));
    config.addJdbcDataSource(opennmsDeuceDs);
    return Arrays.asList(new Object[][] { { config, new File("src/test/resources/org/opennms/core/db/opennms-datasources.xml") } });
}
Also used : ConnectionPool(org.opennms.netmgt.config.opennmsDataSources.ConnectionPool) JdbcDataSource(org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource) Param(org.opennms.netmgt.config.opennmsDataSources.Param) DataSourceConfiguration(org.opennms.netmgt.config.opennmsDataSources.DataSourceConfiguration) File(java.io.File) Parameters(org.junit.runners.Parameterized.Parameters)

Aggregations

Param (org.opennms.netmgt.config.opennmsDataSources.Param)3 Properties (java.util.Properties)2 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)1 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 PropertyVetoException (java.beans.PropertyVetoException)1 File (java.io.File)1 SQLException (java.sql.SQLException)1 Parameters (org.junit.runners.Parameterized.Parameters)1 ConnectionPool (org.opennms.netmgt.config.opennmsDataSources.ConnectionPool)1 DataSourceConfiguration (org.opennms.netmgt.config.opennmsDataSources.DataSourceConfiguration)1 JdbcDataSource (org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource)1