26
26
import jakarta .persistence .ValidationMode ;
27
27
28
28
import org .hibernate .cfg .AvailableSettings ;
29
- import org .hibernate .community .dialect .CommunityDatabase ;
30
- import org .hibernate .dialect .Database ;
31
29
import org .hibernate .id .SequenceMismatchStrategy ;
32
30
import org .hibernate .jpa .boot .spi .JpaSettings ;
33
31
import org .hibernate .jpa .boot .spi .PersistenceUnitDescriptor ;
@@ -103,7 +101,6 @@ public static Optional<SupportedDatabaseKind> setDialectAndStorageEngine(
103
101
Optional <String > explicitDbMinVersion ,
104
102
HibernateOrmConfigPersistenceUnit .HibernateOrmConfigPersistenceUnitDialect dialectConfig ,
105
103
List <DatabaseKindDialectBuildItem > dbKindDialectBuildItems ,
106
- Optional <String > storageEngine ,
107
104
BuildProducer <SystemPropertyBuildItem > systemProperties ,
108
105
BiConsumer <String , String > puPropertiesCollector ,
109
106
Set <String > storageEngineCollector ) {
@@ -115,6 +112,9 @@ public static Optional<SupportedDatabaseKind> setDialectAndStorageEngine(
115
112
for (DatabaseKindDialectBuildItem item : dbKindDialectBuildItems ) {
116
113
if (dbKind .isPresent () && DatabaseKind .is (dbKind .get (), item .getDbKind ())
117
114
|| explicitDialect .isPresent () && item .getMatchingDialects ().contains (explicitDialect .get ())) {
115
+ if (dbKind .isEmpty ()) {
116
+ dbKind = Optional .ofNullable (item .getDbKind ());
117
+ }
118
118
dbProductName = item .getDatabaseProductName ();
119
119
if (dbProductName .isEmpty () && explicitDialect .isEmpty ()) {
120
120
dialect = item .getDialectOptional ();
@@ -145,29 +145,26 @@ public static Optional<SupportedDatabaseKind> setDialectAndStorageEngine(
145
145
puPropertiesCollector .accept (AvailableSettings .JAKARTA_HBM2DDL_DB_VERSION , dbProductVersion .get ());
146
146
}
147
147
148
- Optional <SupportedDatabaseKind > supportedDatabaseKind = handleDialectSpecificSettings (
148
+ Optional <SupportedDatabaseKind > supportedDbKind = dbKind .flatMap (SupportedDatabaseKind ::from );
149
+
150
+ handleDialectSpecificSettings (
149
151
persistenceUnitName ,
150
152
systemProperties ,
151
153
puPropertiesCollector ,
152
154
storageEngineCollector ,
153
155
dialectConfig ,
154
- dbKind ,
155
- dbProductName );
156
+ supportedDbKind );
156
157
157
- return supportedDatabaseKind ;
158
+ return supportedDbKind ;
158
159
}
159
160
160
- private static Optional < SupportedDatabaseKind > handleDialectSpecificSettings (
161
+ private static void handleDialectSpecificSettings (
161
162
String persistenceUnitName ,
162
163
BuildProducer <SystemPropertyBuildItem > systemProperties ,
163
164
BiConsumer <String , String > puPropertiesCollector ,
164
165
Set <String > storageEngineCollector ,
165
166
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 ) {
171
168
handleStorageEngine (databaseKind , persistenceUnitName , dialectConfig , storageEngineCollector ,
172
169
systemProperties );
173
170
@@ -215,53 +212,6 @@ private static Optional<SupportedDatabaseKind> handleDialectSpecificSettings(
215
212
puPropertiesCollector );
216
213
}
217
214
}
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
- });
265
215
}
266
216
267
217
private static void handleStorageEngine (
0 commit comments