Skip to content

Commit ec5c243

Browse files
committed
Improve documentation of ORM 5.6 compatibility switch
* Move it to the "Database related configuration" section * Make sure that enum values are rendered correctly
1 parent c47a599 commit ec5c243

File tree

7 files changed

+113
-28
lines changed

7 files changed

+113
-28
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";

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

Lines changed: 23 additions & 1 deletion
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;
@@ -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;
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
@@ -395,7 +395,7 @@ public void configurationDescriptorBuilding(
395395
null,
396396
jpaModel.getXmlMappings(persistenceXmlDescriptorBuildItem.getDescriptor().getName()),
397397
Collections.emptyMap(),
398-
hibernateOrmConfig.databaseOrmCompatibilityVersion,
398+
hibernateOrmConfig.database.ormCompatibilityVersion,
399399
false, true));
400400
}
401401

@@ -1205,7 +1205,7 @@ private static void producePersistenceUnitDescriptorFromConfig(
12051205
persistenceUnitConfig.multitenantSchemaDatasource.orElse(null),
12061206
xmlMappings,
12071207
persistenceUnitConfig.unsupportedProperties,
1208-
hibernateOrmConfig.databaseOrmCompatibilityVersion,
1208+
hibernateOrmConfig.database.ormCompatibilityVersion,
12091209
false, false));
12101210
}
12111211

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

0 commit comments

Comments
 (0)