Search in sources :

Example 1 with RepositoryFactory

use of com.evolveum.midpoint.init.RepositoryFactory in project midpoint by Evolveum.

the class DataSourceTestBeanPostprocessor method postProcessAfterInitialization.

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if (!(bean instanceof RepositoryFactory)) {
        return bean;
    }
    TestSqlRepositoryFactory factory = context.getBean("testSqlRepositoryFactory", TestSqlRepositoryFactory.class);
    SqlRepositoryConfiguration config = factory.getSqlConfiguration();
    if (!config.isUsingH2()) {
        return bean;
    }
    System.out.println("Changing hibernate.hbm2ddl.auto to update");
    LOGGER.info("Changing hibernate.hbm2ddl.auto to update");
    config.setHibernateHbm2ddl("update");
    return bean;
}
Also used : TestSqlRepositoryFactory(com.evolveum.midpoint.repo.sql.testing.TestSqlRepositoryFactory) RepositoryFactory(com.evolveum.midpoint.init.RepositoryFactory) TestSqlRepositoryFactory(com.evolveum.midpoint.repo.sql.testing.TestSqlRepositoryFactory) SqlRepositoryConfiguration(com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration)

Example 2 with RepositoryFactory

use of com.evolveum.midpoint.init.RepositoryFactory in project midpoint by Evolveum.

the class WfConfiguration method initialize.

@PostConstruct
void initialize() {
    Configuration c = midpointConfiguration.getConfiguration(WF_CONFIG_SECTION);
    checkAllowedKeys(c, KNOWN_KEYS, DEPRECATED_KEYS);
    enabled = c.getBoolean(KEY_ENABLED, true);
    if (!enabled) {
        LOGGER.info("Workflows are disabled.");
        return;
    }
    // activiti properties related to database connection will be taken from SQL repository
    SqlRepositoryConfiguration sqlConfig = null;
    String defaultJdbcUrlPrefix = null;
    dropDatabase = false;
    try {
        RepositoryFactory repositoryFactory = (RepositoryFactory) beanFactory.getBean("repositoryFactory");
        if (!(repositoryFactory.getFactory() instanceof SqlRepositoryFactory)) {
            // it may be null as well
            LOGGER.debug("SQL configuration cannot be found; Activiti database configuration (if any) will be taken from 'workflow' configuration section only");
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("repositoryFactory.getFactory() = " + repositoryFactory);
            }
        } else {
            SqlRepositoryFactory sqlRepositoryFactory = (SqlRepositoryFactory) repositoryFactory.getFactory();
            sqlConfig = sqlRepositoryFactory.getSqlConfiguration();
            if (sqlConfig.isEmbedded()) {
                defaultJdbcUrlPrefix = sqlRepositoryFactory.prepareJdbcUrlPrefix(sqlConfig);
                dropDatabase = sqlConfig.isDropIfExists();
            }
        }
    } catch (NoSuchBeanDefinitionException e) {
        LOGGER.debug("SqlRepositoryFactory is not available, Activiti database configuration (if any) will be taken from 'workflow' configuration section only.");
        LOGGER.trace("Reason is", e);
    } catch (RepositoryServiceFactoryException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Cannot determine default JDBC URL for embedded database", e);
    }
    String explicitJdbcUrl = c.getString(KEY_JDBC_URL, null);
    if (explicitJdbcUrl == null) {
        if (sqlConfig == null || sqlConfig.isEmbedded()) {
            jdbcUrl = defaultJdbcUrlPrefix + "-activiti;DB_CLOSE_ON_EXIT=FALSE;MVCC=FALSE";
        } else {
            jdbcUrl = sqlConfig.getJdbcUrl();
        }
    } else {
        jdbcUrl = explicitJdbcUrl;
    }
    dataSource = c.getString(KEY_DATA_SOURCE, null);
    if (dataSource == null && explicitJdbcUrl == null && sqlConfig != null) {
        // we want to use wf-specific JDBC if there is one (i.e. we do not want to inherit data source from repo in such a case)
        dataSource = sqlConfig.getDataSource();
    }
    if (dataSource != null) {
        LOGGER.info("Activiti database is at " + dataSource + " (a data source)");
    } else {
        LOGGER.info("Activiti database is at " + jdbcUrl + " (a JDBC URL)");
    }
    boolean defaultSchemaUpdate = sqlConfig == null || "update".equals(sqlConfig.getHibernateHbm2ddl());
    activitiSchemaUpdate = c.getBoolean(KEY_ACTIVITI_SCHEMA_UPDATE, defaultSchemaUpdate);
    LOGGER.info("Activiti automatic schema update: {}", activitiSchemaUpdate);
    jdbcDriver = c.getString(KEY_JDBC_DRIVER, sqlConfig != null ? sqlConfig.getDriverClassName() : null);
    jdbcUser = c.getString(KEY_JDBC_USERNAME, sqlConfig != null ? sqlConfig.getJdbcUsername() : null);
    jdbcPassword = c.getString(KEY_JDBC_PASSWORD, sqlConfig != null ? sqlConfig.getJdbcPassword() : null);
    autoDeploymentFrom = c.getStringArray(KEY_AUTO_DEPLOYMENT_FROM);
    if (autoDeploymentFrom.length == 0) {
        autoDeploymentFrom = new String[] { AUTO_DEPLOYMENT_FROM_DEFAULT };
    }
    //        hibernateDialect = sqlConfig != null ? sqlConfig.getHibernateDialect() : "";
    validate();
}
Also used : MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) Configuration(org.apache.commons.configuration.Configuration) SqlRepositoryConfiguration(com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration) SqlRepositoryFactory(com.evolveum.midpoint.repo.sql.SqlRepositoryFactory) SqlRepositoryFactory(com.evolveum.midpoint.repo.sql.SqlRepositoryFactory) RepositoryFactory(com.evolveum.midpoint.init.RepositoryFactory) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException) SqlRepositoryConfiguration(com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration) PostConstruct(javax.annotation.PostConstruct)

Aggregations

RepositoryFactory (com.evolveum.midpoint.init.RepositoryFactory)2 SqlRepositoryConfiguration (com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration)2 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)1 RepositoryServiceFactoryException (com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)1 SqlRepositoryFactory (com.evolveum.midpoint.repo.sql.SqlRepositoryFactory)1 TestSqlRepositoryFactory (com.evolveum.midpoint.repo.sql.testing.TestSqlRepositoryFactory)1 PostConstruct (javax.annotation.PostConstruct)1 Configuration (org.apache.commons.configuration.Configuration)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1