Skip to content

Commit 7ec3667

Browse files
committed
Fix test failures on nightly test pipeline
1 parent ea7c8c6 commit 7ec3667

File tree

18 files changed

+378
-87
lines changed

18 files changed

+378
-87
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
import java.sql.ResultSet;
1212
import java.sql.SQLException;
1313
import java.sql.Types;
14+
import java.time.Instant;
15+
import java.time.LocalDate;
16+
import java.time.LocalDateTime;
17+
import java.time.LocalTime;
18+
import java.time.OffsetDateTime;
19+
import java.time.OffsetTime;
20+
import java.time.ZonedDateTime;
1421
import java.time.temporal.TemporalAccessor;
1522
import java.util.Calendar;
1623
import java.util.Date;
@@ -21,6 +28,7 @@
2128
import org.hibernate.boot.model.FunctionContributions;
2229
import org.hibernate.boot.model.TypeContributions;
2330
import org.hibernate.dialect.DB2Dialect;
31+
import org.hibernate.dialect.DB2GetObjectExtractor;
2432
import org.hibernate.dialect.DB2StructJdbcType;
2533
import org.hibernate.dialect.DatabaseVersion;
2634
import org.hibernate.dialect.Dialect;
@@ -82,15 +90,24 @@
8290
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
8391
import org.hibernate.type.JavaObjectType;
8492
import org.hibernate.type.StandardBasicTypes;
93+
import org.hibernate.type.descriptor.ValueExtractor;
94+
import org.hibernate.type.descriptor.java.JavaType;
8595
import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaType;
8696
import org.hibernate.type.descriptor.jdbc.CharJdbcType;
8797
import org.hibernate.type.descriptor.jdbc.ClobJdbcType;
8898
import org.hibernate.type.descriptor.jdbc.DecimalJdbcType;
99+
import org.hibernate.type.descriptor.jdbc.InstantJdbcType;
100+
import org.hibernate.type.descriptor.jdbc.LocalDateJdbcType;
101+
import org.hibernate.type.descriptor.jdbc.LocalDateTimeJdbcType;
102+
import org.hibernate.type.descriptor.jdbc.LocalTimeJdbcType;
89103
import org.hibernate.type.descriptor.jdbc.ObjectNullResolvingJdbcType;
104+
import org.hibernate.type.descriptor.jdbc.OffsetDateTimeJdbcType;
105+
import org.hibernate.type.descriptor.jdbc.OffsetTimeJdbcType;
90106
import org.hibernate.type.descriptor.jdbc.SmallIntJdbcType;
91107
import org.hibernate.type.descriptor.jdbc.VarbinaryJdbcType;
92108
import org.hibernate.type.descriptor.jdbc.VarcharJdbcType;
93109
import org.hibernate.type.descriptor.jdbc.XmlJdbcType;
110+
import org.hibernate.type.descriptor.jdbc.ZonedDateTimeJdbcType;
94111
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
95112
import org.hibernate.type.descriptor.sql.internal.CapacityDependentDdlType;
96113
import org.hibernate.type.descriptor.sql.internal.DdlTypeImpl;
@@ -805,6 +822,12 @@ public String getCurrentTimestampSelectString() {
805822
return "values current timestamp";
806823
}
807824

825+
@Override
826+
public boolean doesRoundTemporalOnOverflow() {
827+
// DB2 does truncation
828+
return false;
829+
}
830+
808831
@Override
809832
public boolean isCurrentTimestampSelectStringCallable() {
810833
return false;
@@ -877,6 +900,49 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
877900
.getDescriptor( Object.class )
878901
)
879902
);
903+
904+
typeContributions.contributeJdbcType( new InstantJdbcType() {
905+
@Override
906+
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
907+
return new DB2GetObjectExtractor<>( javaType, this, Instant.class );
908+
}
909+
} );
910+
typeContributions.contributeJdbcType( new LocalDateTimeJdbcType() {
911+
@Override
912+
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
913+
return new DB2GetObjectExtractor<>( javaType, this, LocalDateTime.class );
914+
}
915+
} );
916+
typeContributions.contributeJdbcType( new LocalDateJdbcType() {
917+
@Override
918+
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
919+
return new DB2GetObjectExtractor<>( javaType, this, LocalDate.class );
920+
}
921+
} );
922+
typeContributions.contributeJdbcType( new LocalTimeJdbcType() {
923+
@Override
924+
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
925+
return new DB2GetObjectExtractor<>( javaType, this, LocalTime.class );
926+
}
927+
} );
928+
typeContributions.contributeJdbcType( new OffsetDateTimeJdbcType() {
929+
@Override
930+
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
931+
return new DB2GetObjectExtractor<>( javaType, this, OffsetDateTime.class );
932+
}
933+
} );
934+
typeContributions.contributeJdbcType( new OffsetTimeJdbcType() {
935+
@Override
936+
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
937+
return new DB2GetObjectExtractor<>( javaType, this, OffsetTime.class );
938+
}
939+
} );
940+
typeContributions.contributeJdbcType( new ZonedDateTimeJdbcType() {
941+
@Override
942+
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
943+
return new DB2GetObjectExtractor<>( javaType, this, ZonedDateTime.class );
944+
}
945+
} );
880946
}
881947

882948
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbyLegacyDialect.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ public int getDoublePrecision() {
318318
return 52;
319319
}
320320

321+
@Override
322+
public int getDefaultTimestampPrecision() {
323+
return 9;
324+
}
325+
321326
@Override
322327
public void initializeFunctionRegistry(FunctionContributions functionContributions) {
323328
super.initializeFunctionRegistry(functionContributions);

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/HSQLLegacyDialect.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,12 @@ public String getCurrentTimestampSelectString() {
723723
return "call current_timestamp";
724724
}
725725

726+
@Override
727+
public boolean doesRoundTemporalOnOverflow() {
728+
// HSQLDB does truncation
729+
return false;
730+
}
731+
726732
/**
727733
* For HSQLDB 2.0, this is a copy of the base class implementation.
728734
* For HSQLDB 1.8, only READ_UNCOMMITTED is supported.

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MariaDBLegacyDialect.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ public boolean supportsColumnCheck() {
179179
return getVersion().isSameOrAfter( 10, 2 );
180180
}
181181

182+
@Override
183+
public boolean doesRoundTemporalOnOverflow() {
184+
// See https://jira.mariadb.org/browse/MDEV-16991
185+
return false;
186+
}
187+
182188
@Override
183189
protected MySQLStorageEngine getDefaultMySQLStorageEngine() {
184190
return InnoDBStorageEngine.INSTANCE;

hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ public String castPattern(CastType from, CastType to) {
376376
return super.castPattern( from, to );
377377
}
378378

379+
@Override
380+
public int getDefaultTimestampPrecision() {
381+
return 7;
382+
}
383+
379384
public int getDefaultDecimalPrecision() {
380385
//the maximum on HANA
381386
return 34;

hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
import java.sql.ResultSet;
1212
import java.sql.SQLException;
1313
import java.sql.Types;
14+
import java.time.Instant;
15+
import java.time.LocalDate;
16+
import java.time.LocalDateTime;
17+
import java.time.LocalTime;
18+
import java.time.OffsetDateTime;
19+
import java.time.OffsetTime;
20+
import java.time.ZonedDateTime;
1421
import java.time.temporal.TemporalAccessor;
1522
import java.util.Calendar;
1623
import java.util.Date;
@@ -74,15 +81,24 @@
7481
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
7582
import org.hibernate.type.JavaObjectType;
7683
import org.hibernate.type.StandardBasicTypes;
84+
import org.hibernate.type.descriptor.ValueExtractor;
85+
import org.hibernate.type.descriptor.java.JavaType;
7786
import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaType;
7887
import org.hibernate.type.descriptor.jdbc.CharJdbcType;
7988
import org.hibernate.type.descriptor.jdbc.ClobJdbcType;
8089
import org.hibernate.type.descriptor.jdbc.DecimalJdbcType;
90+
import org.hibernate.type.descriptor.jdbc.InstantJdbcType;
91+
import org.hibernate.type.descriptor.jdbc.LocalDateJdbcType;
92+
import org.hibernate.type.descriptor.jdbc.LocalDateTimeJdbcType;
93+
import org.hibernate.type.descriptor.jdbc.LocalTimeJdbcType;
8194
import org.hibernate.type.descriptor.jdbc.ObjectNullResolvingJdbcType;
95+
import org.hibernate.type.descriptor.jdbc.OffsetDateTimeJdbcType;
96+
import org.hibernate.type.descriptor.jdbc.OffsetTimeJdbcType;
8297
import org.hibernate.type.descriptor.jdbc.SmallIntJdbcType;
8398
import org.hibernate.type.descriptor.jdbc.VarbinaryJdbcType;
8499
import org.hibernate.type.descriptor.jdbc.VarcharJdbcType;
85100
import org.hibernate.type.descriptor.jdbc.XmlJdbcType;
101+
import org.hibernate.type.descriptor.jdbc.ZonedDateTimeJdbcType;
86102
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
87103
import org.hibernate.type.descriptor.sql.internal.CapacityDependentDdlType;
88104
import org.hibernate.type.descriptor.sql.internal.DdlTypeImpl;
@@ -888,6 +904,12 @@ public String getCurrentTimestampSelectString() {
888904
return "values current timestamp";
889905
}
890906

907+
@Override
908+
public boolean doesRoundTemporalOnOverflow() {
909+
// DB2 does truncation
910+
return false;
911+
}
912+
891913
@Override
892914
public boolean isCurrentTimestampSelectStringCallable() {
893915
return false;
@@ -960,6 +982,49 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
960982
.getDescriptor( Object.class )
961983
)
962984
);
985+
986+
typeContributions.contributeJdbcType( new InstantJdbcType() {
987+
@Override
988+
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
989+
return new DB2GetObjectExtractor<>( javaType, this, Instant.class );
990+
}
991+
} );
992+
typeContributions.contributeJdbcType( new LocalDateTimeJdbcType() {
993+
@Override
994+
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
995+
return new DB2GetObjectExtractor<>( javaType, this, LocalDateTime.class );
996+
}
997+
} );
998+
typeContributions.contributeJdbcType( new LocalDateJdbcType() {
999+
@Override
1000+
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
1001+
return new DB2GetObjectExtractor<>( javaType, this, LocalDate.class );
1002+
}
1003+
} );
1004+
typeContributions.contributeJdbcType( new LocalTimeJdbcType() {
1005+
@Override
1006+
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
1007+
return new DB2GetObjectExtractor<>( javaType, this, LocalTime.class );
1008+
}
1009+
} );
1010+
typeContributions.contributeJdbcType( new OffsetDateTimeJdbcType() {
1011+
@Override
1012+
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
1013+
return new DB2GetObjectExtractor<>( javaType, this, OffsetDateTime.class );
1014+
}
1015+
} );
1016+
typeContributions.contributeJdbcType( new OffsetTimeJdbcType() {
1017+
@Override
1018+
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
1019+
return new DB2GetObjectExtractor<>( javaType, this, OffsetTime.class );
1020+
}
1021+
} );
1022+
typeContributions.contributeJdbcType( new ZonedDateTimeJdbcType() {
1023+
@Override
1024+
public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
1025+
return new DB2GetObjectExtractor<>( javaType, this, ZonedDateTime.class );
1026+
}
1027+
} );
9631028
}
9641029

9651030
@Override
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.dialect;
8+
9+
import java.sql.CallableStatement;
10+
import java.sql.ResultSet;
11+
import java.sql.SQLException;
12+
13+
import org.hibernate.type.descriptor.WrapperOptions;
14+
import org.hibernate.type.descriptor.java.JavaType;
15+
import org.hibernate.type.descriptor.jdbc.JavaTimeJdbcType;
16+
import org.hibernate.type.descriptor.jdbc.internal.GetObjectExtractor;
17+
18+
/**
19+
* Variant of the {@link GetObjectExtractor} that catches a {@link NullPointerException},
20+
* because the DB2 JDBC driver runs into that exception when trying to access a {@code null} value
21+
* with the {@code getObject(int, Class)} and {@code getObject(String, Class)} methods.
22+
*
23+
* @author Christian Beikov
24+
*/
25+
public class DB2GetObjectExtractor<T> extends GetObjectExtractor<T> {
26+
public DB2GetObjectExtractor(
27+
JavaType<T> javaType,
28+
JavaTimeJdbcType jdbcType,
29+
Class<?> baseClass) {
30+
super( javaType, jdbcType, baseClass );
31+
}
32+
33+
@Override
34+
protected T doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
35+
try {
36+
return super.doExtract( rs, paramIndex, options );
37+
}
38+
catch (NullPointerException ex) {
39+
final Object object = rs.getObject( paramIndex );
40+
if ( object == null ) {
41+
return null;
42+
}
43+
throw ex;
44+
}
45+
}
46+
47+
@Override
48+
protected T doExtract(CallableStatement statement, int paramIndex, WrapperOptions options) throws SQLException {
49+
try {
50+
return super.doExtract( statement, paramIndex, options );
51+
}
52+
catch (NullPointerException ex) {
53+
final Object object = statement.getObject( paramIndex );
54+
if ( object == null ) {
55+
return null;
56+
}
57+
throw ex;
58+
}
59+
}
60+
61+
@Override
62+
protected T doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
63+
try {
64+
return super.doExtract( statement, name, options );
65+
}
66+
catch (NullPointerException ex) {
67+
final Object object = statement.getObject( name );
68+
if ( object == null ) {
69+
return null;
70+
}
71+
throw ex;
72+
}
73+
}
74+
}

hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ public int getDoublePrecision() {
307307
return 52;
308308
}
309309

310+
@Override
311+
public int getDefaultTimestampPrecision() {
312+
return 9;
313+
}
314+
310315
@Override
311316
public void initializeFunctionRegistry(FunctionContributions functionContributions) {
312317
super.initializeFunctionRegistry(functionContributions);

hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4779,6 +4779,15 @@ public int getDefaultTimestampPrecision() {
47794779
return 6; //microseconds!
47804780
}
47814781

4782+
/**
4783+
* Does this dialect round a temporal when converting from a precision higher to a lower one?
4784+
*
4785+
* @return true if rounding is applied, false if truncation is applied
4786+
*/
4787+
public boolean doesRoundTemporalOnOverflow() {
4788+
return true;
4789+
}
4790+
47824791
/**
47834792
* This is the default precision for a generated
47844793
* column mapped to a Java {@link Float} or

hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,12 @@ public String getCurrentTimestampSelectString() {
583583
return "values current_timestamp";
584584
}
585585

586+
@Override
587+
public boolean doesRoundTemporalOnOverflow() {
588+
// HSQLDB does truncation
589+
return false;
590+
}
591+
586592
@Override
587593
public boolean supportsCommentOn() {
588594
return true;

0 commit comments

Comments
 (0)