From fa8383a22ea3b943e7cf773e71f4458b3121ab5c Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Tue, 16 Dec 2014 21:05:01 -0800 Subject: [PATCH] HHH-8401 : Support fractional seconds on MySQL 5.7 (cherry picked from commit fe94cda1d1a2ede18b5a577e3ac80db85a806ef3) --- .../dialect/MySQL57InnoDBDialect.java | 80 ++++++ .../dialect/function/NoArgSQLFunction.java | 4 + .../StaticPrecisionFspTimestampFunction.java | 79 ++++++ .../MySQL57TimestampFspFunctionTest.java | 102 ++++++++ .../MySQL57TimestampPropertyTest.java | 225 +++++++++++++++++ .../test/temporal/TimePropertyTest.java | 102 ++++++++ .../test/temporal/TimestampPropertyTest.java | 227 ++++++++++++++++++ 7 files changed, 819 insertions(+) create mode 100644 hibernate-core/src/main/java/org/hibernate/dialect/MySQL57InnoDBDialect.java create mode 100644 hibernate-core/src/main/java/org/hibernate/dialect/function/StaticPrecisionFspTimestampFunction.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/temporal/MySQL57TimestampFspFunctionTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/temporal/MySQL57TimestampPropertyTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/temporal/TimePropertyTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/temporal/TimestampPropertyTest.java diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQL57InnoDBDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL57InnoDBDialect.java new file mode 100644 index 0000000000..0209e77c7d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQL57InnoDBDialect.java @@ -0,0 +1,80 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +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 MySQL57InnoDBDialect extends MySQL5InnoDBDialect { + public MySQL57InnoDBDialect() { + 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 also supports fractional seconds precision for time values + // (time(fsp)). According to SQL 1992, the default for