77import static org .hibernate .cfg .AvailableSettings .USE_DIRECT_REFERENCE_CACHE_ENTRIES ;
88import static org .hibernate .cfg .AvailableSettings .USE_QUERY_CACHE ;
99import static org .hibernate .cfg .AvailableSettings .USE_SECOND_LEVEL_CACHE ;
10- import static org .hibernate .cfg .DialectSpecificSettings .COCKROACH_VERSION_STRING ;
11- import static org .hibernate .cfg .DialectSpecificSettings .HANA_MAX_LOB_PREFETCH_SIZE ;
1210import static org .hibernate .cfg .DialectSpecificSettings .MYSQL_BYTES_PER_CHARACTER ;
1311import static org .hibernate .cfg .DialectSpecificSettings .MYSQL_NO_BACKSLASH_ESCAPES ;
1412import static org .hibernate .cfg .DialectSpecificSettings .ORACLE_APPLICATION_CONTINUITY ;
1513import static org .hibernate .cfg .DialectSpecificSettings .ORACLE_AUTONOMOUS_DATABASE ;
1614import static org .hibernate .cfg .DialectSpecificSettings .ORACLE_EXTENDED_STRING_SIZE ;
1715import static org .hibernate .cfg .DialectSpecificSettings .SQL_SERVER_COMPATIBILITY_LEVEL ;
18- import static org .hibernate .cfg .DialectSpecificSettings .SYBASE_ANSI_NULL ;
1916
2017import java .io .IOException ;
2118import java .net .URL ;
@@ -1210,105 +1207,101 @@ private static void handleDialectSpecificSettings(
12101207 Optional <String > dbKind ,
12111208 Optional <String > dialect ) {
12121209
1213- final Optional <SupportedDatabaseKind > databaseKind = determineDatabaseKind ( dbKind , dialect );
1210+ final Optional <SupportedDatabaseKind > databaseKind = determineDatabaseKind (dbKind , dialect );
12141211
1215- handleStorageEngine ( databaseKind , persistenceUnitName , dialectConfig , storageEngineCollector ,
1216- puPropertiesCollector , systemProperties );
1212+ handleStorageEngine (databaseKind , persistenceUnitName , dialectConfig , storageEngineCollector ,
1213+ puPropertiesCollector , systemProperties );
12171214
1218- if ( dialectConfig .mariadb ().bytesPerCharacter ().isPresent ()
1219- || dialectConfig .mariadb ().noBackslashEscapes ().isPresent () ) {
1220- if ( databaseKind .isPresent () && databaseKind .get () != SupportedDatabaseKind .MARIADB ) {
1221- LOG .warnf ( "MariaDB specific settings being ignored because the database is not MariaDB." );
1222- }
1223- else {
1215+ if (dialectConfig .mariadb ().bytesPerCharacter ().isPresent ()
1216+ || dialectConfig .mariadb ().noBackslashEscapes ().isPresent ()) {
1217+ if (databaseKind .isPresent () && databaseKind .get () != SupportedDatabaseKind .MARIADB ) {
1218+ LOG .warnf ("MariaDB specific settings being ignored because the database is not MariaDB." );
1219+ } else {
12241220 applyOptionalIntegerSetting (dialectConfig .mariadb ().bytesPerCharacter (), MYSQL_BYTES_PER_CHARACTER ,
1225- puPropertiesCollector );
1221+ puPropertiesCollector );
12261222 applyOptionalBooleanSetting (dialectConfig .mariadb ().noBackslashEscapes (), MYSQL_NO_BACKSLASH_ESCAPES ,
1227- puPropertiesCollector );
1223+ puPropertiesCollector );
12281224 }
12291225 }
12301226
1231- if ( dialectConfig .mysql ().bytesPerCharacter ().isPresent ()
1232- || dialectConfig .mysql ().noBackslashEscapes ().isPresent () ) {
1233- if ( databaseKind .isPresent () && databaseKind .get () != SupportedDatabaseKind .MYSQL ) {
1234- LOG .warnf ( "MariaDB specific settings being ignored because the database is not MySQL." );
1235- }
1236- else {
1227+ if (dialectConfig .mysql ().bytesPerCharacter ().isPresent ()
1228+ || dialectConfig .mysql ().noBackslashEscapes ().isPresent ()) {
1229+ if (databaseKind .isPresent () && databaseKind .get () != SupportedDatabaseKind .MYSQL ) {
1230+ LOG .warnf ("MariaDB specific settings being ignored because the database is not MySQL." );
1231+ } else {
12371232 applyOptionalIntegerSetting (dialectConfig .mysql ().bytesPerCharacter (), MYSQL_BYTES_PER_CHARACTER ,
1238- puPropertiesCollector );
1233+ puPropertiesCollector );
12391234 applyOptionalBooleanSetting (dialectConfig .mysql ().noBackslashEscapes (), MYSQL_NO_BACKSLASH_ESCAPES ,
1240- puPropertiesCollector );
1235+ puPropertiesCollector );
12411236 }
12421237 }
12431238
1244- if ( dialectConfig .oracle ().isAnyPropertySet () ) {
1245- if ( databaseKind .isPresent () && databaseKind .get () != SupportedDatabaseKind .ORACLE ) {
1246- LOG .warnf ( "Oracle specific settings being ignored because the database is not Oracle." );
1247- }
1248- else {
1239+ if (dialectConfig .oracle ().isAnyPropertySet ()) {
1240+ if (databaseKind .isPresent () && databaseKind .get () != SupportedDatabaseKind .ORACLE ) {
1241+ LOG .warnf ("Oracle specific settings being ignored because the database is not Oracle." );
1242+ } else {
12491243 applyOptionalBooleanSetting (dialectConfig .oracle ().applicationContinuity (), ORACLE_APPLICATION_CONTINUITY ,
1250- puPropertiesCollector );
1244+ puPropertiesCollector );
12511245 applyOptionalBooleanSetting (dialectConfig .oracle ().autonomous (), ORACLE_AUTONOMOUS_DATABASE ,
1252- puPropertiesCollector );
1246+ puPropertiesCollector );
12531247 applyOptionalBooleanSetting (dialectConfig .oracle ().extended (), ORACLE_EXTENDED_STRING_SIZE ,
1254- puPropertiesCollector );
1248+ puPropertiesCollector );
12551249 }
12561250 }
12571251
1258- if ( dialectConfig .mssql ().isAnyPropertySet () ) {
1259- if ( databaseKind .isPresent () && databaseKind .get () != SupportedDatabaseKind .MSSQL ) {
1260- LOG .warnf ( "SQL Server specific settings being ignored because the database is not SQL Server." );
1261- }
1262- else {
1263- applyOptionalStringSetting ( dialectConfig .mssql ().compatibilityLevel (), SQL_SERVER_COMPATIBILITY_LEVEL ,
1264- puPropertiesCollector );
1252+ if (dialectConfig .mssql ().isAnyPropertySet ()) {
1253+ if (databaseKind .isPresent () && databaseKind .get () != SupportedDatabaseKind .MSSQL ) {
1254+ LOG .warnf ("SQL Server specific settings being ignored because the database is not SQL Server." );
1255+ } else {
1256+ applyOptionalStringSetting (dialectConfig .mssql ().compatibilityLevel (), SQL_SERVER_COMPATIBILITY_LEVEL ,
1257+ puPropertiesCollector );
12651258 }
12661259 }
12671260 }
12681261
12691262 private static Optional <SupportedDatabaseKind > determineDatabaseKind (Optional <String > dbKind , Optional <String > dialect ) {
1270- if ( dbKind .isPresent () ) {
1271- final String databaseKindName = DatabaseKind .normalize ( dbKind .get () );
1272- final SupportedDatabaseKind resolved = determineDatabaseKind ( databaseKindName );
1273- if ( resolved != null ) {
1274- return Optional .of ( resolved );
1263+ if (dbKind .isPresent ()) {
1264+ final String databaseKindName = DatabaseKind .normalize (dbKind .get ());
1265+ final SupportedDatabaseKind resolved = determineDatabaseKind (databaseKindName );
1266+ if (resolved != null ) {
1267+ return Optional .of (resolved );
12751268 }
12761269 }
12771270
1278- if ( dialect .isPresent () ) {
1271+ if (dialect .isPresent ()) {
12791272 String lowercaseDialect = dialect .get ().toLowerCase (Locale .ROOT );
1280- final SupportedDatabaseKind resolved = determineDatabaseKind ( lowercaseDialect );
1281- if ( resolved != null ) {
1282- return Optional .of ( resolved );
1273+ final SupportedDatabaseKind resolved = determineDatabaseKind (lowercaseDialect );
1274+ if (resolved != null ) {
1275+ return Optional .of (resolved );
12831276 }
12841277 }
12851278
12861279 return Optional .empty ();
12871280 }
12881281
12891282 private static SupportedDatabaseKind determineDatabaseKind (String name ) {
1290- if ( name .contains ( "db2" ) ) {
1283+ if (name .contains ("db2" ) ) {
12911284 return SupportedDatabaseKind .DB2 ;
12921285 }
1293- if ( name .contains ( "derby" ) ) {
1286+ if (name .contains ("derby" ) ) {
12941287 return SupportedDatabaseKind .DERBY ;
12951288 }
1296- if ( name .contains ( "h2" ) ) {
1289+ if (name .contains ("h2" ) ) {
12971290 return SupportedDatabaseKind .H2 ;
12981291 }
1299- if ( name .contains ( "mariadb" ) ) {
1292+ if (name .contains ("mariadb" ) ) {
13001293 return SupportedDatabaseKind .MARIADB ;
13011294 }
1302- if ( name .contains ( "mssql" ) || name .contains ( "sqlserver" ) ) {
1295+ if (name .contains ("mssql" ) || name .contains ("sqlserver" ) ) {
13031296 return SupportedDatabaseKind .MSSQL ;
13041297 }
1305- if ( name .contains ( "mysql" ) ) {
1298+ if (name .contains ("mysql" ) ) {
13061299 return SupportedDatabaseKind .MYSQL ;
13071300 }
1308- if ( name .contains ( "oracle" ) ) {
1301+ if (name .contains ("oracle" ) ) {
13091302 return SupportedDatabaseKind .ORACLE ;
13101303 }
1311- if ( name .contains ( "postgresql" ) ) {
1304+ if (name .contains ("postgresql" ) ) {
13121305 return SupportedDatabaseKind .POSTGRESQL ;
13131306 }
13141307
@@ -1323,63 +1316,58 @@ private static void handleStorageEngine(
13231316 BiConsumer <String , String > puPropertiesCollector ,
13241317 BuildProducer <SystemPropertyBuildItem > systemProperties ) {
13251318
1326- final String topLevelStorageEngine = dialectConfig .storageEngine ().orElse ( null );
1319+ final String topLevelStorageEngine = dialectConfig .storageEngine ().orElse (null );
13271320
1328- if ( topLevelStorageEngine != null ) {
1321+ if (topLevelStorageEngine != null ) {
13291322 // NOTE: this top-level storage-engine setting is deprecated - log a warning
13301323 LOG .warnf (
13311324 "The storage engine set through configuration property '%1$s' is no longer supported; "
13321325 + "use '%1$s' or '%1$s' instead, depending on the database." ,
1333- HibernateOrmRuntimeConfig .puPropertyKey ( persistenceUnitName , "dialect.mariadb.storage-engine" ),
1334- HibernateOrmRuntimeConfig .puPropertyKey ( persistenceUnitName , "dialect.mysql.storage-engine" )
1335- );
1326+ HibernateOrmRuntimeConfig .puPropertyKey (persistenceUnitName , "dialect.mariadb.storage-engine" ),
1327+ HibernateOrmRuntimeConfig .puPropertyKey (persistenceUnitName , "dialect.mysql.storage-engine" ));
13361328 }
13371329
13381330 // if we know this is mariadb and any non-mariadb settings are set, ...
13391331 // todo : what? log a warning? exception?
13401332
1341- final String mariaDbStorageEngine = dialectConfig .mariadb ().storageEngine ().orElse ( topLevelStorageEngine );
1342- final String mysqlDbStorageEngine = dialectConfig .mysql ().storageEngine ().orElse ( topLevelStorageEngine );
1343- if ( supportedDatabaseKind .isPresent () && supportedDatabaseKind .get () == SupportedDatabaseKind .MARIADB ) {
1344- if ( mariaDbStorageEngine != null ) {
1333+ final String mariaDbStorageEngine = dialectConfig .mariadb ().storageEngine ().orElse (topLevelStorageEngine );
1334+ final String mysqlDbStorageEngine = dialectConfig .mysql ().storageEngine ().orElse (topLevelStorageEngine );
1335+ if (supportedDatabaseKind .isPresent () && supportedDatabaseKind .get () == SupportedDatabaseKind .MARIADB ) {
1336+ if (mariaDbStorageEngine != null ) {
13451337 storageEngineCollector .add (mariaDbStorageEngine );
13461338 systemProperties .produce (new SystemPropertyBuildItem (AvailableSettings .STORAGE_ENGINE , mariaDbStorageEngine ));
13471339 }
1348- }
1349- else if ( supportedDatabaseKind .isPresent () && supportedDatabaseKind .get () == SupportedDatabaseKind .MYSQL ) {
1350- if ( mysqlDbStorageEngine != null ) {
1340+ } else if (supportedDatabaseKind .isPresent () && supportedDatabaseKind .get () == SupportedDatabaseKind .MYSQL ) {
1341+ if (mysqlDbStorageEngine != null ) {
13511342 storageEngineCollector .add (mysqlDbStorageEngine );
13521343 systemProperties .produce (new SystemPropertyBuildItem (AvailableSettings .STORAGE_ENGINE , mysqlDbStorageEngine ));
13531344 }
1354- }
1355- else {
1345+ } else {
13561346 final String storageEngine ;
13571347 final String storageEngineSource ;
1358- if ( topLevelStorageEngine != null ) {
1348+ if (topLevelStorageEngine != null ) {
13591349 storageEngine = topLevelStorageEngine ;
13601350 storageEngineSource = HibernateOrmRuntimeConfig .puPropertyKey (persistenceUnitName , "dialect.storage-engine" );
1361- }
1362- else if ( mariaDbStorageEngine != null ) {
1351+ } else if (mariaDbStorageEngine != null ) {
13631352 storageEngine = mariaDbStorageEngine ;
1364- storageEngineSource = HibernateOrmRuntimeConfig .puPropertyKey (persistenceUnitName , "dialect.mariadb.storage-engine" );
1365- }
1366- else if ( mysqlDbStorageEngine != null ) {
1353+ storageEngineSource = HibernateOrmRuntimeConfig .puPropertyKey (persistenceUnitName ,
1354+ "dialect.mariadb.storage-engine" );
1355+ } else if (mysqlDbStorageEngine != null ) {
13671356 storageEngine = mysqlDbStorageEngine ;
1368- storageEngineSource = HibernateOrmRuntimeConfig .puPropertyKey (persistenceUnitName , "dialect.mysql.storage-engine" );
1369- }
1370- else {
1357+ storageEngineSource = HibernateOrmRuntimeConfig .puPropertyKey (persistenceUnitName ,
1358+ "dialect.mysql.storage-engine" );
1359+ } else {
13711360 storageEngine = null ;
13721361 storageEngineSource = null ;
13731362 }
13741363
1375- if ( storageEngine != null ) {
1376- if ( supportedDatabaseKind .isPresent () ) {
1364+ if (storageEngine != null ) {
1365+ if (supportedDatabaseKind .isPresent ()) {
13771366 LOG .warnf (
13781367 "The storage engine set through configuration property '%1$s', is being ignored"
13791368 + " because the database is neither MySQL nor MariaDB." ,
13801369 storageEngineSource );
1381- }
1382- else {
1370+ } else {
13831371 systemProperties .produce (new SystemPropertyBuildItem (AvailableSettings .STORAGE_ENGINE , storageEngine ));
13841372 }
13851373 }
0 commit comments