Skip to content

Commit

Permalink
minor code cleanups in MySQLDialect
Browse files Browse the repository at this point in the history
note: system properties are already included in Environment properties
  • Loading branch information
gavinking committed Jan 18, 2025
1 parent bb104e3 commit adf607a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.hibernate.PessimisticLockException;
import org.hibernate.boot.model.FunctionContributions;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.FetchSettings;
import org.hibernate.dialect.aggregate.AggregateSupport;
import org.hibernate.dialect.aggregate.MySQLAggregateSupport;
import org.hibernate.dialect.function.CommonFunctionFactory;
Expand Down Expand Up @@ -89,6 +91,7 @@
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
import static org.hibernate.internal.util.JdbcExceptionHelper.extractSqlState;
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
import static org.hibernate.internal.util.StringHelper.split;
import static org.hibernate.type.SqlTypes.BIGINT;
import static org.hibernate.type.SqlTypes.BINARY;
import static org.hibernate.type.SqlTypes.BIT;
Expand Down Expand Up @@ -217,7 +220,7 @@ protected static DatabaseVersion createVersion(DialectResolutionInfo info) {
protected static DatabaseVersion createVersion(DialectResolutionInfo info, DatabaseVersion defaultVersion) {
final String versionString = info.getDatabaseVersion();
if ( versionString != null ) {
final String[] components = StringHelper.split( ".-", versionString );
final String[] components = split( ".-", versionString );
if ( components.length >= 3 ) {
try {
final int majorVersion = parseInt( components[0] );
Expand All @@ -241,26 +244,19 @@ protected DatabaseVersion getMinimumSupportedVersion() {
@Override
protected void initDefaultProperties() {
super.initDefaultProperties();
getDefaultProperties().setProperty( Environment.MAX_FETCH_DEPTH, "2" );
getDefaultProperties().setProperty( FetchSettings.MAX_FETCH_DEPTH, "2" );
}

private MySQLStorageEngine createStorageEngine() {
String storageEngine = Environment.getProperties().getProperty( Environment.STORAGE_ENGINE );
if (storageEngine == null) {
storageEngine = System.getProperty( Environment.STORAGE_ENGINE );
}
if (storageEngine == null) {
return getDefaultMySQLStorageEngine();
}
else if( "innodb".equalsIgnoreCase( storageEngine ) ) {
return InnoDBStorageEngine.INSTANCE;
}
else if( "myisam".equalsIgnoreCase( storageEngine ) ) {
return MyISAMStorageEngine.INSTANCE;
}
else {
throw new UnsupportedOperationException( "The " + storageEngine + " storage engine is not supported" );
}
final String storageEngine = Environment.getProperties().getProperty( AvailableSettings.STORAGE_ENGINE );
return storageEngine == null
? getDefaultMySQLStorageEngine()
: switch ( storageEngine ) {
case "innodb" -> InnoDBStorageEngine.INSTANCE;
case "myisam" -> MyISAMStorageEngine.INSTANCE;
default -> throw new UnsupportedOperationException(
"The '" + storageEngine + "' storage engine is not supported" );
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public long getDefaultLobLength() {
private static boolean isAnsiNull(DialectResolutionInfo info) {
final DatabaseMetaData databaseMetaData = info.getDatabaseMetadata();
if ( databaseMetaData != null ) {
try (java.sql.Statement s = databaseMetaData.getConnection().createStatement() ) {
try ( java.sql.Statement s = databaseMetaData.getConnection().createStatement() ) {
final ResultSet rs = s.executeQuery( "SELECT @@options" );
if ( rs.next() ) {
final byte[] optionBytes = rs.getBytes( 1 );
Expand All @@ -223,7 +223,7 @@ private static boolean isAnsiNull(DialectResolutionInfo info) {
private int pageSize(DialectResolutionInfo info) {
final DatabaseMetaData databaseMetaData = info.getDatabaseMetadata();
if ( databaseMetaData != null ) {
try (java.sql.Statement s = databaseMetaData.getConnection().createStatement() ) {
try ( java.sql.Statement s = databaseMetaData.getConnection().createStatement() ) {
final ResultSet rs = s.executeQuery( "SELECT @@maxpagesize" );
if ( rs.next() ) {
return rs.getInt( 1 );
Expand Down

0 comments on commit adf607a

Please sign in to comment.