From d82b3369ff6d64007fe589bdbc3ed102f05e51a1 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 17 Feb 2017 11:45:22 +0000 Subject: [PATCH 0001/1886] 5.2.8 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c2c0b8165ce7..48e67eeee5e6 100644 --- a/build.gradle +++ b/build.gradle @@ -58,7 +58,7 @@ allprojects { } ext { - hibernateTargetVersion = '5.2.8.Final' + hibernateTargetVersion = '5.2.9-SNAPSHOT' expectedGradleVersion = '3.2.1' baselineJavaVersion = '1.8' From 2b79644b633634249ac7ce2d122b07acbb7f9096 Mon Sep 17 00:00:00 2001 From: Vlad Mihalcea Date: Thu, 9 Feb 2017 15:14:30 +0200 Subject: [PATCH 0002/1886] HHH-11473 - Refactor MySQL Dialects --- databases.gradle | 2 +- .../chapters/query/spatial/Spatial.adoc | 6 +- etc/hibernate.properties.template | 2 - .../internal/StrategySelectorBuilder.java | 2 + .../org/hibernate/cfg/AvailableSettings.java | 9 +++ .../java/org/hibernate/dialect/Dialect.java | 1 - .../dialect/InnoDBStorageEngine.java | 31 ++++++++ .../org/hibernate/dialect/MariaDBDialect.java | 2 +- .../dialect/MyISAMStorageEngine.java | 31 ++++++++ .../org/hibernate/dialect/MySQL55Dialect.java | 20 +++++ .../org/hibernate/dialect/MySQL57Dialect.java | 76 +++++++++++++++++++ .../dialect/MySQL57InnoDBDialect.java | 2 + .../org/hibernate/dialect/MySQL5Dialect.java | 10 ++- .../dialect/MySQL5InnoDBDialect.java | 2 + .../org/hibernate/dialect/MySQLDialect.java | 52 +++++++++++-- .../hibernate/dialect/MySQLInnoDBDialect.java | 2 + .../hibernate/dialect/MySQLMyISAMDialect.java | 2 + .../hibernate/dialect/MySQLStorageEngine.java | 17 +++++ .../test/annotations/EntityTest.java | 67 ++++++++-------- ...ySQLDropConstraintThrowsExceptionTest.java | 4 +- .../unit/lockhint/MySQLStorageEngineTest.java | 39 ++++++++++ .../MySQL57TimestampFspFunctionTest.java | 5 +- .../MySQL57TimestampPropertyTest.java | 4 +- .../ValidityAuditStrategyRevEndTsTest.java | 4 +- .../resources/hibernate.test.session-cfg.xml | 2 +- .../mysql/MySQL56InnoDBSpatialDialect.java | 2 + .../dialect/mysql/MySQL56SpatialDialect.java | 4 +- .../mysql/MySQL5InnoDBSpatialDialect.java | 3 +- 28 files changed, 342 insertions(+), 61 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/dialect/InnoDBStorageEngine.java create mode 100644 hibernate-core/src/main/java/org/hibernate/dialect/MyISAMStorageEngine.java create mode 100644 hibernate-core/src/main/java/org/hibernate/dialect/MySQL55Dialect.java create mode 100644 hibernate-core/src/main/java/org/hibernate/dialect/MySQL57Dialect.java create mode 100644 hibernate-core/src/main/java/org/hibernate/dialect/MySQLStorageEngine.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/dialect/unit/lockhint/MySQLStorageEngineTest.java diff --git a/databases.gradle b/databases.gradle index 21b161865f4d..ea2ed8de50ce 100644 --- a/databases.gradle +++ b/databases.gradle @@ -38,7 +38,7 @@ ext { 'jdbc.url' : 'jdbc:postgresql:hibernate_orm_test' ], mysql : [ - 'db.dialect' : 'org.hibernate.dialect.MySQL57InnoDBDialect', + 'db.dialect' : 'org.hibernate.dialect.MySQL57Dialect', 'jdbc.driver': 'com.mysql.jdbc.Driver', 'jdbc.user' : 'hibernateormtest', 'jdbc.pass' : 'hibernateormtest', diff --git a/documentation/src/main/asciidoc/userguide/chapters/query/spatial/Spatial.adoc b/documentation/src/main/asciidoc/userguide/chapters/query/spatial/Spatial.adoc index 2d830ac9c555..b3a24dbcd975 100644 --- a/documentation/src/main/asciidoc/userguide/chapters/query/spatial/Spatial.adoc +++ b/documentation/src/main/asciidoc/userguide/chapters/query/spatial/Spatial.adoc @@ -137,12 +137,8 @@ There are several dialects for MySQL: `MySQLSpatialDialect`::: a spatially-extended version of Hibernate `MySQLDialect` -`MySQLSpatialInnoDBDialect`::: - a spatially-extended version of Hibernate `MySQLInnoDBDialect` `MySQLSpatial56Dialect`::: a spatially-extended version of Hibernate `MySQL5DBDialect`. -`MySQLSpatial5InnoDBDialect`::: - the same as `MySQLSpatial56Dialect`, but with support for the InnoDB storage engine. [NOTE] ==== @@ -150,7 +146,7 @@ MySQL versions before 5.6.1 had only limited support for spatial operators. Most operators only took account of the minimum bounding rectangles (MBR) of the geometries, and not the geometries themselves. This changed in version 5.6.1 were MySQL introduced `ST_*` spatial operators. -The dialects `MySQLSpatial56Dialect` and `MySQLSpatial5InnoDBDialect` use these newer, more precise operators. +The dialect `MySQLSpatial56Dialect` uses these newer, more precise operators. These dialects may therefore produce results that differ from that of the other spatial dialects. diff --git a/etc/hibernate.properties.template b/etc/hibernate.properties.template index 2df7e5eee8d7..51438e21b6f3 100644 --- a/etc/hibernate.properties.template +++ b/etc/hibernate.properties.template @@ -43,8 +43,6 @@ hibernate.connection.url @DB_URL@ #hibernate.dialect org.hibernate.dialect.MySQLDialect -#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect -#hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect #hibernate.connection.driver_class org.gjt.mm.mysql.Driver #hibernate.connection.driver_class com.mysql.jdbc.Driver #hibernate.connection.url jdbc:mysql:///test diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java index 53878363aa7b..ec9c4671a4e9 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java @@ -44,6 +44,7 @@ import org.hibernate.dialect.JDataStoreDialect; import org.hibernate.dialect.MckoiDialect; import org.hibernate.dialect.MimerSQLDialect; +import org.hibernate.dialect.MySQL57Dialect; import org.hibernate.dialect.MySQL57InnoDBDialect; import org.hibernate.dialect.MySQL5Dialect; import org.hibernate.dialect.MySQL5InnoDBDialect; @@ -212,6 +213,7 @@ private void addDialects(StrategySelectorImpl strategySelector) { addDialect( strategySelector, MySQL5Dialect.class ); addDialect( strategySelector, MySQL5InnoDBDialect.class ); addDialect( strategySelector, MySQL57InnoDBDialect.class ); + addDialect( strategySelector, MySQL57Dialect.class ); addDialect( strategySelector, Oracle8iDialect.class ); addDialect( strategySelector, Oracle9iDialect.class ); addDialect( strategySelector, Oracle10gDialect.class ); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java index 9afa4aba743b..624c4cad39d1 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -379,6 +379,15 @@ public interface AvailableSettings { */ String DIALECT_RESOLVERS = "hibernate.dialect_resolvers"; + /** + * Defines the default storage engine for the relational databases that support multiple storage engines. + * This property must be set either as an Environment variable or JVM System Property. + * That is because the Dialect is bootstrapped prior to Hibernate property resolution. + * + * @since 5.2.9 + */ + String STORAGE_ENGINE = "hibernate.dialect.storage_engine"; + /** * Used to specify the {@link org.hibernate.tool.schema.spi.SchemaManagementTool} to use for performing * schema management. The default is to use {@link org.hibernate.tool.schema.internal.HibernateSchemaManagementTool} diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index 5c955d44284f..9d7999f00186 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -256,7 +256,6 @@ public static Dialect getDialect() throws HibernateException { return instantiateDialect( Environment.getProperties().getProperty( Environment.DIALECT ) ); } - /** * Get an instance of the dialect specified by the given properties or by * the current System properties. diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/InnoDBStorageEngine.java b/hibernate-core/src/main/java/org/hibernate/dialect/InnoDBStorageEngine.java new file mode 100644 index 000000000000..3480eafd840a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/InnoDBStorageEngine.java @@ -0,0 +1,31 @@ +package org.hibernate.dialect; + +/** + * Represents the InnoDB storage engine. + * + * @author Vlad Mihalcea + */ +public class InnoDBStorageEngine implements MySQLStorageEngine{ + + public static final MySQLStorageEngine INSTANCE = new InnoDBStorageEngine(); + + @Override + public boolean supportsCascadeDelete() { + return true; + } + + @Override + public String getTableTypeString(String engineKeyword) { + return String.format( " %s=InnoDB", engineKeyword ); + } + + @Override + public boolean hasSelfReferentialForeignKeyBug() { + return true; + } + + @Override + public boolean dropConstraints() { + return true; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java index b5775645669b..92738fdc09df 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBDialect.java @@ -9,7 +9,7 @@ /** * @author Vlad Mihalcea */ -public class MariaDBDialect extends MySQL5InnoDBDialect { +public class MariaDBDialect extends MySQL5Dialect { public MariaDBDialect() { super(); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MyISAMStorageEngine.java b/hibernate-core/src/main/java/org/hibernate/dialect/MyISAMStorageEngine.java new file mode 100644 index 000000000000..09f5c04391b3 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MyISAMStorageEngine.java @@ -0,0 +1,31 @@ +package org.hibernate.dialect; + +/** + * Represents the MyISAM storage engine. + * + * @author Vlad Mihalcea + */ +public class MyISAMStorageEngine implements MySQLStorageEngine{ + + public static final MySQLStorageEngine INSTANCE = new MyISAMStorageEngine(); + + @Override + public boolean supportsCascadeDelete() { + return false; + } + + @Override + public String getTableTypeString(String engineKeyword) { + return String.format( " %s=MyISAM", engineKeyword ); + } + + @Override + public boolean hasSelfReferentialForeignKeyBug() { + return false; + } + + @Override + public boolean dropConstraints() { + return false; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL55Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL55Dialect.java new file mode 100644 index 000000000000..fb4ce0e490ea --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL55Dialect.java @@ -0,0 +1,20 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.dialect; + +/** + * An SQL dialect for MySQL 5.5.x specific features. + * + * @author Vlad Mihalcea + */ +public class MySQL55Dialect extends MySQL5Dialect { + + @Override + protected MySQLStorageEngine getDefaultMySQLStorageEngine() { + return InnoDBStorageEngine.INSTANCE; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL57Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL57Dialect.java new file mode 100644 index 000000000000..2adf0514bc78 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL57Dialect.java @@ -0,0 +1,76 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.dialect; + +import java.sql.Types; + +import org.hibernate.dialect.function.SQLFunction; +import org.hibernate.dialect.function.StaticPrecisionFspTimestampFunction; + +/** + * @author Gail Badner + */ +public class MySQL57Dialect extends MySQL55Dialect { + public MySQL57Dialect() { + super(); + + // For details about MySQL 5.7 support for fractional seconds + // precision (fsp): http://dev.mysql.com/doc/refman/5.7/en/fractional-seconds.html + // Regarding datetime(fsp), "The fsp value, if given, must be + // in the range 0 to 6. A value of 0 signifies that there is + // no fractional part. If omitted, the default precision is 0. + // (This differs from the standard SQL default of 6, for + // compatibility with previous MySQL versions.)". + + // The following is defined because Hibernate currently expects + // the SQL 1992 default of 6 (which is inconsistent with the MySQL + // default). + registerColumnType( Types.TIMESTAMP, "datetime(6)" ); + + // MySQL 5.7 brings JSON native support with a dedicated datatype. + // For more details about MySql new JSON datatype support, see: + // https://dev.mysql.com/doc/refman/5.7/en/json.html + registerColumnType( Types.JAVA_OBJECT, "json" ); + + // MySQL also supports fractional seconds precision for time values + // (time(fsp)). According to SQL 1992, the default for