Migrate java type descriptor tests and fix JdbcTimestampTypeDescriptor

This commit is contained in:
Christian Beikov 2021-03-02 17:29:56 +01:00
parent a3d2f1937e
commit ce41447875
19 changed files with 32 additions and 34 deletions

View File

@ -7,9 +7,12 @@
package org.hibernate.type.descriptor.java; package org.hibernate.type.descriptor.java;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.ParseException; import java.time.ZoneId;
import java.text.SimpleDateFormat; import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
@ -41,17 +44,8 @@ public class JdbcTimestampTypeDescriptor extends AbstractTemporalTypeDescriptor<
* @see #TIMESTAMP_FORMAT * @see #TIMESTAMP_FORMAT
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final DateTimeFormatter LITERAL_FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE_TIME; public static final DateTimeFormatter LITERAL_FORMATTER = DateTimeFormatter.ofPattern( TIMESTAMP_FORMAT )
.withZone( ZoneId.from( ZoneOffset.UTC ) );
/**
* Alias for {@link java.time.format.DateTimeFormatter#ISO_LOCAL_DATE_TIME}.
*
* Intended for use with logging
*
* @see #LITERAL_FORMATTER
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public static final DateTimeFormatter LOGGABLE_FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
public static class TimestampMutabilityPlan extends MutableMutabilityPlan<Date> { public static class TimestampMutabilityPlan extends MutableMutabilityPlan<Date> {
public static final TimestampMutabilityPlan INSTANCE = new TimestampMutabilityPlan(); public static final TimestampMutabilityPlan INSTANCE = new TimestampMutabilityPlan();
@ -92,15 +86,19 @@ public class JdbcTimestampTypeDescriptor extends AbstractTemporalTypeDescriptor<
@Override @Override
public String toString(Date value) { public String toString(Date value) {
return LOGGABLE_FORMATTER.format( value.toInstant() ); return LITERAL_FORMATTER.format( value.toInstant() );
} }
@Override @Override
public Date fromString(String string) { public Date fromString(String string) {
try { try {
return new Timestamp( new SimpleDateFormat( TIMESTAMP_FORMAT ).parse( string ).getTime() ); final TemporalAccessor accessor = LITERAL_FORMATTER.parse( string );
return new Timestamp(
accessor.getLong( ChronoField.INSTANT_SECONDS ) * 1000L
+ accessor.get( ChronoField.NANO_OF_SECOND ) / 1_000_000
);
} }
catch ( ParseException pe) { catch ( DateTimeParseException pe) {
throw new HibernateException( "could not parse timestamp string" + string, pe ); throw new HibernateException( "could not parse timestamp string" + string, pe );
} }
} }

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import java.io.Serializable; import java.io.Serializable;
import java.sql.Blob; import java.sql.Blob;
import java.sql.Clob; import java.sql.Clob;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor; import org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import java.math.BigInteger; import java.math.BigInteger;
import org.hibernate.type.descriptor.java.BigIntegerTypeDescriptor; import org.hibernate.type.descriptor.java.BigIntegerTypeDescriptor;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import org.hibernate.type.descriptor.java.BooleanTypeDescriptor; import org.hibernate.type.descriptor.java.BooleanTypeDescriptor;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import java.time.Duration; import java.time.Duration;
import org.hibernate.type.descriptor.java.DurationJavaDescriptor; import org.hibernate.type.descriptor.java.DurationJavaDescriptor;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import java.time.Instant; import java.time.Instant;
import org.hibernate.type.descriptor.java.InstantJavaDescriptor; import org.hibernate.type.descriptor.java.InstantJavaDescriptor;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import java.util.Date; import java.util.Date;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import java.util.Date; import java.util.Date;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import java.time.LocalDate; import java.time.LocalDate;
import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor; import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import org.hibernate.type.descriptor.java.LocalDateTimeJavaDescriptor; import org.hibernate.type.descriptor.java.LocalDateTimeJavaDescriptor;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import java.time.LocalDate; import java.time.LocalDate;
import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor; import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.OffsetTime; import java.time.OffsetTime;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor; import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import org.hibernate.type.descriptor.java.StringTypeDescriptor; import org.hibernate.type.descriptor.java.StringTypeDescriptor;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.type.descriptor.java; package org.hibernate.orm.test.type.descriptor.java;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;