Search in sources :

Example 1 with SqaleRepositoryConfiguration

use of com.evolveum.midpoint.repo.sqale.SqaleRepositoryConfiguration in project midpoint by Evolveum.

the class SqaleAuditServiceFactory method initCustomColumns.

private void initCustomColumns(@NotNull Configuration configuration, SqaleRepoContext sqlRepoContext) {
    List<HierarchicalConfiguration<ImmutableNode>> subConfigColumns = ((BaseHierarchicalConfiguration) configuration).configurationsAt(CONF_AUDIT_SERVICE_COLUMNS);
    // here we use config from context, it can be main repository configuration
    SqaleRepositoryConfiguration repoConfig = (SqaleRepositoryConfiguration) sqlRepoContext.getJdbcRepositoryConfiguration();
    boolean createMissing = repoConfig.isCreateMissingCustomColumns() || // but we'll consider the flag also on audit configuration, just in case
    configuration.getBoolean(PROPERTY_CREATE_MISSING_CUSTOM_COLUMNS, false);
    SqlTableMetadata tableMetadata = null;
    if (createMissing) {
        try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startReadOnlyTransaction()) {
            tableMetadata = SqlTableMetadata.create(jdbcSession.connection(), QAuditEventRecord.TABLE_NAME);
        }
    }
    for (Configuration subConfigColumn : subConfigColumns) {
        String columnName = getStringFromConfig(subConfigColumn, CONF_AUDIT_SERVICE_COLUMN_NAME);
        String propertyName = getStringFromConfig(subConfigColumn, CONF_AUDIT_SERVICE_EVENT_RECORD_PROPERTY_NAME);
        // No type definition for now, it's all String or String implicit conversion.
        ColumnMetadata columnMetadata = ColumnMetadata.named(columnName).ofType(Types.VARCHAR);
        QAuditEventRecordMapping.get().addExtensionColumn(propertyName, columnMetadata);
        if (tableMetadata != null && tableMetadata.get(columnName) == null) {
            try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startTransaction()) {
                jdbcSession.addColumn(QAuditEventRecord.TABLE_NAME, columnMetadata);
                jdbcSession.commit();
            }
        }
    }
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) ColumnMetadata(com.querydsl.sql.ColumnMetadata) SqaleRepositoryConfiguration(com.evolveum.midpoint.repo.sqale.SqaleRepositoryConfiguration) JdbcRepositoryConfiguration(com.evolveum.midpoint.repo.sqlbase.JdbcRepositoryConfiguration) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) Configuration(org.apache.commons.configuration2.Configuration) BaseHierarchicalConfiguration(org.apache.commons.configuration2.BaseHierarchicalConfiguration) SqaleRepositoryConfiguration(com.evolveum.midpoint.repo.sqale.SqaleRepositoryConfiguration) BaseHierarchicalConfiguration(org.apache.commons.configuration2.BaseHierarchicalConfiguration) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) BaseHierarchicalConfiguration(org.apache.commons.configuration2.BaseHierarchicalConfiguration) SqlTableMetadata(com.evolveum.midpoint.repo.sqlbase.SqlTableMetadata)

Example 2 with SqaleRepositoryConfiguration

use of com.evolveum.midpoint.repo.sqale.SqaleRepositoryConfiguration in project midpoint by Evolveum.

the class SqaleAuditServiceFactory method createSqaleRepoContext.

private SqaleRepoContext createSqaleRepoContext(Configuration configuration) throws RepositoryServiceFactoryException {
    // one of these properties must be present to trigger separate audit datasource config
    if (configuration.getString(PROPERTY_JDBC_URL) == null && configuration.getString(PROPERTY_DATASOURCE) == null) {
        LOGGER.info("SQL audit service will use default repository configuration.");
        return createSqaleRepoContext(SqaleRepositoryConfiguration.initForAudit(sqaleRepositoryConfiguration, configuration), repositoryDataSource, schemaService);
    }
    LOGGER.info("Configuring SQL audit service to use a different datasource");
    SqaleRepositoryConfiguration config = new SqaleRepositoryConfiguration(configuration);
    // normally Spring calls this, but for audit this is unmanaged bean
    config.init();
    DataSourceFactory dataSourceFactory = new DataSourceFactory(config);
    DataSource dataSource = dataSourceFactory.createDataSource("mp-audit");
    return createSqaleRepoContext(config, dataSource, schemaService);
}
Also used : DataSourceFactory(com.evolveum.midpoint.repo.sqlbase.DataSourceFactory) SqaleRepositoryConfiguration(com.evolveum.midpoint.repo.sqale.SqaleRepositoryConfiguration) DataSource(javax.sql.DataSource)

Aggregations

SqaleRepositoryConfiguration (com.evolveum.midpoint.repo.sqale.SqaleRepositoryConfiguration)2 DataSourceFactory (com.evolveum.midpoint.repo.sqlbase.DataSourceFactory)1 JdbcRepositoryConfiguration (com.evolveum.midpoint.repo.sqlbase.JdbcRepositoryConfiguration)1 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)1 SqlTableMetadata (com.evolveum.midpoint.repo.sqlbase.SqlTableMetadata)1 ColumnMetadata (com.querydsl.sql.ColumnMetadata)1 DataSource (javax.sql.DataSource)1 BaseHierarchicalConfiguration (org.apache.commons.configuration2.BaseHierarchicalConfiguration)1 Configuration (org.apache.commons.configuration2.Configuration)1 HierarchicalConfiguration (org.apache.commons.configuration2.HierarchicalConfiguration)1