Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Hibernate ORM/Reactive/Envers extensions to @ConfigMapping #38731

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_DEFAULT;
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_ENUM_VALUE;
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_IGNORE;
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_MAP_KEY;
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_SECTION;
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_ITEM;
Expand Down Expand Up @@ -246,6 +247,8 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String r
: annotationMirror.getElementValues().values().iterator().next().getValue().toString();
} else if (annotationName.equals(ANNOTATION_CONFIG_WITH_UNNAMED_KEY)) {
unnamedMapKey = true;
} else if (annotationName.equals(ANNOTATION_CONFIG_DOC_IGNORE)) {
generateDocumentation = false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public void disableHibernateEnversStaticInit(HibernateEnversRecorder recorder,
// TODO move this to runtime init once we implement in Hibernate ORM a way
// to remove entity types from the metamodel on runtime init
public void checkNoExplicitActiveTrue(HibernateEnversBuildTimeConfig buildTimeConfig) {
for (var entry : buildTimeConfig.getAllPersistenceUnitConfigsAsMap().entrySet()) {
for (var entry : buildTimeConfig.persistenceUnits().entrySet()) {
var config = entry.getValue();
if (config.active.isPresent() && config.active.get()) {
if (config.active().isPresent() && config.active().get()) {
var puName = entry.getKey();
String enabledPropertyKey = HibernateEnversBuildTimeConfig.extensionPropertyKey("enabled");
String activePropertyKey = HibernateEnversBuildTimeConfig.persistenceUnitPropertyKey(puName, "active");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class HibernateEnversEnabled implements BooleanSupplier {

@Override
public boolean getAsBoolean() {
return config.enabled;
return config.enabled();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public void registerEnversReflections(BuildProducer<ReflectiveClassBuildItem> re
.produce(ReflectiveClassBuildItem.builder("org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity")
.methods().build());

for (HibernateEnversBuildTimeConfigPersistenceUnit pu : buildTimeConfig.getAllPersistenceUnitConfigsAsMap().values()) {
pu.revisionListener.ifPresent(
for (HibernateEnversBuildTimeConfigPersistenceUnit pu : buildTimeConfig.persistenceUnits().values()) {
pu.revisionListener().ifPresent(
s -> reflectiveClass.produce(ReflectiveClassBuildItem.builder(s).methods().fields().build()));
pu.auditStrategy.ifPresent(
pu.auditStrategy().ifPresent(
s -> reflectiveClass.produce(ReflectiveClassBuildItem.builder(s).methods().fields().build()));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package io.quarkus.hibernate.envers;

import java.util.Map;
import java.util.TreeMap;

import io.quarkus.hibernate.orm.runtime.PersistenceUnitUtil;
import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigDocSection;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;
import io.smallrye.config.WithParentName;
import io.smallrye.config.WithUnnamedKey;

@ConfigMapping(prefix = "quarkus.hibernate-envers")
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public class HibernateEnversBuildTimeConfig {
public interface HibernateEnversBuildTimeConfig {
/**
* Whether Hibernate Envers is enabled <strong>during the build</strong>.
*
Expand All @@ -23,37 +25,22 @@ public class HibernateEnversBuildTimeConfig {
*
* @asciidoclet
*/
@ConfigItem(defaultValue = "true")
public boolean enabled;
@WithDefault("true")
boolean enabled();

/**
* Configuration for the default persistence unit.
* Configuration for persistence units.
*/
@ConfigItem(name = ConfigItem.PARENT)
public HibernateEnversBuildTimeConfigPersistenceUnit defaultPersistenceUnit;

/**
* Configuration for additional named persistence units.
*/
@ConfigDocSection
@WithParentName
@WithUnnamedKey(PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME)
@ConfigDocMapKey("persistence-unit-name")
@ConfigItem(name = ConfigItem.PARENT)
public Map<String, HibernateEnversBuildTimeConfigPersistenceUnit> persistenceUnits;

public Map<String, HibernateEnversBuildTimeConfigPersistenceUnit> getAllPersistenceUnitConfigsAsMap() {
Map<String, HibernateEnversBuildTimeConfigPersistenceUnit> map = new TreeMap<>();
if (defaultPersistenceUnit != null) {
map.put(PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME, defaultPersistenceUnit);
}
map.putAll(persistenceUnits);
return map;
}
Map<String, HibernateEnversBuildTimeConfigPersistenceUnit> persistenceUnits();

public static String extensionPropertyKey(String radical) {
static String extensionPropertyKey(String radical) {
return "quarkus.hibernate-envers." + radical;
}

public static String persistenceUnitPropertyKey(String persistenceUnitName, String radical) {
static String persistenceUnitPropertyKey(String persistenceUnitName, String radical) {
StringBuilder keyBuilder = new StringBuilder("quarkus.hibernate-envers.");
if (!PersistenceUnitUtil.isDefaultPersistenceUnit(persistenceUnitName)) {
keyBuilder.append("\"").append(persistenceUnitName).append("\".");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.WithDefault;

@ConfigGroup
public class HibernateEnversBuildTimeConfigPersistenceUnit {
public interface HibernateEnversBuildTimeConfigPersistenceUnit {

/**
* Whether Hibernate Envers should be active for this persistence unit at runtime.
Expand All @@ -24,164 +25,163 @@ public class HibernateEnversBuildTimeConfigPersistenceUnit {
*
* @asciidoclet
*/
@ConfigItem(defaultValueDocumentation = "'true' if Hibernate ORM is enabled; 'false' otherwise")
public Optional<Boolean> active = Optional.empty();
@ConfigDocDefault("'true' if Hibernate ORM is enabled; 'false' otherwise")
Optional<Boolean> active();

/**
* Enable store_data_at_delete feature.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#STORE_DATA_AT_DELETE}.
*/
@ConfigItem(defaultValue = "false")
public boolean storeDataAtDelete;
@WithDefault("false")
boolean storeDataAtDelete();

/**
* Defines a suffix for historical data table. Defaults to {@literal _AUD}.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#AUDIT_TABLE_SUFFIX}.
*/
@ConfigItem(defaultValue = "_AUD")
public Optional<String> auditTableSuffix;
@WithDefault("_AUD")
Optional<String> auditTableSuffix();
Comment on lines +42 to +43
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's very weird to have defaults on Optional properties, but as you can see that was already the case before. I didn't want to go into that rabbit hole for this PR, since my changes are unrelated.


/**
* Defines a prefix for historical data table. Default is the empty string.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#AUDIT_TABLE_PREFIX}.
*/
@ConfigItem(defaultValue = "")
public Optional<String> auditTablePrefix;
@WithDefault("")
Optional<String> auditTablePrefix();

/**
* Revision field name. Defaults to {@literal REV}.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#REVISION_FIELD_NAME}.
*/
@ConfigItem(defaultValue = "REV")
public Optional<String> revisionFieldName;
@WithDefault("REV")
Optional<String> revisionFieldName();

/**
* Revision type field name. Defaults to {@literal REVTYPE}.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#REVISION_TYPE_FIELD_NAME}.
*/
@ConfigItem(defaultValue = "REVTYPE")
public Optional<String> revisionTypeFieldName;
@WithDefault("REVTYPE")
Optional<String> revisionTypeFieldName();

/**
* Enable the revision_on_collection_change feature.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#REVISION_ON_COLLECTION_CHANGE}.
*/
@ConfigItem(defaultValue = "true")
public boolean revisionOnCollectionChange;
@WithDefault("true")
boolean revisionOnCollectionChange();

/**
* Enable the do_not_audit_optimistic_locking_field feature.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#DO_NOT_AUDIT_OPTIMISTIC_LOCKING_FIELD}.
*/
@ConfigItem(defaultValue = "true")
public boolean doNotAuditOptimisticLockingField;
@WithDefault("true")
boolean doNotAuditOptimisticLockingField();

/**
* Defines the default schema of where audit tables are to be created.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#DEFAULT_SCHEMA}.
*/
@ConfigItem(defaultValue = "")
public Optional<String> defaultSchema;
@WithDefault("")
Optional<String> defaultSchema();

/**
* Defines the default catalog of where audit tables are to be created.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#DEFAULT_CATALOG}.
*/
@ConfigItem(defaultValue = "")
public Optional<String> defaultCatalog;
@WithDefault("")
Optional<String> defaultCatalog();

/**
* Enables the track_entities_changed_in_revision feature.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#TRACK_ENTITIES_CHANGED_IN_REVISION}.
*/
@ConfigItem(defaultValue = "false")
public boolean trackEntitiesChangedInRevision;
@WithDefault("false")
boolean trackEntitiesChangedInRevision();

/**
* Enables the use_revision_entity_with_native_id feature.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#USE_REVISION_ENTITY_WITH_NATIVE_ID}.
*/
@ConfigItem(defaultValue = "true")
public boolean useRevisionEntityWithNativeId;
@WithDefault("true")
boolean useRevisionEntityWithNativeId();

/**
* Enables the global_with_modified_flag feature.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#GLOBAL_WITH_MODIFIED_FLAG}.
*/
@ConfigItem(defaultValue = "false")
public boolean globalWithModifiedFlag;
@WithDefault("false")
boolean globalWithModifiedFlag();

/**
* Defines the suffix to be used for modified flag columns. Defaults to {@literal _MOD}.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#MODIFIED_FLAG_SUFFIX}
*/
@ConfigItem(defaultValue = "_MOD")
public Optional<String> modifiedFlagSuffix;
@WithDefault("_MOD")
Optional<String> modifiedFlagSuffix();

/**
* Defines the fully qualified class name of a user defined revision listener.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#REVISION_LISTENER}.
*/
@ConfigItem
public Optional<String> revisionListener;
Optional<String> revisionListener();

/**
* Defines the fully qualified class name of the audit strategy to be used.
*
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#AUDIT_STRATEGY}.
*/
@ConfigItem(defaultValue = "org.hibernate.envers.strategy.DefaultAuditStrategy")
public Optional<String> auditStrategy;
@WithDefault("org.hibernate.envers.strategy.DefaultAuditStrategy")
Optional<String> auditStrategy();

/**
* Defines the property name for the audit entity's composite primary key. Defaults to {@literal originalId}.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#ORIGINAL_ID_PROP_NAME}.
*/
@ConfigItem(defaultValue = "originalId")
public Optional<String> originalIdPropName;
@WithDefault("originalId")
Optional<String> originalIdPropName();

/**
* Defines the column name that holds the end revision number in audit entities. Defaults to {@literal REVEND}.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#AUDIT_STRATEGY_VALIDITY_END_REV_FIELD_NAME}.
*/
@ConfigItem(defaultValue = "REVEND")
public Optional<String> auditStrategyValidityEndRevFieldName;
@WithDefault("REVEND")
Optional<String> auditStrategyValidityEndRevFieldName();

/**
* Enables the audit_strategy_validity_store_revend_timestamp feature.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#AUDIT_STRATEGY_VALIDITY_STORE_REVEND_TIMESTAMP}.
*/
@ConfigItem(defaultValue = "false")
public boolean auditStrategyValidityStoreRevendTimestamp;
@WithDefault("false")
boolean auditStrategyValidityStoreRevendTimestamp();

/**
* Defines the column name of the revision end timestamp in the audit tables. Defaults to {@literal REVEND_TSTMP}.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#AUDIT_STRATEGY_VALIDITY_REVEND_TIMESTAMP_FIELD_NAME}.
*/
@ConfigItem(defaultValue = "REVEND_TSTMP")
public Optional<String> auditStrategyValidityRevendTimestampFieldName;
@WithDefault("REVEND_TSTMP")
Optional<String> auditStrategyValidityRevendTimestampFieldName();

/**
* Defines the name of the column used for storing collection ordinal values for embeddable elements.
* Defaults to {@literal SETORDINAL}.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#EMBEDDABLE_SET_ORDINAL_FIELD_NAME}.
*/
@ConfigItem(defaultValue = "SETORDINAL")
public Optional<String> embeddableSetOrdinalFieldName;
@WithDefault("SETORDINAL")
Optional<String> embeddableSetOrdinalFieldName();

/**
* Enables the allow_identifier_reuse feature.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#ALLOW_IDENTIFIER_REUSE}.
*/
@ConfigItem(defaultValue = "false")
public boolean allowIdentifierReuse;
@WithDefault("false")
boolean allowIdentifierReuse();

/**
* Defines the naming strategy to be used for modified columns.
* Defaults to {@literal org.hibernate.envers.boot.internal.LegacyModifiedColumnNamingStrategy}.
* Maps to {@link org.hibernate.envers.configuration.EnversSettings#MODIFIED_COLUMN_NAMING_STRATEGY}.
*/
@ConfigItem(defaultValue = "org.hibernate.envers.boot.internal.LegacyModifiedColumnNamingStrategy")
public Optional<String> modifiedColumnNamingStrategy;
@WithDefault("org.hibernate.envers.boot.internal.LegacyModifiedColumnNamingStrategy")
Optional<String> modifiedColumnNamingStrategy();

}
Loading
Loading