HHH-11473 - Refactor MySQLDialect

- move storage engine resolving into constructor
This commit is contained in:
Andrea Boriero 2017-02-23 19:23:07 +00:00 committed by Vlad Mihalcea
parent 39c04f14ae
commit f3dafb3205
1 changed files with 23 additions and 23 deletions

View File

@ -46,6 +46,7 @@ import org.hibernate.type.StandardBasicTypes;
public class MySQLDialect extends Dialect { public class MySQLDialect extends Dialect {
private final UniqueDelegate uniqueDelegate; private final UniqueDelegate uniqueDelegate;
private MySQLStorageEngine storageEngine;
private static final LimitHandler LIMIT_HANDLER = new AbstractLimitHandler() { private static final LimitHandler LIMIT_HANDLER = new AbstractLimitHandler() {
@Override @Override
@ -65,6 +66,24 @@ public class MySQLDialect extends Dialect {
*/ */
public MySQLDialect() { public MySQLDialect() {
super(); super();
String storageEngine = Environment.getProperties().getProperty( Environment.STORAGE_ENGINE );
if(storageEngine == null) {
storageEngine = System.getProperty( Environment.STORAGE_ENGINE );
}
if(storageEngine == null) {
this.storageEngine = getDefaultMySQLStorageEngine();
}
else if( "innodb".equals( storageEngine.toLowerCase() ) ) {
this.storageEngine = InnoDBStorageEngine.INSTANCE;
}
else if( "myisam".equals( storageEngine.toLowerCase() ) ) {
this.storageEngine = MyISAMStorageEngine.INSTANCE;
}
else {
throw new UnsupportedOperationException( "The " + storageEngine + " storage engine is not supported!" );
}
registerColumnType( Types.BIT, "bit" ); registerColumnType( Types.BIT, "bit" );
registerColumnType( Types.BIGINT, "bigint" ); registerColumnType( Types.BIGINT, "bigint" );
registerColumnType( Types.SMALLINT, "smallint" ); registerColumnType( Types.SMALLINT, "smallint" );
@ -539,12 +558,12 @@ public class MySQLDialect extends Dialect {
@Override @Override
public boolean supportsCascadeDelete() { public boolean supportsCascadeDelete() {
return getMySQLStorageEngine().supportsCascadeDelete(); return storageEngine.supportsCascadeDelete();
} }
@Override @Override
public String getTableTypeString() { public String getTableTypeString() {
return getMySQLStorageEngine().getTableTypeString(getEngineKeyword()); return storageEngine.getTableTypeString( getEngineKeyword());
} }
protected String getEngineKeyword() { protected String getEngineKeyword() {
@ -553,31 +572,12 @@ public class MySQLDialect extends Dialect {
@Override @Override
public boolean hasSelfReferentialForeignKeyBug() { public boolean hasSelfReferentialForeignKeyBug() {
return getMySQLStorageEngine().hasSelfReferentialForeignKeyBug(); return storageEngine.hasSelfReferentialForeignKeyBug();
} }
@Override @Override
public boolean dropConstraints() { public boolean dropConstraints() {
return getMySQLStorageEngine().dropConstraints(); return storageEngine.dropConstraints();
}
protected MySQLStorageEngine getMySQLStorageEngine() {
String storageEngine = Environment.getProperties().getProperty( Environment.STORAGE_ENGINE );
if(storageEngine == null) {
storageEngine = System.getProperty( Environment.STORAGE_ENGINE );
}
if(storageEngine == null) {
return getDefaultMySQLStorageEngine();
}
if( "innodb".equals( storageEngine.toLowerCase() ) ) {
return InnoDBStorageEngine.INSTANCE;
}
else if( "myisam".equals( storageEngine.toLowerCase() ) ) {
return MyISAMStorageEngine.INSTANCE;
}
else {
throw new UnsupportedOperationException( "The " + storageEngine + " storage engine is not supported!" );
}
} }
protected MySQLStorageEngine getDefaultMySQLStorageEngine() { protected MySQLStorageEngine getDefaultMySQLStorageEngine() {