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();
}
}
}
}
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);
}
Aggregations