From d9bae6f31e401119605576f93ce474b3d4ecae6a Mon Sep 17 00:00:00 2001 From: Atgoogat <36623640+Atgoogat@users.noreply.github.com> Date: Fri, 21 Jan 2022 12:52:57 +0100 Subject: [PATCH] HHH-15046: fix nullptr problem with db2z/i dialect intialization --- .../org/hibernate/dialect/DB2iDialect.java | 23 +++++++------------ .../org/hibernate/dialect/DB2zDialect.java | 21 ++++++----------- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java index bb8dbdbfcc..a5902af6ce 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java @@ -33,8 +33,6 @@ import org.hibernate.sql.exec.spi.JdbcOperation; */ public class DB2iDialect extends DB2Dialect { - private final DatabaseVersion version; - public DB2iDialect(DialectResolutionInfo info) { this( info.makeCopy() ); registerKeywords( info ); @@ -45,17 +43,12 @@ public class DB2iDialect extends DB2Dialect { } public DB2iDialect(DatabaseVersion version) { - super(); - this.version = version; - } - - public DatabaseVersion getIVersion() { - return version; + super(version); } @Override protected UniqueDelegate createUniqueDelegate() { - return getIVersion().isSameOrAfter(7, 3) + return getVersion().isSameOrAfter(7, 3) ? new DefaultUniqueDelegate(this) : super.createUniqueDelegate(); } @@ -65,13 +58,13 @@ public class DB2iDialect extends DB2Dialect { */ @Override public SequenceSupport getSequenceSupport() { - return getIVersion().isSameOrAfter(7, 3) + return getVersion().isSameOrAfter(7, 3) ? DB2iSequenceSupport.INSTANCE : NoSequenceSupport.INSTANCE; } @Override public String getQuerySequencesString() { - if ( getIVersion().isSameOrAfter(7,3) ) { + if ( getVersion().isSameOrAfter(7,3) ) { return "select distinct sequence_name from qsys2.syssequences " + "where current_schema='*LIBL' and sequence_schema in (select schema_name from qsys2.library_list_info) " + "or sequence_schema=current_schema"; @@ -83,13 +76,13 @@ public class DB2iDialect extends DB2Dialect { @Override public LimitHandler getLimitHandler() { - return getIVersion().isSameOrAfter(7, 3) + return getVersion().isSameOrAfter(7, 3) ? FetchLimitHandler.INSTANCE : LegacyDB2LimitHandler.INSTANCE; } @Override public IdentityColumnSupport getIdentityColumnSupport() { - return getIVersion().isSameOrAfter(7, 3) + return getVersion().isSameOrAfter(7, 3) ? new DB2IdentityColumnSupport() : new DB2390IdentityColumnSupport(); } @@ -101,7 +94,7 @@ public class DB2iDialect extends DB2Dialect { @Override public boolean supportsLateral() { - return getIVersion().isSameOrAfter( 7, 1 ); + return getVersion().isSameOrAfter( 7, 1 ); } @Override @@ -110,7 +103,7 @@ public class DB2iDialect extends DB2Dialect { @Override protected SqlAstTranslator buildTranslator( SessionFactoryImplementor sessionFactory, Statement statement) { - return new DB2iSqlAstTranslator<>( sessionFactory, statement, version ); + return new DB2iSqlAstTranslator<>( sessionFactory, statement, getVersion() ); } }; } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java index 88e19b481a..f6d68b74fd 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java @@ -35,8 +35,6 @@ import static org.hibernate.type.SqlTypes.TIMESTAMP_WITH_TIMEZONE; */ public class DB2zDialect extends DB2Dialect { - private final DatabaseVersion version; - public DB2zDialect(DialectResolutionInfo info) { this( info.makeCopy() ); registerKeywords( info ); @@ -47,14 +45,13 @@ public class DB2zDialect extends DB2Dialect { } public DB2zDialect(DatabaseVersion version) { - super(); - this.version = version; + super(version); } @Override protected String columnType(int jdbcTypeCode) { // See https://www.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/wnew/src/tpc/db2z_10_timestamptimezone.html - if ( jdbcTypeCode==TIMESTAMP_WITH_TIMEZONE && version.isAfter(10) ) { + if ( jdbcTypeCode==TIMESTAMP_WITH_TIMEZONE && getVersion().isAfter(10) ) { return "timestamp with time zone"; } return super.columnType(jdbcTypeCode); @@ -62,28 +59,24 @@ public class DB2zDialect extends DB2Dialect { @Override public TimeZoneSupport getTimeZoneSupport() { - return getZVersion().isAfter(10) ? TimeZoneSupport.NATIVE : TimeZoneSupport.NONE; - } - - DatabaseVersion getZVersion() { - return version; + return getVersion().isAfter(10) ? TimeZoneSupport.NATIVE : TimeZoneSupport.NONE; } @Override public SequenceSupport getSequenceSupport() { - return getZVersion().isBefore(8) + return getVersion().isBefore(8) ? NoSequenceSupport.INSTANCE : DB2zSequenceSupport.INSTANCE; } @Override public String getQuerySequencesString() { - return getZVersion().isBefore(8) ? null : "select * from sysibm.syssequences"; + return getVersion().isBefore(8) ? null : "select * from sysibm.syssequences"; } @Override public LimitHandler getLimitHandler() { - return getZVersion().isBefore(12) + return getVersion().isBefore(12) ? FetchLimitHandler.INSTANCE : OffsetFetchLimitHandler.INSTANCE; } @@ -160,7 +153,7 @@ public class DB2zDialect extends DB2Dialect { @Override protected SqlAstTranslator buildTranslator( SessionFactoryImplementor sessionFactory, Statement statement) { - return new DB2zSqlAstTranslator<>( sessionFactory, statement, version ); + return new DB2zSqlAstTranslator<>( sessionFactory, statement, getVersion() ); } }; }