HHH-17460 - Ongoing JPA 32 work
This commit is contained in:
parent
7659c79f7a
commit
702ace0bc4
|
@ -12,6 +12,7 @@ import java.time.LocalTime;
|
|||
import java.time.OffsetDateTime;
|
||||
import java.time.OffsetTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.hibernate.annotations.FractionalSeconds;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
|
@ -98,7 +99,14 @@ public class FractionalSecondsTests {
|
|||
@SessionFactory
|
||||
@SkipForDialect(dialectClass = SybaseDialect.class, reason = "Because... Sybase...", matchSubTypes = true)
|
||||
void testUsage(SessionFactoryScope scope) {
|
||||
final Instant start = Instant.now();
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
final Instant start;
|
||||
if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
start = Instant.now().truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
start = Instant.now();
|
||||
}
|
||||
|
||||
scope.inTransaction( (session) -> {
|
||||
final TestEntity testEntity = new TestEntity();
|
||||
|
@ -109,7 +117,6 @@ public class FractionalSecondsTests {
|
|||
|
||||
scope.inTransaction( (session) -> {
|
||||
final TestEntity testEntity = session.find( TestEntity.class, 1 );
|
||||
final Dialect dialect = session.getSessionFactory().getJdbcServices().getDialect();
|
||||
assertThat( testEntity.theInstant ).isEqualTo( DateTimeUtils.adjustToDefaultPrecision( start, dialect ) );
|
||||
} );
|
||||
}
|
||||
|
@ -122,7 +129,14 @@ public class FractionalSecondsTests {
|
|||
@SkipForDialect(dialectClass = SybaseDialect.class, reason = "Because... Sybase...", matchSubTypes = true)
|
||||
@SkipForDialect(dialectClass = AltibaseDialect.class, reason = "Altibase does not support specifying a precision on timestamps")
|
||||
void testUsage0(SessionFactoryScope scope) {
|
||||
final Instant start = Instant.now();
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
final Instant start;
|
||||
if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
start = Instant.now().truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
start = Instant.now();
|
||||
}
|
||||
|
||||
scope.inTransaction( (session) -> {
|
||||
final TestEntity0 testEntity = new TestEntity0();
|
||||
|
@ -133,7 +147,6 @@ public class FractionalSecondsTests {
|
|||
|
||||
scope.inTransaction( (session) -> {
|
||||
final TestEntity0 testEntity = session.find( TestEntity0.class, 1 );
|
||||
final Dialect dialect = session.getSessionFactory().getJdbcServices().getDialect();
|
||||
assertThat( testEntity.theInstant ).isEqualTo( DateTimeUtils.adjustToPrecision( start, 0, dialect ) );
|
||||
} );
|
||||
}
|
||||
|
@ -146,7 +159,14 @@ public class FractionalSecondsTests {
|
|||
@SkipForDialect(dialectClass = SybaseDialect.class, reason = "Because... Sybase...", matchSubTypes = true)
|
||||
@SkipForDialect(dialectClass = AltibaseDialect.class, reason = "Altibase does not support specifying a precision on timestamps")
|
||||
void testUsage3(SessionFactoryScope scope) {
|
||||
final Instant start = Instant.now();
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
final Instant start;
|
||||
if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
start = Instant.now().truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
start = Instant.now();
|
||||
}
|
||||
|
||||
scope.inTransaction( (session) -> {
|
||||
final TestEntity3 testEntity = new TestEntity3();
|
||||
|
@ -157,7 +177,6 @@ public class FractionalSecondsTests {
|
|||
|
||||
scope.inTransaction( (session) -> {
|
||||
final TestEntity3 testEntity = session.find( TestEntity3.class, 1 );
|
||||
final Dialect dialect = session.getSessionFactory().getJdbcServices().getDialect();
|
||||
assertThat( testEntity.theInstant ).isEqualTo( DateTimeUtils.adjustToPrecision( start, 3, dialect ) );
|
||||
} );
|
||||
}
|
||||
|
@ -173,7 +192,14 @@ public class FractionalSecondsTests {
|
|||
@SkipForDialect(dialectClass = CockroachDialect.class, reason = "CockroachDB only supports precision <= 6")
|
||||
@SkipForDialect(dialectClass = HANADialect.class, reason = "HANA does not support specifying a precision on timestamps")
|
||||
void testUsage9(SessionFactoryScope scope) {
|
||||
final Instant start = Instant.now();
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
final Instant start;
|
||||
if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
start = Instant.now().truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
start = Instant.now();
|
||||
}
|
||||
|
||||
scope.inTransaction( (session) -> {
|
||||
final TestEntity9 testEntity = new TestEntity9();
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.time.LocalTime;
|
|||
import java.time.OffsetDateTime;
|
||||
import java.time.OffsetTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.hibernate.annotations.FractionalSeconds;
|
||||
import org.hibernate.annotations.JdbcTypeCode;
|
||||
|
@ -100,7 +101,14 @@ public class JavaTimeFractionalSecondsTests {
|
|||
@SessionFactory
|
||||
@SkipForDialect(dialectClass = SybaseDialect.class, reason = "Because... Sybase...", matchSubTypes = true)
|
||||
void testUsage(SessionFactoryScope scope) {
|
||||
final Instant start = Instant.now();
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
final Instant start;
|
||||
if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
start = Instant.now().truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
start = Instant.now();
|
||||
}
|
||||
|
||||
scope.inTransaction( (session) -> {
|
||||
final TestEntity testEntity = new TestEntity();
|
||||
|
@ -111,7 +119,6 @@ public class JavaTimeFractionalSecondsTests {
|
|||
|
||||
scope.inTransaction( (session) -> {
|
||||
final TestEntity testEntity = session.find( TestEntity.class, 1 );
|
||||
final Dialect dialect = session.getSessionFactory().getJdbcServices().getDialect();
|
||||
assertThat( testEntity.theInstant ).isEqualTo( DateTimeUtils.adjustToDefaultPrecision( start, dialect ) );
|
||||
} );
|
||||
}
|
||||
|
@ -124,7 +131,14 @@ public class JavaTimeFractionalSecondsTests {
|
|||
@SkipForDialect(dialectClass = SybaseDialect.class, reason = "Because... Sybase...", matchSubTypes = true)
|
||||
@SkipForDialect(dialectClass = AltibaseDialect.class, reason = "Altibase does not support specifying a precision on timestamps")
|
||||
void testUsage0(SessionFactoryScope scope) {
|
||||
final Instant start = Instant.now();
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
final Instant start;
|
||||
if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
start = Instant.now().truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
start = Instant.now();
|
||||
}
|
||||
|
||||
scope.inTransaction( (session) -> {
|
||||
final TestEntity0 testEntity = new TestEntity0();
|
||||
|
@ -135,7 +149,6 @@ public class JavaTimeFractionalSecondsTests {
|
|||
|
||||
scope.inTransaction( (session) -> {
|
||||
final TestEntity0 testEntity = session.find( TestEntity0.class, 1 );
|
||||
final Dialect dialect = session.getSessionFactory().getJdbcServices().getDialect();
|
||||
assertThat( testEntity.theInstant ).isEqualTo( DateTimeUtils.adjustToPrecision( start, 0, dialect ) );
|
||||
} );
|
||||
}
|
||||
|
@ -148,7 +161,14 @@ public class JavaTimeFractionalSecondsTests {
|
|||
@SkipForDialect(dialectClass = SybaseDialect.class, reason = "Because... Sybase...", matchSubTypes = true)
|
||||
@SkipForDialect(dialectClass = AltibaseDialect.class, reason = "Altibase does not support specifying a precision on timestamps")
|
||||
void testUsage3(SessionFactoryScope scope) {
|
||||
final Instant start = Instant.now();
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
final Instant start;
|
||||
if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
start = Instant.now().truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
start = Instant.now();
|
||||
}
|
||||
|
||||
scope.inTransaction( (session) -> {
|
||||
final TestEntity3 testEntity = new TestEntity3();
|
||||
|
@ -159,7 +179,6 @@ public class JavaTimeFractionalSecondsTests {
|
|||
|
||||
scope.inTransaction( (session) -> {
|
||||
final TestEntity3 testEntity = session.find( TestEntity3.class, 1 );
|
||||
final Dialect dialect = session.getSessionFactory().getJdbcServices().getDialect();
|
||||
assertThat( testEntity.theInstant ).isEqualTo( DateTimeUtils.adjustToPrecision( start, 3, dialect ) );
|
||||
} );
|
||||
}
|
||||
|
@ -175,7 +194,14 @@ public class JavaTimeFractionalSecondsTests {
|
|||
@SkipForDialect(dialectClass = CockroachDialect.class, reason = "CockroachDB only supports precision <= 6")
|
||||
@SkipForDialect(dialectClass = HANADialect.class, reason = "HANA does not support specifying a precision on timestamps")
|
||||
void testUsage9(SessionFactoryScope scope) {
|
||||
final Instant start = Instant.now();
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
final Instant start;
|
||||
if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
start = Instant.now().truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
start = Instant.now();
|
||||
}
|
||||
|
||||
scope.inTransaction( (session) -> {
|
||||
final TestEntity9 testEntity = new TestEntity9();
|
||||
|
|
|
@ -6,9 +6,12 @@ import java.time.ZoneId;
|
|||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.TemporalUnit;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.dialect.SybaseDialect;
|
||||
import org.hibernate.type.descriptor.DateTimeUtils;
|
||||
|
||||
|
@ -33,13 +36,18 @@ public class AutoZonedTest {
|
|||
@Test void test(SessionFactoryScope scope) {
|
||||
final ZonedDateTime nowZoned;
|
||||
final OffsetDateTime nowOffset;
|
||||
if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect ) {
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
if ( dialect instanceof SybaseDialect) {
|
||||
// Sybase has 1/300th sec precision
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") )
|
||||
.with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) )
|
||||
.with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
}
|
||||
else if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") ).truncatedTo( ChronoUnit.MICROS );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) ).truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) );
|
||||
|
@ -53,7 +61,6 @@ public class AutoZonedTest {
|
|||
});
|
||||
scope.inSession( s -> {
|
||||
Zoned z = s.find(Zoned.class, id);
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
|
||||
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
|
||||
assertEquals(
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.time.ZoneId;
|
|||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
|
@ -33,13 +34,18 @@ public class ColumnZonedTest {
|
|||
@Test void test(SessionFactoryScope scope) {
|
||||
final ZonedDateTime nowZoned;
|
||||
final OffsetDateTime nowOffset;
|
||||
if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect ) {
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
if ( dialect instanceof SybaseDialect ) {
|
||||
// Sybase has 1/300th sec precision
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") )
|
||||
.with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) )
|
||||
.with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
}
|
||||
else if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") ).truncatedTo( ChronoUnit.MICROS );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) ).truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) );
|
||||
|
@ -53,7 +59,6 @@ public class ColumnZonedTest {
|
|||
});
|
||||
scope.inSession( s -> {
|
||||
Zoned z = s.find(Zoned.class, id);
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
|
||||
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
|
||||
assertEquals(
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.time.ZoneId;
|
|||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.SybaseDialect;
|
||||
|
@ -30,13 +31,18 @@ public class DefaultZonedTest {
|
|||
@Test void test(SessionFactoryScope scope) {
|
||||
final ZonedDateTime nowZoned;
|
||||
final OffsetDateTime nowOffset;
|
||||
if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect ) {
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
if ( dialect instanceof SybaseDialect ) {
|
||||
// Sybase has 1/300th sec precision
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") )
|
||||
.with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) )
|
||||
.with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
}
|
||||
else if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") ).truncatedTo( ChronoUnit.MICROS );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) ).truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) );
|
||||
|
@ -50,7 +56,6 @@ public class DefaultZonedTest {
|
|||
});
|
||||
scope.inSession( s -> {
|
||||
Zoned z = s.find(Zoned.class, id);
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
|
||||
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
|
||||
assertEquals(
|
||||
|
|
|
@ -6,9 +6,11 @@ import java.time.ZoneId;
|
|||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.MySQLDialect;
|
||||
import org.hibernate.dialect.SybaseDialect;
|
||||
import org.hibernate.type.descriptor.DateTimeUtils;
|
||||
|
||||
|
@ -34,13 +36,18 @@ public class JDBCTimeZoneZonedTest {
|
|||
@Test void test(SessionFactoryScope scope) {
|
||||
final ZonedDateTime nowZoned;
|
||||
final OffsetDateTime nowOffset;
|
||||
if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect ) {
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
if ( dialect instanceof SybaseDialect || dialect instanceof MySQLDialect ) {
|
||||
// Sybase has 1/300th sec precision
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") )
|
||||
.with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) )
|
||||
.with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
}
|
||||
else if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") ).truncatedTo( ChronoUnit.MICROS );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) ).truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) );
|
||||
|
@ -56,7 +63,6 @@ public class JDBCTimeZoneZonedTest {
|
|||
Zoned z = s.find(Zoned.class, id);
|
||||
ZoneId systemZone = ZoneId.systemDefault();
|
||||
ZoneOffset systemOffset = systemZone.getRules().getOffset( Instant.now() );
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
|
||||
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
|
||||
assertEquals(
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.time.ZoneId;
|
|||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
|
@ -33,13 +34,18 @@ public class PassThruZonedTest {
|
|||
@Test void test(SessionFactoryScope scope) {
|
||||
final ZonedDateTime nowZoned;
|
||||
final OffsetDateTime nowOffset;
|
||||
if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect ) {
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
if ( dialect instanceof SybaseDialect ) {
|
||||
// Sybase has 1/300th sec precision
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") )
|
||||
.with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) )
|
||||
.with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
}
|
||||
else if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") ).truncatedTo( ChronoUnit.MICROS );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) ).truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) );
|
||||
|
@ -55,7 +61,6 @@ public class PassThruZonedTest {
|
|||
Zoned z = s.find(Zoned.class, id);
|
||||
ZoneId systemZone = ZoneId.systemDefault();
|
||||
ZoneOffset systemOffset = systemZone.getRules().getOffset( Instant.now() );
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
|
||||
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
|
||||
assertEquals(
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.hibernate.orm.test.timezones;
|
|||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.hibernate.annotations.JdbcTypeCode;
|
||||
|
@ -28,10 +29,14 @@ public class UTCNormalizedInstantTest {
|
|||
|
||||
@Test void test(SessionFactoryScope scope) {
|
||||
final Instant instant;
|
||||
if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect ) {
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
if ( dialect instanceof SybaseDialect ) {
|
||||
// Sybase has 1/300th sec precision
|
||||
instant = Instant.now().with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
}
|
||||
else if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
instant = Instant.now().truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
instant = Instant.now();
|
||||
}
|
||||
|
@ -44,7 +49,6 @@ public class UTCNormalizedInstantTest {
|
|||
});
|
||||
scope.inSession( s-> {
|
||||
final Zoned z = s.find(Zoned.class, id);
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
assertEquals(
|
||||
DateTimeUtils.adjustToDefaultPrecision( z.utcInstant, dialect ),
|
||||
DateTimeUtils.adjustToDefaultPrecision( instant, dialect )
|
||||
|
@ -62,23 +66,26 @@ public class UTCNormalizedInstantTest {
|
|||
SharedDriverManagerConnectionProviderImpl.getInstance().onDefaultTimeZoneChange();
|
||||
try {
|
||||
final Instant instant;
|
||||
if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect ) {
|
||||
// Sybase has 1/300th sec precision
|
||||
instant = Instant.now().with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
}
|
||||
else {
|
||||
instant = Instant.now();
|
||||
}
|
||||
long id = scope.fromTransaction( s-> {
|
||||
final Zoned z = new Zoned();
|
||||
z.utcInstant = instant;
|
||||
z.localInstant = instant;
|
||||
s.persist(z);
|
||||
return z.id;
|
||||
});
|
||||
scope.inSession( s-> {
|
||||
final Zoned z = s.find(Zoned.class, id);
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
if ( dialect instanceof SybaseDialect ) {
|
||||
// Sybase has 1/300th sec precision
|
||||
instant = Instant.now().with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
}
|
||||
else if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
instant = Instant.now().truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
instant = Instant.now();
|
||||
}
|
||||
long id = scope.fromTransaction( s-> {
|
||||
final Zoned z = new Zoned();
|
||||
z.utcInstant = instant;
|
||||
z.localInstant = instant;
|
||||
s.persist(z);
|
||||
return z.id;
|
||||
});
|
||||
scope.inSession( s-> {
|
||||
final Zoned z = s.find(Zoned.class, id);
|
||||
Instant expected = DateTimeUtils.adjustToDefaultPrecision( z.utcInstant, dialect );
|
||||
Instant actual = DateTimeUtils.adjustToDefaultPrecision( instant, dialect );
|
||||
assertEquals(
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.time.ZoneId;
|
|||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
|
@ -33,13 +34,18 @@ public class UTCNormalizedZonedTest {
|
|||
@Test void test(SessionFactoryScope scope) {
|
||||
final ZonedDateTime nowZoned;
|
||||
final OffsetDateTime nowOffset;
|
||||
if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect ) {
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
if ( dialect instanceof SybaseDialect ) {
|
||||
// Sybase has 1/300th sec precision
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") )
|
||||
.with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) )
|
||||
.with( ChronoField.NANO_OF_SECOND, 0L );
|
||||
}
|
||||
else if ( dialect.getDefaultTimestampPrecision() == 6 ) {
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") ).truncatedTo( ChronoUnit.MICROS );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) ).truncatedTo( ChronoUnit.MICROS );
|
||||
}
|
||||
else {
|
||||
nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") );
|
||||
nowOffset = OffsetDateTime.now().withOffsetSameInstant( ZoneOffset.ofHours(3) );
|
||||
|
@ -53,7 +59,6 @@ public class UTCNormalizedZonedTest {
|
|||
});
|
||||
scope.inSession( s-> {
|
||||
Zoned z = s.find(Zoned.class, id);
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
|
||||
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
|
||||
assertEquals(
|
||||
|
|
Loading…
Reference in New Issue