Skip to content

Commit

Permalink
Fix issues with nightly tests
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Mar 30, 2023
1 parent 5658eee commit 6ddf354
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 19 deletions.
Expand Up @@ -77,10 +77,10 @@
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
import org.hibernate.type.descriptor.jdbc.H2FormatJsonJdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.TimeAsTimestampWithTimeZoneJdbcType;
import org.hibernate.type.descriptor.jdbc.TimeUtcAsJdbcTimeJdbcType;
import org.hibernate.type.descriptor.jdbc.TimeUtcAsOffsetTimeJdbcType;
import org.hibernate.type.descriptor.jdbc.TimestampUtcAsInstantJdbcType;
import org.hibernate.type.descriptor.jdbc.TimestampWithTimeZoneJdbcType;
import org.hibernate.type.descriptor.jdbc.UUIDJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.type.descriptor.sql.internal.DdlTypeImpl;
Expand Down Expand Up @@ -273,7 +273,7 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry

if ( getVersion().isBefore( 2 ) ) {
// Support for TIME_WITH_TIMEZONE was only added in 2.0
jdbcTypeRegistry.addDescriptor( TIME_WITH_TIMEZONE, TimestampWithTimeZoneJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptor( TimeAsTimestampWithTimeZoneJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptor( TimeUtcAsJdbcTimeJdbcType.INSTANCE );
}
else {
Expand Down
46 changes: 36 additions & 10 deletions hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java
Expand Up @@ -486,6 +486,7 @@ public String timestampdiffPattern(TemporalUnit unit, TemporalType fromTemporalT
}

public static String timestampdiffPatternV10(TemporalUnit unit, TemporalType fromTemporalType, TemporalType toTemporalType) {
final boolean isTime = fromTemporalType == TemporalType.TIME || toTemporalType == TemporalType.TIME;
final String fromExpression;
final String toExpression;
if ( unit.isDateUnit() ) {
Expand Down Expand Up @@ -518,20 +519,45 @@ public static String timestampdiffPatternV10(TemporalUnit unit, TemporalType fro
}
switch ( unit ) {
case NATIVE:
return "(select (days(t2)-days(t1))*86400+(midnight_seconds(t2)-midnight_seconds(t1))+(microsecond(t2)-microsecond(t1))/1e6 " +
"from lateral(values(" + fromExpression + ',' + toExpression + ")) as temp(t1,t2))";
if ( isTime ) {
return "(midnight_seconds(" + toExpression + ")-midnight_seconds(" + fromExpression + "))";
}
else {
return "(select (days(t2)-days(t1))*86400+(midnight_seconds(t2)-midnight_seconds(t1))+(microsecond(t2)-microsecond(t1))/1e6 " +
"from lateral(values(" + fromExpression + ',' + toExpression + ")) as temp(t1,t2))";
}
case NANOSECOND:
return "(select (days(t2)-days(t1))*86400+(midnight_seconds(t2)-midnight_seconds(t1))*1e9+(microsecond(t2)-microsecond(t1))*1e3 " +
"from lateral(values(" + fromExpression + ',' + toExpression + ")) as temp(t1,t2))";
if ( isTime ) {
return "(midnight_seconds(" + toExpression + ")-midnight_seconds(" + fromExpression + "))*1e9";
}
else {
return "(select (days(t2)-days(t1))*86400+(midnight_seconds(t2)-midnight_seconds(t1))*1e9+(microsecond(t2)-microsecond(t1))*1e3 " +
"from lateral(values(" + fromExpression + ',' + toExpression + ")) as temp(t1,t2))";
}
case SECOND:
return "(select (days(t2)-days(t1))*86400+(midnight_seconds(t2)-midnight_seconds(t1)) " +
"from lateral(values(" + fromExpression + ',' + toExpression + ")) as temp(t1,t2))";
if ( isTime ) {
return "(midnight_seconds(" + toExpression + ")-midnight_seconds(" + fromExpression + "))";
}
else {
return "(select (days(t2)-days(t1))*86400+(midnight_seconds(t2)-midnight_seconds(t1)) " +
"from lateral(values(" + fromExpression + ',' + toExpression + ")) as temp(t1,t2))";
}
case MINUTE:
return "(select (days(t2)-days(t1))*1440+(midnight_seconds(t2)-midnight_seconds(t1))/60 from " +
"lateral(values(" + fromExpression + ',' + toExpression + ")) as temp(t1,t2))";
if ( isTime ) {
return "(midnight_seconds(" + toExpression + ")-midnight_seconds(" + fromExpression + "))/60";
}
else {
return "(select (days(t2)-days(t1))*1440+(midnight_seconds(t2)-midnight_seconds(t1))/60 from " +
"lateral(values(" + fromExpression + ',' + toExpression + ")) as temp(t1,t2))";
}
case HOUR:
return "(select (days(t2)-days(t1))*24+(midnight_seconds(t2)-midnight_seconds(t1))/3600 " +
"from lateral(values(" + fromExpression + ',' + toExpression + ")) as temp(t1,t2))";
if ( isTime ) {
return "(midnight_seconds(" + toExpression + ")-midnight_seconds(" + fromExpression + "))/3600";
}
else {
return "(select (days(t2)-days(t1))*24+(midnight_seconds(t2)-midnight_seconds(t1))/3600 " +
"from lateral(values(" + fromExpression + ',' + toExpression + ")) as temp(t1,t2))";
}
case YEAR:
return "(year(" + toExpression + ")-year(" + fromExpression + "))";
// the months_between() function results
Expand Down
Expand Up @@ -69,6 +69,7 @@
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl;
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
import org.hibernate.type.descriptor.jdbc.H2FormatJsonJdbcType;
import org.hibernate.type.descriptor.jdbc.TimeAsTimestampWithTimeZoneJdbcType;
import org.hibernate.type.descriptor.jdbc.TimeUtcAsJdbcTimeJdbcType;
import org.hibernate.type.descriptor.jdbc.TimestampUtcAsInstantJdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcType;
Expand Down Expand Up @@ -100,9 +101,7 @@
import static org.hibernate.type.SqlTypes.NUMERIC;
import static org.hibernate.type.SqlTypes.NVARCHAR;
import static org.hibernate.type.SqlTypes.OTHER;
import static org.hibernate.type.SqlTypes.TIMESTAMP_UTC;
import static org.hibernate.type.SqlTypes.TIMESTAMP_WITH_TIMEZONE;
import static org.hibernate.type.SqlTypes.TIME_UTC;
import static org.hibernate.type.SqlTypes.TIME_WITH_TIMEZONE;
import static org.hibernate.type.SqlTypes.UUID;
import static org.hibernate.type.SqlTypes.VARBINARY;
Expand Down Expand Up @@ -254,7 +253,7 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry

if ( getVersion().isBefore( 2 ) ) {
// Support for TIME_WITH_TIMEZONE was only added in 2.0
jdbcTypeRegistry.addDescriptor( TIME_WITH_TIMEZONE, TimestampWithTimeZoneJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptor( TimeAsTimestampWithTimeZoneJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptor( TimeUtcAsJdbcTimeJdbcType.INSTANCE );
}
else {
Expand Down
@@ -0,0 +1,60 @@
/*
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.type.descriptor.jdbc;

import java.sql.Types;
import java.time.OffsetTime;

import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.jdbc.internal.JdbcLiteralFormatterTemporal;
import org.hibernate.type.spi.TypeConfiguration;

import jakarta.persistence.TemporalType;

/**
* Descriptor for {@link Types#TIMESTAMP_WITH_TIMEZONE TIMESTAMP_WITH_TIMEZONE} handling.
*/
public class TimeAsTimestampWithTimeZoneJdbcType extends TimestampWithTimeZoneJdbcType {
public static final TimeAsTimestampWithTimeZoneJdbcType INSTANCE = new TimeAsTimestampWithTimeZoneJdbcType();

public TimeAsTimestampWithTimeZoneJdbcType() {
}

@Override
public int getJdbcTypeCode() {
return Types.TIMESTAMP_WITH_TIMEZONE;
}

@Override
public int getDefaultSqlTypeCode() {
return Types.TIME_WITH_TIMEZONE;
}

@Override
public String getFriendlyName() {
return "TIME_AS_TIMESTAMP_WITH_TIMEZONE";
}

@Override
public String toString() {
return "TimeAsTimestampWithTimeZoneDescriptor";
}

@Override
public <T> JavaType<T> getJdbcRecommendedJavaTypeMapping(
Integer length,
Integer scale,
TypeConfiguration typeConfiguration) {
return typeConfiguration.getJavaTypeRegistry().getDescriptor( OffsetTime.class );
}

@Override
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) {
return new JdbcLiteralFormatterTemporal<>( javaType, TemporalType.TIME );
}

}
Expand Up @@ -43,7 +43,10 @@ public void verifyMappings(SessionFactoryScope scope) {
final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("offsetTime");
final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping();
assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(OffsetTime.class));
assertThat( jdbcMapping.getJdbcType().getJdbcTypeCode(), isOneOf( Types.TIME, Types.TIME_WITH_TIMEZONE));
assertThat(
jdbcMapping.getJdbcType().getJdbcTypeCode(),
isOneOf( Types.TIME, Types.TIMESTAMP_WITH_TIMEZONE, Types.TIME_WITH_TIMEZONE )
);

scope.inTransaction(
(session) -> {
Expand Down
Expand Up @@ -284,15 +284,15 @@ public static class TimeZoneStorageEntity {
private ZonedDateTime zonedDateTimeNormalized;

@TimeZoneStorage(TimeZoneStorageType.NORMALIZE_UTC)
@Column(name = "birthtime_offset_normalized_utc")
@Column(name = "birthtime_offset_utc")
private OffsetTime offsetTimeNormalizedUtc;

@TimeZoneStorage(TimeZoneStorageType.NORMALIZE_UTC)
@Column(name = "birthday_offset_normalized_utc")
@Column(name = "birthday_offset_utc")
private OffsetDateTime offsetDateTimeNormalizedUtc;

@TimeZoneStorage(TimeZoneStorageType.NORMALIZE_UTC)
@Column(name = "birthday_zoned_normalized_utc")
@Column(name = "birthday_zoned_utc")
private ZonedDateTime zonedDateTimeNormalizedUtc;

public TimeZoneStorageEntity() {
Expand Down

0 comments on commit 6ddf354

Please sign in to comment.