Skip to content

Commit a00ee60

Browse files
committed
HHH-18641 Remove support for DB2i versions older than 7.2 and modernize some DB2z stuff
1 parent e769668 commit a00ee60

File tree

5 files changed

+13
-71
lines changed

5 files changed

+13
-71
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ protected boolean shouldEmulateFetchClause(QueryPart queryPart) {
4040
if ( useOffsetFetchClause( queryPart ) && !isRowsOnlyFetchClauseType( queryPart ) ) {
4141
return true;
4242
}
43-
// According to LegacyDB2LimitHandler, variable limit also isn't supported before 7.10
44-
return version.isBefore(7, 10)
43+
// According to LegacyDB2LimitHandler, variable limit also isn't supported before 7.1
44+
return version.isBefore(7, 1)
4545
&& queryPart.getFetchClauseExpression() != null
4646
&& !( queryPart.getFetchClauseExpression() instanceof Literal );
4747
}
4848

4949
@Override
5050
protected boolean supportsOffsetClause() {
51-
return version.isSameOrAfter(7, 10);
51+
return version.isSameOrAfter(7, 1);
5252
}
5353

5454
@Override

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
import jakarta.persistence.Timeout;
88
import org.hibernate.Timeouts;
9-
import org.hibernate.boot.model.FunctionContributions;
10-
import org.hibernate.dialect.function.CommonFunctionFactory;
119
import org.hibernate.dialect.identity.DB2IdentityColumnSupport;
1210
import org.hibernate.dialect.identity.DB2zIdentityColumnSupport;
1311
import org.hibernate.dialect.identity.IdentityColumnSupport;
@@ -32,14 +30,14 @@
3230
import static org.hibernate.type.SqlTypes.ROWID;
3331

3432
/**
35-
* A SQL dialect for DB2 for IBM i version 7.1 and above, previously known as "DB2/400".
33+
* A SQL dialect for DB2 for IBM i version 7.2 and above, previously known as "DB2/400".
3634
*
3735
* @author Peter DeGregorio (pdegregorio)
3836
* @author Christian Beikov
3937
*/
4038
public class DB2iDialect extends DB2Dialect {
4139

42-
private final static DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 7, 1 );
40+
private final static DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 7, 2 );
4341
public final static DatabaseVersion DB2_LUW_VERSION = DB2Dialect.MINIMUM_VERSION;
4442

4543
private static final String FOR_UPDATE_SQL = " for update with rs";
@@ -63,17 +61,6 @@ protected DatabaseVersion getMinimumSupportedVersion() {
6361
return MINIMUM_VERSION;
6462
}
6563

66-
@Override
67-
public void initializeFunctionRegistry(FunctionContributions functionContributions) {
68-
super.initializeFunctionRegistry( functionContributions );
69-
if ( getVersion().isSameOrAfter( 7, 2 ) ) {
70-
final var functionFactory = new CommonFunctionFactory( functionContributions );
71-
functionFactory.listagg( null );
72-
functionFactory.inverseDistributionOrderedSetAggregates();
73-
functionFactory.hypotheticalOrderedSetAggregates_windowEmulation();
74-
}
75-
}
76-
7764
@Override
7865
public DatabaseVersion getDB2Version() {
7966
return DB2_LUW_VERSION;
@@ -98,8 +85,8 @@ public boolean supportsIfExistsBeforeTableName() {
9885

9986
@Override
10087
public boolean supportsUpdateReturning() {
101-
// Only supported for insert statements on DB2 for i: https://www.ibm.com/docs/en/i/7.1?topic=clause-table-reference
102-
return false;
88+
// Only supported as of version 7.6: https://www.ibm.com/docs/en/i/7.6.0?topic=clause-table-reference
89+
return getVersion().isSameOrAfter( 7, 6 );
10390
}
10491

10592
/**

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

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
package org.hibernate.dialect;
66

77

8-
import org.hibernate.boot.model.FunctionContributions;
9-
import org.hibernate.dialect.function.CommonFunctionFactory;
108
import org.hibernate.dialect.identity.DB2zIdentityColumnSupport;
119
import org.hibernate.dialect.identity.IdentityColumnSupport;
1210
import org.hibernate.dialect.pagination.LimitHandler;
@@ -65,28 +63,13 @@ protected DatabaseVersion getMinimumSupportedVersion() {
6563
return MINIMUM_VERSION;
6664
}
6765

68-
@Override
69-
public void initializeFunctionRegistry(FunctionContributions functionContributions) {
70-
super.initializeFunctionRegistry( functionContributions );
71-
if ( getVersion().isSameOrAfter( 12 ) ) {
72-
final var functionFactory = new CommonFunctionFactory( functionContributions );
73-
functionFactory.listagg( null );
74-
functionFactory.inverseDistributionOrderedSetAggregates();
75-
functionFactory.hypotheticalOrderedSetAggregates_windowEmulation();
76-
}
77-
}
78-
7966
@Override
8067
protected String columnType(int sqlTypeCode) {
81-
if ( getVersion().isAfter( 10 ) ) {
82-
switch ( sqlTypeCode ) {
83-
case TIME_WITH_TIMEZONE:
84-
case TIMESTAMP_WITH_TIMEZONE:
85-
// See https://www.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/wnew/src/tpc/db2z_10_timestamptimezone.html
86-
return "timestamp with time zone";
87-
}
88-
}
89-
return super.columnType( sqlTypeCode );
68+
return switch ( sqlTypeCode ) {
69+
// See https://www.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/wnew/src/tpc/db2z_10_timestamptimezone.html
70+
case TIME_WITH_TIMEZONE, TIMESTAMP_WITH_TIMEZONE -> "timestamp with time zone";
71+
default -> super.columnType( sqlTypeCode );
72+
};
9073
}
9174

9275
@Override
@@ -113,7 +96,7 @@ public String getCreateIndexTail(boolean unique, List<Column> columns) {
11396

11497
@Override
11598
public TimeZoneSupport getTimeZoneSupport() {
116-
return getVersion().isAfter(10) ? TimeZoneSupport.NATIVE : TimeZoneSupport.NONE;
99+
return TimeZoneSupport.NATIVE;
117100
}
118101

119102
@Override

hibernate-core/src/main/java/org/hibernate/dialect/sql/ast/DB2iSqlAstTranslator.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import org.hibernate.query.sqm.ComparisonOperator;
1010
import org.hibernate.sql.ast.tree.Statement;
1111
import org.hibernate.sql.ast.tree.expression.Expression;
12-
import org.hibernate.sql.ast.tree.expression.Literal;
13-
import org.hibernate.sql.ast.tree.select.QueryPart;
1412
import org.hibernate.sql.exec.spi.JdbcOperation;
1513

1614
import static org.hibernate.dialect.DB2iDialect.DB2_LUW_VERSION;
@@ -29,27 +27,6 @@ public DB2iSqlAstTranslator(SessionFactoryImplementor sessionFactory, Statement
2927
this.version = version;
3028
}
3129

32-
@Override
33-
protected boolean shouldEmulateFetchClause(QueryPart queryPart) {
34-
// Check if current query part is already row numbering to avoid infinite recursion
35-
if ( getQueryPartForRowNumbering() == queryPart ) {
36-
return false;
37-
}
38-
// Percent fetches or ties fetches aren't supported in DB2
39-
if ( useOffsetFetchClause( queryPart ) && !isRowsOnlyFetchClauseType( queryPart ) ) {
40-
return true;
41-
}
42-
// According to LegacyDB2LimitHandler, variable limit also isn't supported before 7.10
43-
return version.isBefore(7, 10)
44-
&& queryPart.getFetchClauseExpression() != null
45-
&& !( queryPart.getFetchClauseExpression() instanceof Literal );
46-
}
47-
48-
@Override
49-
protected boolean supportsOffsetClause() {
50-
return version.isSameOrAfter(7, 10);
51-
}
52-
5330
@Override
5431
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
5532
renderComparisonStandard( lhs, operator, rhs );

hibernate-core/src/main/java/org/hibernate/dialect/sql/ast/DB2zSqlAstTranslator.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ protected boolean shouldEmulateFetchClause(QueryPart queryPart) {
3636
return getQueryPartForRowNumbering() != queryPart && ( useOffsetFetchClause( queryPart ) && !isRowsOnlyFetchClauseType( queryPart ) );
3737
}
3838

39-
@Override
40-
protected boolean supportsOffsetClause() {
41-
return version.isSameOrAfter(12);
42-
}
43-
4439
@Override
4540
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
4641
// Supported at least since DB2 z/OS 9.0

0 commit comments

Comments
 (0)