Skip to content

Commit 8e7ca48

Browse files
authored
Merge pull request #31620 from yrodiere/i31475-cleanup
Polish tests and documentation for `quarkus.hibernate-orm.database.orm-compatibility.version`
2 parents fe333db + a5aa4b6 commit 8e7ca48

File tree

10 files changed

+117
-48
lines changed

10 files changed

+117
-48
lines changed

core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ final public class Constants {
6060
public static final String ANNOTATION_CONFIG_GROUP = "io.quarkus.runtime.annotations.ConfigGroup";
6161
public static final String ANNOTATION_CONFIG_DOC_MAP_KEY = "io.quarkus.runtime.annotations.ConfigDocMapKey";
6262
public static final String ANNOTATION_CONFIG_DOC_SECTION = "io.quarkus.runtime.annotations.ConfigDocSection";
63+
public static final String ANNOTATION_CONFIG_DOC_ENUM_VALUE = "io.quarkus.runtime.annotations.ConfigDocEnumValue";
6364

6465
public static final String ANNOTATION_CONFIG_WITH_NAME = "io.smallrye.config.WithName";
6566
public static final String ANNOTATION_CONFIG_WITH_DEFAULT = "io.smallrye.config.WithDefault";
Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.quarkus.annotation.processor.generate_doc;
22

3+
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_ENUM_VALUE;
34
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_MAP_KEY;
45
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_DOC_SECTION;
56
import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_ITEM;
@@ -52,7 +53,7 @@
5253
import io.quarkus.annotation.processor.Constants;
5354
import io.quarkus.annotation.processor.generate_doc.JavaDocParser.SectionHolder;
5455

55-
class ConfigDoItemFinder {
56+
class ConfigDocItemFinder {
5657

5758
private static final String COMMA = ",";
5859
private static final String BACK_TICK = "`";
@@ -70,7 +71,7 @@ class ConfigDoItemFinder {
7071
private final FsMap allConfigurationGroups;
7172
private final FsMap allConfigurationRoots;
7273

73-
public ConfigDoItemFinder(Set<ConfigRootInfo> configRoots,
74+
public ConfigDocItemFinder(Set<ConfigRootInfo> configRoots,
7475
Map<String, TypeElement> configGroupQualifiedNameToTypeElementMap,
7576
Properties javaDocProperties, FsMap allConfigurationGroups, FsMap allConfigurationRoots) {
7677
this.configRoots = configRoots;
@@ -435,7 +436,12 @@ private List<String> extractEnumValues(TypeMirror realTypeMirror, boolean useHyp
435436
final String constantJavaDocKey = javaDocKey + DOT + enumValue;
436437
final String rawJavaDoc = javaDocProperties.getProperty(constantJavaDocKey);
437438

438-
enumValue = useHyphenatedEnumValue ? hyphenateEnumValue(enumValue) : enumValue;
439+
String explicitEnumValueName = extractEnumValueName(field);
440+
if (explicitEnumValueName != null) {
441+
enumValue = explicitEnumValueName;
442+
} else {
443+
enumValue = useHyphenatedEnumValue ? hyphenateEnumValue(enumValue) : enumValue;
444+
}
439445
if (rawJavaDoc != null && !rawJavaDoc.isBlank()) {
440446
// Show enum constant description as a Tooltip
441447
String javaDoc = enumJavaDocParser.parseConfigDescription(rawJavaDoc);
@@ -450,6 +456,22 @@ private List<String> extractEnumValues(TypeMirror realTypeMirror, boolean useHyp
450456
return acceptedValues;
451457
}
452458

459+
private String extractEnumValueName(Element enumField) {
460+
for (AnnotationMirror annotationMirror : enumField.getAnnotationMirrors()) {
461+
String annotationName = annotationMirror.getAnnotationType().toString();
462+
if (annotationName.equals(ANNOTATION_CONFIG_DOC_ENUM_VALUE)) {
463+
for (var entry : annotationMirror.getElementValues().entrySet()) {
464+
var key = entry.getKey().toString();
465+
var value = entry.getValue().getValue();
466+
if ("value()".equals(key)) {
467+
return value.toString();
468+
}
469+
}
470+
}
471+
}
472+
return null;
473+
}
474+
453475
private boolean isEnumType(TypeMirror realTypeMirror) {
454476
return realTypeMirror instanceof DeclaredType
455477
&& ((DeclaredType) realTypeMirror).asElement().getKind() == ElementKind.ENUM;

core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemScanner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ public Set<ConfigDocGeneratedOutput> scanExtensionsConfigurationItems(Properties
122122
throws IOException {
123123

124124
Set<ConfigDocGeneratedOutput> configDocGeneratedOutputs = new HashSet<>();
125-
final ConfigDoItemFinder configDoItemFinder = new ConfigDoItemFinder(configRoots, configGroupsToTypeElement,
125+
final ConfigDocItemFinder configDocItemFinder = new ConfigDocItemFinder(configRoots, configGroupsToTypeElement,
126126
javaDocProperties, allConfigGroupGeneratedDocs, allExtensionGeneratedDocs);
127-
final ScannedConfigDocsItemHolder inMemoryScannedItemsHolder = configDoItemFinder.findInMemoryConfigurationItems();
127+
final ScannedConfigDocsItemHolder inMemoryScannedItemsHolder = configDocItemFinder.findInMemoryConfigurationItems();
128128

129129
if (!inMemoryScannedItemsHolder.isEmpty()) {
130130
updateScannedExtensionArtifactFiles(inMemoryScannedItemsHolder);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.quarkus.runtime.annotations;
2+
3+
import static java.lang.annotation.ElementType.FIELD;
4+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
5+
6+
import java.lang.annotation.Documented;
7+
import java.lang.annotation.Retention;
8+
import java.lang.annotation.Target;
9+
10+
/**
11+
* A way to explicitly customize the string displayed in the documentation
12+
* when listing accepted values for an enum.
13+
* <p>
14+
* Only works when applied to enum values.
15+
*/
16+
@Retention(RUNTIME)
17+
@Target({ FIELD })
18+
@Documented
19+
public @interface ConfigDocEnumValue {
20+
21+
/**
22+
* @return The string displayed in the documentation for this value
23+
* when listing accepted values for a configuration property of the relevant enum type.
24+
*/
25+
String value();
26+
27+
}

extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmConfig.java

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,11 @@ public class HibernateOrmConfig {
2929
public boolean enabled;
3030

3131
/**
32-
* When set, attempts to exchange data with the database
33-
* as the given version of Hibernate ORM would have,
34-
* *on a best-effort basis*.
35-
*
36-
* Please note:
37-
*
38-
* * schema validation may still fail in some cases:
39-
* this attempts to make Hibernate ORM 6+ behave correctly at runtime,
40-
* but it may still expect a different (but runtime-compatible) schema.
41-
* * robust test suites are still useful and recommended:
42-
* you should still check that your application behaves as intended with your legacy schema.
43-
* * this feature is inherently unstable:
44-
* some aspects of it may stop working in future versions of Quarkus,
45-
* and older versions will be dropped as Hibernate ORM changes pile up
46-
* and support for those older versions becomes too unreliable.
47-
* * you should still plan a migration of your schema to a newer version of Hibernate ORM.
48-
* For help with migration, refer to
49-
* link:https://github.com/quarkusio/quarkus/wiki/Migration-Guide-3.0:-Hibernate-ORM-5-to-6-migration[the Quarkus 3
50-
* migration guide from Hibernate ORM 5 to 6].
51-
*
52-
* @asciidoclet
32+
* Database related configuration.
5333
*/
54-
@ConfigItem(name = "database.orm-compatibility.version", defaultValue = "LATEST")
55-
@ConvertWith(DatabaseOrmCompatibilityVersion.Converter.class)
56-
public DatabaseOrmCompatibilityVersion databaseOrmCompatibilityVersion;
34+
@ConfigItem
35+
@ConfigDocSection
36+
public HibernateOrmConfigDatabase database;
5737

5838
/**
5939
* Configuration for the default persistence unit.
@@ -159,4 +139,35 @@ public boolean isAnyPropertySet() {
159139
return bindParam || bindParameters;
160140
}
161141
}
142+
143+
@ConfigGroup
144+
public static class HibernateOrmConfigDatabase {
145+
/**
146+
* When set, attempts to exchange data with the database
147+
* as the given version of Hibernate ORM would have,
148+
* *on a best-effort basis*.
149+
*
150+
* Please note:
151+
*
152+
* * schema validation may still fail in some cases:
153+
* this attempts to make Hibernate ORM 6+ behave correctly at runtime,
154+
* but it may still expect a different (but runtime-compatible) schema.
155+
* * robust test suites are still useful and recommended:
156+
* you should still check that your application behaves as intended with your legacy schema.
157+
* * this feature is inherently unstable:
158+
* some aspects of it may stop working in future versions of Quarkus,
159+
* and older versions will be dropped as Hibernate ORM changes pile up
160+
* and support for those older versions becomes too unreliable.
161+
* * you should still plan a migration of your schema to a newer version of Hibernate ORM.
162+
* For help with migration, refer to
163+
* link:https://github.com/quarkusio/quarkus/wiki/Migration-Guide-3.0:-Hibernate-ORM-5-to-6-migration[the Quarkus 3
164+
* migration guide from Hibernate ORM 5 to 6].
165+
*
166+
* @asciidoclet
167+
*/
168+
@ConfigItem(name = "orm-compatibility.version", defaultValue = "latest")
169+
@ConvertWith(DatabaseOrmCompatibilityVersion.Converter.class)
170+
public DatabaseOrmCompatibilityVersion ormCompatibilityVersion;
171+
}
172+
162173
}

extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public void configurationDescriptorBuilding(
399399
null,
400400
jpaModel.getXmlMappings(persistenceXmlDescriptorBuildItem.getDescriptor().getName()),
401401
Collections.emptyMap(),
402-
hibernateOrmConfig.databaseOrmCompatibilityVersion,
402+
hibernateOrmConfig.database.ormCompatibilityVersion,
403403
false, true));
404404
}
405405

@@ -1209,7 +1209,7 @@ private static void producePersistenceUnitDescriptorFromConfig(
12091209
persistenceUnitConfig.multitenantSchemaDatasource.orElse(null),
12101210
xmlMappings,
12111211
persistenceUnitConfig.unsupportedProperties,
1212-
hibernateOrmConfig.databaseOrmCompatibilityVersion,
1212+
hibernateOrmConfig.database.ormCompatibilityVersion,
12131213
false, false));
12141214
}
12151215

extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/config/DatabaseOrmCompatibilityVersion.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@
1010
import org.hibernate.cfg.AvailableSettings;
1111

1212
import io.quarkus.datasource.common.runtime.DatabaseKind;
13+
import io.quarkus.runtime.annotations.ConfigDocEnumValue;
1314

1415
public enum DatabaseOrmCompatibilityVersion {
16+
/**
17+
* **Best-effort** compatibility with a database schema and data
18+
* meant for Hibernate ORM 5.6,
19+
* even though the version of Hibernate ORM shipped with Quarkus is different.
20+
*
21+
* @asciidoclet
22+
*/
23+
@ConfigDocEnumValue("5.6")
1524
V5_6("5.6") {
1625
@Override
1726
public Map<String, String> settings(Optional<String> dbKind) {
@@ -43,6 +52,15 @@ public Map<String, String> settings(Optional<String> dbKind) {
4352
return result;
4453
}
4554
},
55+
/**
56+
* No particular effort on compatibility:
57+
* just assume the database schema and data are compatible
58+
* with the "latest" version of Hibernate ORM,
59+
* i.e. the version shipped with Quarkus.
60+
*
61+
* @asciidoclet
62+
*/
63+
@ConfigDocEnumValue("latest")
4664
LATEST("latest") {
4765
@Override
4866
public Map<String, String> settings(Optional<String> dbKind) {
@@ -62,6 +80,12 @@ private static boolean usedToSupportUuid(String dbKind) {
6280
this.externalRepresentation = externalRepresentation;
6381
}
6482

83+
@Override
84+
public String toString() {
85+
// Necessary for proper rendering in the documentation
86+
return externalRepresentation;
87+
}
88+
6589
public abstract Map<String, String> settings(Optional<String> dbKind);
6690

6791
public static class Converter

extensions/hibernate-reactive/deployment/src/main/java/io/quarkus/hibernate/reactive/deployment/HibernateReactiveProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void buildReactivePersistenceUnit(
166166
PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME, dbKindOptional,
167167
jpaModel.getXmlMappings(reactivePU.getName()),
168168
persistenceUnitConfig.unsupportedProperties,
169-
hibernateOrmConfig.databaseOrmCompatibilityVersion,
169+
hibernateOrmConfig.database.ormCompatibilityVersion,
170170
true, false));
171171
}
172172

integration-tests/hibernate-orm-compatibility-5.6/mariadb/src/test/java/io/quarkus/it/hibernate/compatibility/CompatibilityTestInGraalITCase.java

Lines changed: 0 additions & 8 deletions
This file was deleted.

integration-tests/hibernate-orm-compatibility-5.6/postgresql/src/test/java/io/quarkus/it/hibernate/compatibility/CompatibilityTestInGraalITCase.java

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)