Search in sources :

Example 16 with RepositoryServiceFactoryException

use of com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException in project midpoint by Evolveum.

the class DataSourceFactory method createDataSource.

public DataSource createDataSource(String applicationName) throws RepositoryServiceFactoryException {
    LOGGER.info("Loading datasource.");
    if (configuration == null) {
        throw new RepositoryServiceFactoryException("SQL configuration is null, couldn't create datasource.");
    }
    if (StringUtils.isNotEmpty(configuration.getDataSource())) {
        try {
            LOGGER.info("JNDI datasource present in configuration, looking for '{}'.", configuration.getDataSource());
            dataSource = createJndiDataSource();
        } catch (Exception ex) {
            throw new RepositoryServiceFactoryException("Couldn't initialize datasource using datasource " + configuration.getDataSource() + ", reason: " + ex.getMessage(), ex);
        }
    } else {
        String jdbcUrl = configuration.getJdbcUrl(applicationName);
        try {
            LOGGER.info("Constructing default datasource with connection pooling; JDBC URL: {}" + "\n Using driver: {}", jdbcUrl, configuration.getDriverClassName());
            HikariConfig config = createHikariConfig(applicationName);
            dataSource = new HikariDataSource(config);
            internalDataSource = true;
        } catch (Exception ex) {
            throw new RepositoryServiceFactoryException("Couldn't initialize datasource using JDBC URL " + jdbcUrl + ", reason: " + ex.getMessage(), ex);
        }
    }
    return dataSource;
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariConfig(com.zaxxer.hikari.HikariConfig) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException) IOException(java.io.IOException) NamingException(javax.naming.NamingException)

Aggregations

RepositoryServiceFactoryException (com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)16 IOException (java.io.IOException)7 BindException (java.net.BindException)6 File (java.io.File)5 AuditServiceFactoryException (com.evolveum.midpoint.audit.api.AuditServiceFactoryException)3 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 ServerSocket (java.net.ServerSocket)2 Properties (java.util.Properties)2 NamingException (javax.naming.NamingException)2 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)1 SqaleRepoContext (com.evolveum.midpoint.repo.sqale.SqaleRepoContext)1 SqlRepositoryConfiguration (com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration)1 SqlRepositoryFactory (com.evolveum.midpoint.repo.sql.SqlRepositoryFactory)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 PropertyVetoException (java.beans.PropertyVetoException)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1