Skip to content

Commit 6eb9e8b

Browse files
committed
Simplify inference of the SupportedDbKind
We used to try to derive it from the dbKind string, falling back to attempting to interpret the Hibernate ORM "DB Product Name". But the "DB Product Name" can only be set in situation where *we have a dbKind string already*, so the fallback is pointless. Since the fallback also has problems (use of CommunityDatabase which is not necessarily in the classpath), we might as well remove it.
1 parent 9033cfe commit 6eb9e8b

File tree

1 file changed

+3
-41
lines changed

1 file changed

+3
-41
lines changed

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

Lines changed: 3 additions & 41 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;
@@ -114,6 +112,9 @@ public static Optional<SupportedDatabaseKind> setDialectAndStorageEngine(
114112
for (DatabaseKindDialectBuildItem item : dbKindDialectBuildItems) {
115113
if (dbKind.isPresent() && DatabaseKind.is(dbKind.get(), item.getDbKind())
116114
|| explicitDialect.isPresent() && item.getMatchingDialects().contains(explicitDialect.get())) {
115+
if (dbKind.isEmpty()) {
116+
dbKind = Optional.ofNullable(item.getDbKind());
117+
}
117118
dbProductName = item.getDatabaseProductName();
118119
if (dbProductName.isEmpty() && explicitDialect.isEmpty()) {
119120
dialect = item.getDialectOptional();
@@ -145,9 +146,6 @@ public static Optional<SupportedDatabaseKind> setDialectAndStorageEngine(
145146
}
146147

147148
Optional<SupportedDatabaseKind> supportedDbKind = dbKind.flatMap(SupportedDatabaseKind::from);
148-
if (supportedDbKind.isEmpty()) {
149-
supportedDbKind = supportedDatabaseKindFromProductName(dbProductName);
150-
}
151149

152150
handleDialectSpecificSettings(
153151
persistenceUnitName,
@@ -216,42 +214,6 @@ private static void handleDialectSpecificSettings(
216214
}
217215
}
218216

219-
private static Optional<SupportedDatabaseKind> supportedDatabaseKindFromProductName(
220-
Optional<String> dbProductNameOptional) {
221-
222-
return dbProductNameOptional
223-
.filter(s -> !s.isEmpty())
224-
.flatMap(dbProductName -> {
225-
226-
if (Database.DB2.productNameMatches(dbProductName)) {
227-
return Optional.of(SupportedDatabaseKind.DB2);
228-
}
229-
if (CommunityDatabase.DERBY.productNameMatches(dbProductName)) {
230-
return Optional.of(SupportedDatabaseKind.DERBY);
231-
}
232-
if (Database.H2.productNameMatches(dbProductName)) {
233-
return Optional.of(SupportedDatabaseKind.H2);
234-
}
235-
if (Database.MARIADB.productNameMatches(dbProductName)) {
236-
return Optional.of(SupportedDatabaseKind.MARIADB);
237-
}
238-
if (Database.MYSQL.productNameMatches(dbProductName)) {
239-
return Optional.of(SupportedDatabaseKind.MYSQL);
240-
}
241-
if (Database.ORACLE.productNameMatches(dbProductName)) {
242-
return Optional.of(SupportedDatabaseKind.ORACLE);
243-
}
244-
if (Database.POSTGRESQL.productNameMatches(dbProductName)) {
245-
return Optional.of(SupportedDatabaseKind.POSTGRESQL);
246-
}
247-
if (Database.SQLSERVER.productNameMatches(dbProductName)) {
248-
return Optional.of(SupportedDatabaseKind.MSSQL);
249-
}
250-
return Optional.empty();
251-
252-
});
253-
}
254-
255217
private static void handleStorageEngine(
256218
Optional<SupportedDatabaseKind> supportedDatabaseKind,
257219
String persistenceUnitName,

0 commit comments

Comments
 (0)