Skip to content

Commit ecfa8cb

Browse files
authored
Merge pull request #50146 from yrodiere/i50141
Simplify inference of the SupportedDbKind and avoid NoClassDefFoundError on `CommunityDatabase`
2 parents 537dc79 + 6eb9e8b commit ecfa8cb

File tree

3 files changed

+10
-62
lines changed

3 files changed

+10
-62
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,6 @@ private static Optional<DatabaseKind.SupportedDatabaseKind> collectDialectConfig
10561056
explicitDbMinVersion,
10571057
dialectConfig,
10581058
dbKindMetadataBuildItems,
1059-
persistenceUnitConfig.dialect().storageEngine(),
10601059
systemProperties,
10611060
puPropertiesCollector,
10621061
storageEngineCollector);

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

Lines changed: 10 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import jakarta.persistence.ValidationMode;
2727

2828
import org.hibernate.cfg.AvailableSettings;
29-
import org.hibernate.community.dialect.CommunityDatabase;
30-
import org.hibernate.dialect.Database;
3129
import org.hibernate.id.SequenceMismatchStrategy;
3230
import org.hibernate.jpa.boot.spi.JpaSettings;
3331
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
@@ -103,7 +101,6 @@ public static Optional<SupportedDatabaseKind> setDialectAndStorageEngine(
103101
Optional<String> explicitDbMinVersion,
104102
HibernateOrmConfigPersistenceUnit.HibernateOrmConfigPersistenceUnitDialect dialectConfig,
105103
List<DatabaseKindDialectBuildItem> dbKindDialectBuildItems,
106-
Optional<String> storageEngine,
107104
BuildProducer<SystemPropertyBuildItem> systemProperties,
108105
BiConsumer<String, String> puPropertiesCollector,
109106
Set<String> storageEngineCollector) {
@@ -115,6 +112,9 @@ public static Optional<SupportedDatabaseKind> setDialectAndStorageEngine(
115112
for (DatabaseKindDialectBuildItem item : dbKindDialectBuildItems) {
116113
if (dbKind.isPresent() && DatabaseKind.is(dbKind.get(), item.getDbKind())
117114
|| explicitDialect.isPresent() && item.getMatchingDialects().contains(explicitDialect.get())) {
115+
if (dbKind.isEmpty()) {
116+
dbKind = Optional.ofNullable(item.getDbKind());
117+
}
118118
dbProductName = item.getDatabaseProductName();
119119
if (dbProductName.isEmpty() && explicitDialect.isEmpty()) {
120120
dialect = item.getDialectOptional();
@@ -145,29 +145,26 @@ public static Optional<SupportedDatabaseKind> setDialectAndStorageEngine(
145145
puPropertiesCollector.accept(AvailableSettings.JAKARTA_HBM2DDL_DB_VERSION, dbProductVersion.get());
146146
}
147147

148-
Optional<SupportedDatabaseKind> supportedDatabaseKind = handleDialectSpecificSettings(
148+
Optional<SupportedDatabaseKind> supportedDbKind = dbKind.flatMap(SupportedDatabaseKind::from);
149+
150+
handleDialectSpecificSettings(
149151
persistenceUnitName,
150152
systemProperties,
151153
puPropertiesCollector,
152154
storageEngineCollector,
153155
dialectConfig,
154-
dbKind,
155-
dbProductName);
156+
supportedDbKind);
156157

157-
return supportedDatabaseKind;
158+
return supportedDbKind;
158159
}
159160

160-
private static Optional<SupportedDatabaseKind> handleDialectSpecificSettings(
161+
private static void handleDialectSpecificSettings(
161162
String persistenceUnitName,
162163
BuildProducer<SystemPropertyBuildItem> systemProperties,
163164
BiConsumer<String, String> puPropertiesCollector,
164165
Set<String> storageEngineCollector,
165166
HibernateOrmConfigPersistenceUnit.HibernateOrmConfigPersistenceUnitDialect dialectConfig,
166-
Optional<String> dbKind,
167-
Optional<String> dbProductName) {
168-
169-
final Optional<SupportedDatabaseKind> databaseKind = determineDatabaseKind(dbKind, dbProductName);
170-
167+
Optional<SupportedDatabaseKind> databaseKind) {
171168
handleStorageEngine(databaseKind, persistenceUnitName, dialectConfig, storageEngineCollector,
172169
systemProperties);
173170

@@ -215,53 +212,6 @@ private static Optional<SupportedDatabaseKind> handleDialectSpecificSettings(
215212
puPropertiesCollector);
216213
}
217214
}
218-
219-
return databaseKind;
220-
}
221-
222-
private static Optional<SupportedDatabaseKind> determineDatabaseKind(
223-
Optional<String> dbKindOptional,
224-
Optional<String> dbProductNameOptional) {
225-
226-
Optional<SupportedDatabaseKind> supportedDatabaseKindFromDBKind = dbKindOptional.flatMap(SupportedDatabaseKind::from);
227-
228-
return supportedDatabaseKindFromDBKind.or(() -> supportedDatabaseKindFromProductName(dbProductNameOptional));
229-
}
230-
231-
private static Optional<SupportedDatabaseKind> supportedDatabaseKindFromProductName(
232-
Optional<String> dbProductNameOptional) {
233-
234-
return dbProductNameOptional
235-
.filter(s -> !s.isEmpty())
236-
.flatMap(dbProductName -> {
237-
238-
if (Database.DB2.productNameMatches(dbProductName)) {
239-
return Optional.of(SupportedDatabaseKind.DB2);
240-
}
241-
if (CommunityDatabase.DERBY.productNameMatches(dbProductName)) {
242-
return Optional.of(SupportedDatabaseKind.DERBY);
243-
}
244-
if (Database.H2.productNameMatches(dbProductName)) {
245-
return Optional.of(SupportedDatabaseKind.H2);
246-
}
247-
if (Database.MARIADB.productNameMatches(dbProductName)) {
248-
return Optional.of(SupportedDatabaseKind.MARIADB);
249-
}
250-
if (Database.MYSQL.productNameMatches(dbProductName)) {
251-
return Optional.of(SupportedDatabaseKind.MYSQL);
252-
}
253-
if (Database.ORACLE.productNameMatches(dbProductName)) {
254-
return Optional.of(SupportedDatabaseKind.ORACLE);
255-
}
256-
if (Database.POSTGRESQL.productNameMatches(dbProductName)) {
257-
return Optional.of(SupportedDatabaseKind.POSTGRESQL);
258-
}
259-
if (Database.SQLSERVER.productNameMatches(dbProductName)) {
260-
return Optional.of(SupportedDatabaseKind.MSSQL);
261-
}
262-
return Optional.empty();
263-
264-
});
265215
}
266216

267217
private static void handleStorageEngine(

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ private static QuarkusPersistenceUnitDescriptorWithSupportedDBKind generateReact
392392
explicitDbMinVersion,
393393
dialectConfig,
394394
dbKindDialectBuildItems,
395-
persistenceUnitConfig.dialect().storageEngine(),
396395
systemProperties,
397396
descriptor.getProperties()::setProperty,
398397
storageEngineCollector);

0 commit comments

Comments
 (0)