HHH-13304 MySQLDialect shouldn't access System Properties

This commit is contained in:
Sanne Grinovero 2019-03-05 22:12:11 +00:00
parent d353a10382
commit 271bf2d4cd
2 changed files with 17 additions and 14 deletions

View File

@ -46,7 +46,7 @@ import org.hibernate.type.StandardBasicTypes;
public class MySQLDialect extends Dialect {
private final UniqueDelegate uniqueDelegate;
private MySQLStorageEngine storageEngine;
private final MySQLStorageEngine storageEngine;
private static final LimitHandler LIMIT_HANDLER = new AbstractLimitHandler() {
@Override
@ -68,9 +68,6 @@ public class MySQLDialect extends Dialect {
super();
String storageEngine = Environment.getProperties().getProperty( Environment.STORAGE_ENGINE );
if(storageEngine == null) {
storageEngine = System.getProperty( Environment.STORAGE_ENGINE );
}
if ( storageEngine == null ) {
this.storageEngine = getDefaultMySQLStorageEngine();
}
@ -81,7 +78,7 @@ public class MySQLDialect extends Dialect {
this.storageEngine = MyISAMStorageEngine.INSTANCE;
}
else {
throw new UnsupportedOperationException( "The " + storageEngine + " storage engine is not supported!" );
throw new UnsupportedOperationException( "The storage engine '" + storageEngine + "' is not supported!" );
}
registerColumnType( Types.BIT, "bit" );

View File

@ -7,6 +7,7 @@
package org.hibernate.test.dialect.unit.lockhint;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.MySQL57Dialect;
import org.hibernate.testing.junit4.BaseUnitTestCase;
@ -15,11 +16,12 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
/**
* @author Vlad Mihalcea
*/
import java.lang.reflect.Field;
import java.util.Properties;
public class MySQLStorageEngineTest extends BaseUnitTestCase {
@Test
@ -28,19 +30,23 @@ public class MySQLStorageEngineTest extends BaseUnitTestCase {
}
@Test
public void testOverrideStorage() {
String previousValue = System.setProperty( AvailableSettings.STORAGE_ENGINE, "myisam" );
public void testOverrideStorage() throws NoSuchFieldException, IllegalAccessException {
final Field globalPropertiesField = Environment.class.getDeclaredField( "GLOBAL_PROPERTIES" );
globalPropertiesField.setAccessible( true );
final Properties systemProperties = (Properties) globalPropertiesField.get( null );
assertNotNull( systemProperties );
final Object previousValue = systemProperties.setProperty( AvailableSettings.STORAGE_ENGINE, "myisam" );
try {
assertEquals( " engine=MyISAM", new MySQL57Dialect().getTableTypeString() );
}
finally {
if ( previousValue != null ) {
System.setProperty( AvailableSettings.STORAGE_ENGINE, previousValue );
systemProperties.setProperty( AvailableSettings.STORAGE_ENGINE, previousValue.toString() );
}
else {
System.clearProperty( AvailableSettings.STORAGE_ENGINE );
assertThat( System.getProperty( AvailableSettings.STORAGE_ENGINE ), is( nullValue() ) );
systemProperties.remove( AvailableSettings.STORAGE_ENGINE );
}
}
}
}