HHH-17460 - Ongoing JPA 32 work

This commit is contained in:
Andrea Boriero 2024-04-02 17:56:00 +02:00 committed by Steve Ebersole
parent 894a182798
commit 7659c79f7a
7 changed files with 65 additions and 34 deletions

View File

@ -1,5 +1,6 @@
package org.hibernate.orm.test.timezones; package org.hibernate.orm.test.timezones;
import java.time.Instant;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZoneOffset; import java.time.ZoneOffset;
@ -53,13 +54,17 @@ public class AutoZonedTest {
scope.inSession( s -> { scope.inSession( s -> {
Zoned z = s.find(Zoned.class, id); Zoned z = s.find(Zoned.class, id);
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect(); final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowZoned.toInstant(), dialect ), expected,
DateTimeUtils.roundToDefaultPrecision( z.zonedDateTime.toInstant(), dialect ) actual
); );
expected = DateTimeUtils.adjustToDefaultPrecision( nowOffset.toInstant(), dialect );
actual = DateTimeUtils.adjustToDefaultPrecision( z.offsetDateTime.toInstant(), dialect );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowOffset.toInstant(), dialect ), expected,
DateTimeUtils.roundToDefaultPrecision( z.offsetDateTime.toInstant(), dialect ) actual
); );
assertEquals( nowZoned.toOffsetDateTime().getOffset(), z.zonedDateTime.toOffsetDateTime().getOffset() ); assertEquals( nowZoned.toOffsetDateTime().getOffset(), z.zonedDateTime.toOffsetDateTime().getOffset() );
assertEquals( nowOffset.getOffset(), z.offsetDateTime.getOffset() ); assertEquals( nowOffset.getOffset(), z.offsetDateTime.getOffset() );

View File

@ -1,5 +1,6 @@
package org.hibernate.orm.test.timezones; package org.hibernate.orm.test.timezones;
import java.time.Instant;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZoneOffset; import java.time.ZoneOffset;
@ -53,13 +54,17 @@ public class ColumnZonedTest {
scope.inSession( s -> { scope.inSession( s -> {
Zoned z = s.find(Zoned.class, id); Zoned z = s.find(Zoned.class, id);
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect(); final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowZoned.toInstant(), dialect ), expected,
DateTimeUtils.roundToDefaultPrecision( z.zonedDateTime.toInstant(), dialect ) actual
); );
expected = DateTimeUtils.adjustToDefaultPrecision( nowOffset.toInstant(), dialect );
actual = DateTimeUtils.adjustToDefaultPrecision( z.offsetDateTime.toInstant(), dialect );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowOffset.toInstant(), dialect ), expected,
DateTimeUtils.roundToDefaultPrecision( z.offsetDateTime.toInstant(), dialect ) actual
); );
assertEquals( nowZoned.toOffsetDateTime().getOffset(), z.zonedDateTime.toOffsetDateTime().getOffset() ); assertEquals( nowZoned.toOffsetDateTime().getOffset(), z.zonedDateTime.toOffsetDateTime().getOffset() );
assertEquals( nowOffset.getOffset(), z.offsetDateTime.getOffset() ); assertEquals( nowOffset.getOffset(), z.offsetDateTime.getOffset() );

View File

@ -1,5 +1,6 @@
package org.hibernate.orm.test.timezones; package org.hibernate.orm.test.timezones;
import java.time.Instant;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZoneOffset; import java.time.ZoneOffset;
@ -50,13 +51,17 @@ public class DefaultZonedTest {
scope.inSession( s -> { scope.inSession( s -> {
Zoned z = s.find(Zoned.class, id); Zoned z = s.find(Zoned.class, id);
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect(); final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowZoned.toInstant(), dialect ), expected,
DateTimeUtils.roundToDefaultPrecision( z.zonedDateTime.toInstant(), dialect ) actual
); );
expected = DateTimeUtils.adjustToDefaultPrecision( nowOffset.toInstant(), dialect );
actual = DateTimeUtils.adjustToDefaultPrecision( z.offsetDateTime.toInstant(), dialect );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowOffset.toInstant(), dialect ), expected,
DateTimeUtils.roundToDefaultPrecision( z.offsetDateTime.toInstant(), dialect ) actual
); );
if ( dialect.getTimeZoneSupport() == TimeZoneSupport.NATIVE ) { if ( dialect.getTimeZoneSupport() == TimeZoneSupport.NATIVE ) {
assertEquals( nowZoned.toOffsetDateTime().getOffset(), z.zonedDateTime.toOffsetDateTime().getOffset() ); assertEquals( nowZoned.toOffsetDateTime().getOffset(), z.zonedDateTime.toOffsetDateTime().getOffset() );

View File

@ -57,13 +57,17 @@ public class JDBCTimeZoneZonedTest {
ZoneId systemZone = ZoneId.systemDefault(); ZoneId systemZone = ZoneId.systemDefault();
ZoneOffset systemOffset = systemZone.getRules().getOffset( Instant.now() ); ZoneOffset systemOffset = systemZone.getRules().getOffset( Instant.now() );
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect(); final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowZoned.toInstant(), dialect ), expected,
DateTimeUtils.roundToDefaultPrecision( z.zonedDateTime.toInstant(), dialect ) actual
); );
expected = DateTimeUtils.adjustToDefaultPrecision( nowOffset.toInstant(), dialect );
actual = DateTimeUtils.adjustToDefaultPrecision( z.offsetDateTime.toInstant(), dialect );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowOffset.toInstant(), dialect ), expected,
DateTimeUtils.roundToDefaultPrecision( z.offsetDateTime.toInstant(), dialect ) actual
); );
assertEquals( systemZone, z.zonedDateTime.getZone() ); assertEquals( systemZone, z.zonedDateTime.getZone() );
assertEquals( systemOffset, z.offsetDateTime.getOffset() ); assertEquals( systemOffset, z.offsetDateTime.getOffset() );

View File

@ -56,13 +56,17 @@ public class PassThruZonedTest {
ZoneId systemZone = ZoneId.systemDefault(); ZoneId systemZone = ZoneId.systemDefault();
ZoneOffset systemOffset = systemZone.getRules().getOffset( Instant.now() ); ZoneOffset systemOffset = systemZone.getRules().getOffset( Instant.now() );
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect(); final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowZoned.toInstant(), dialect ), expected,
DateTimeUtils.roundToDefaultPrecision( z.zonedDateTime.toInstant(), dialect ) actual
); );
expected = DateTimeUtils.adjustToDefaultPrecision( nowOffset.toInstant(), dialect );
actual = DateTimeUtils.adjustToDefaultPrecision( z.offsetDateTime.toInstant(), dialect );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowOffset.toInstant(), dialect ), expected,
DateTimeUtils.roundToDefaultPrecision( z.offsetDateTime.toInstant(), dialect ) actual
); );
assertEquals( systemZone, z.zonedDateTime.getZone() ); assertEquals( systemZone, z.zonedDateTime.getZone() );
assertEquals( systemOffset, z.offsetDateTime.getOffset() ); assertEquals( systemOffset, z.offsetDateTime.getOffset() );

View File

@ -46,12 +46,12 @@ public class UTCNormalizedInstantTest {
final Zoned z = s.find(Zoned.class, id); final Zoned z = s.find(Zoned.class, id);
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect(); final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( z.utcInstant, dialect ), DateTimeUtils.adjustToDefaultPrecision( z.utcInstant, dialect ),
DateTimeUtils.roundToDefaultPrecision( instant, dialect ) DateTimeUtils.adjustToDefaultPrecision( instant, dialect )
); );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( z.localInstant, dialect ), DateTimeUtils.adjustToDefaultPrecision( z.localInstant, dialect ),
DateTimeUtils.roundToDefaultPrecision( instant, dialect ) DateTimeUtils.adjustToDefaultPrecision( instant, dialect )
); );
}); });
} }
@ -79,13 +79,16 @@ public class UTCNormalizedInstantTest {
scope.inSession( s-> { scope.inSession( s-> {
final Zoned z = s.find(Zoned.class, id); final Zoned z = s.find(Zoned.class, id);
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect(); final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
Instant expected = DateTimeUtils.adjustToDefaultPrecision( z.utcInstant, dialect );
Instant actual = DateTimeUtils.adjustToDefaultPrecision( instant, dialect );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( z.utcInstant, dialect ), expected,
DateTimeUtils.roundToDefaultPrecision( instant, dialect ) actual
); );
expected = DateTimeUtils.adjustToDefaultPrecision( z.localInstant, dialect );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( z.localInstant, dialect ), expected,
DateTimeUtils.roundToDefaultPrecision( instant, dialect ) actual
); );
}); });
} }

View File

@ -1,5 +1,6 @@
package org.hibernate.orm.test.timezones; package org.hibernate.orm.test.timezones;
import java.time.Instant;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZoneOffset; import java.time.ZoneOffset;
@ -53,13 +54,17 @@ public class UTCNormalizedZonedTest {
scope.inSession( s-> { scope.inSession( s-> {
Zoned z = s.find(Zoned.class, id); Zoned z = s.find(Zoned.class, id);
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect(); final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowZoned.toInstant(), dialect ), expected,
DateTimeUtils.roundToDefaultPrecision( z.zonedDateTime.toInstant(), dialect ) actual
); );
expected = DateTimeUtils.adjustToDefaultPrecision( nowOffset.toInstant(), dialect );
actual = DateTimeUtils.adjustToDefaultPrecision( z.offsetDateTime.toInstant(), dialect );
assertEquals( assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowOffset.toInstant(), dialect ), expected,
DateTimeUtils.roundToDefaultPrecision( z.offsetDateTime.toInstant(), dialect ) actual
); );
assertEquals( ZoneId.of("Z"), z.zonedDateTime.getZone() ); assertEquals( ZoneId.of("Z"), z.zonedDateTime.getZone() );
assertEquals( ZoneOffset.ofHours(0), z.offsetDateTime.getOffset() ); assertEquals( ZoneOffset.ofHours(0), z.offsetDateTime.getOffset() );