From 4aea43bdb0e4cba3082e1c9f54d71c57166ea82c Mon Sep 17 00:00:00 2001 From: Pierrick Rouxel Date: Sun, 5 Aug 2018 22:10:04 +0200 Subject: [PATCH] HHH-12856 Cleanup DB2400Dialect --- .../internal/StrategySelectorBuilder.java | 4 +- .../org/hibernate/dialect/DB2400Dialect.java | 65 ------------------- ...7R1Dialect.java => DB2400V7R3Dialect.java} | 15 +++-- .../java/org/hibernate/dialect/Database.java | 12 +--- .../dialect/resolver/DialectFactoryTest.java | 1 - 5 files changed, 15 insertions(+), 82 deletions(-) rename hibernate-core/src/main/java/org/hibernate/dialect/{DB2400V7R1Dialect.java => DB2400V7R3Dialect.java} (70%) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java index cb79bb8863..89f9c5843d 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java @@ -28,7 +28,7 @@ import org.hibernate.dialect.Cache71Dialect; import org.hibernate.dialect.DB2390Dialect; import org.hibernate.dialect.DB2390V8Dialect; import org.hibernate.dialect.DB2400Dialect; -import org.hibernate.dialect.DB2400V7R1Dialect; +import org.hibernate.dialect.DB2400V7R3Dialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.DerbyTenFiveDialect; import org.hibernate.dialect.DerbyTenSevenDialect; @@ -203,7 +203,7 @@ public class StrategySelectorBuilder { addDialect( strategySelector, DB2390Dialect.class ); addDialect( strategySelector, DB2390V8Dialect.class ); addDialect( strategySelector, DB2400Dialect.class ); - addDialect( strategySelector, DB2400V7R1Dialect.class ); + addDialect( strategySelector, DB2400V7R3Dialect.class ); addDialect( strategySelector, DerbyTenFiveDialect.class ); addDialect( strategySelector, DerbyTenSixDialect.class ); addDialect( strategySelector, DerbyTenSevenDialect.class ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2400Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2400Dialect.java index c85faa3a4f..5d55f5168e 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2400Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2400Dialect.java @@ -21,81 +21,16 @@ import org.hibernate.engine.spi.RowSelection; */ public class DB2400Dialect extends DB2Dialect { - private static final AbstractLimitHandler LIMIT_HANDLER = new AbstractLimitHandler() { - @Override - public String processSql(String sql, RowSelection selection) { - if ( LimitHelper.hasFirstRow( selection ) ) { - //nest the main query in an outer select - return "select * from ( select inner2_.*, rownumber() over(order by order of inner2_) as rownumber_ from ( " - + sql + " fetch first " + getMaxOrLimit( selection ) + " rows only ) as inner2_ ) as inner1_ where rownumber_ > " - + selection.getFirstRow() + " order by rownumber_"; - } - return sql + " fetch first " + getMaxOrLimit( selection ) + " rows only"; - } - - @Override - public boolean supportsLimit() { - return true; - } - - @Override - public boolean useMaxForLimit() { - return true; - } - - @Override - public boolean supportsVariableLimit() { - return false; - } - }; - @Override public boolean supportsSequences() { return false; } - @Override - public boolean supportsLimit() { - return true; - } - @Override public String getQuerySequencesString() { return null; } - @Override - @SuppressWarnings("deprecation") - public boolean supportsLimitOffset() { - return false; - } - - @Override - public boolean useMaxForLimit() { - return true; - } - - @Override - public boolean supportsVariableLimit() { - return false; - } - - @Override - public String getLimitString(String sql, int offset, int limit) { - if ( offset > 0 ) { - throw new UnsupportedOperationException( "query result offset is not supported" ); - } - if ( limit == 0 ) { - return sql; - } - return sql + " fetch first " + limit + " rows only "; - } - - @Override - public LimitHandler getLimitHandler() { - return LIMIT_HANDLER; - } - @Override public String getForUpdateString() { return " for update with rs"; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2400V7R1Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2400V7R3Dialect.java similarity index 70% rename from hibernate-core/src/main/java/org/hibernate/dialect/DB2400V7R1Dialect.java rename to hibernate-core/src/main/java/org/hibernate/dialect/DB2400V7R3Dialect.java index 806ddb35bc..381f3b4b96 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2400V7R1Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2400V7R3Dialect.java @@ -6,6 +6,8 @@ */ package org.hibernate.dialect; +import org.hibernate.dialect.identity.DB2IdentityColumnSupport; +import org.hibernate.dialect.identity.IdentityColumnSupport; import org.hibernate.dialect.unique.DefaultUniqueDelegate; import org.hibernate.dialect.unique.UniqueDelegate; @@ -15,11 +17,11 @@ import org.hibernate.dialect.unique.UniqueDelegate; * * @author Pierrick Rouxel (pierrickrouxel) */ -public class DB2400V7R1Dialect extends DB2Dialect { +public class DB2400V7R3Dialect extends DB2400Dialect { private final UniqueDelegate uniqueDelegate; - public DB2400V7R1Dialect() { + public DB2400V7R3Dialect() { super(); uniqueDelegate = new DefaultUniqueDelegate(this); @@ -31,12 +33,17 @@ public class DB2400V7R1Dialect extends DB2Dialect { } @Override - public String getForUpdateString() { - return " for update with rs"; + public boolean supportsSequences() { + return true; } @Override public String getQuerySequencesString() { return "select seqname from qsys2.syssequences"; } + + @Override + public IdentityColumnSupport getIdentityColumnSupport() { + return new DB2IdentityColumnSupport(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Database.java b/hibernate-core/src/main/java/org/hibernate/dialect/Database.java index 3f4f8a835e..4cca9edc35 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Database.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Database.java @@ -47,7 +47,7 @@ public enum Database { DB2 { @Override public Class latestDialect() { - return DB2400V7R1Dialect.class; + return DB2400Dialect.class; } @Override @@ -55,15 +55,7 @@ public enum Database { final String databaseName = info.getDatabaseName(); if ( "DB2 UDB for AS/400".equals( databaseName ) ) { - final int majorVersion = info.getDatabaseMajorVersion(); - final int minorVersion = info.getDatabaseMinorVersion(); - - if ( majorVersion > 7 || ( majorVersion == 7 && minorVersion >= 1 ) ) { - return latestDialectInstance( this ); - } - else { - return new DB2400Dialect(); - } + return new DB2400Dialect(); } if ( databaseName.startsWith( "DB2/" ) ) { diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java b/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java index da7bae10f6..8c75ba5ee2 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java @@ -153,7 +153,6 @@ public class DialectFactoryTest extends BaseUnitTestCase { testDetermination( "DB2/LINUX390", DB2Dialect.class, resolver ); testDetermination( "DB2/AIX64", DB2Dialect.class, resolver ); testDetermination( "DB2 UDB for AS/400", DB2400Dialect.class, resolver ); - testDetermination( "DB2 UDB for AS/400", 7, 1, DB2400V7R1Dialect.class, resolver ); testDetermination( "Oracle", 8, Oracle8iDialect.class, resolver ); testDetermination( "Oracle", 9, Oracle9iDialect.class, resolver ); testDetermination( "Oracle", 10, Oracle10gDialect.class, resolver );