use of com.evolveum.midpoint.repo.sqlbase.SqlTableMetadata 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();
}
}
}
}
Aggregations