clean up version stuff in DB2i/z dialects
This commit is contained in:
parent
e992b41756
commit
bd9276d6d7
|
@ -33,34 +33,31 @@ import org.hibernate.sql.exec.spi.JdbcOperation;
|
|||
*/
|
||||
public class DB2iDialect extends DB2Dialect {
|
||||
|
||||
private final int version;
|
||||
private final DatabaseVersion version;
|
||||
|
||||
public DB2iDialect(DialectResolutionInfo info) {
|
||||
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
|
||||
this( info.makeCopy() );
|
||||
registerKeywords( info );
|
||||
}
|
||||
|
||||
public DB2iDialect() {
|
||||
this( 700 );
|
||||
this( DatabaseVersion.make(7) );
|
||||
}
|
||||
|
||||
public DB2iDialect(int version) {
|
||||
public DB2iDialect(DatabaseVersion version) {
|
||||
super();
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public int getIVersion() {
|
||||
public DatabaseVersion getIVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UniqueDelegate createUniqueDelegate() {
|
||||
if ( getIVersion() >= 730 ) {
|
||||
return new DefaultUniqueDelegate( this );
|
||||
}
|
||||
else {
|
||||
return super.createUniqueDelegate();
|
||||
}
|
||||
return getIVersion().isSameOrAfter(7, 3)
|
||||
? new DefaultUniqueDelegate(this)
|
||||
: super.createUniqueDelegate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,17 +65,13 @@ public class DB2iDialect extends DB2Dialect {
|
|||
*/
|
||||
@Override
|
||||
public SequenceSupport getSequenceSupport() {
|
||||
if ( getIVersion() >= 730 ) {
|
||||
return DB2iSequenceSupport.INSTANCE;
|
||||
}
|
||||
else {
|
||||
return NoSequenceSupport.INSTANCE;
|
||||
}
|
||||
return getIVersion().isSameOrAfter(7, 3)
|
||||
? DB2iSequenceSupport.INSTANCE : NoSequenceSupport.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQuerySequencesString() {
|
||||
if ( getIVersion() >= 730 ) {
|
||||
if ( getIVersion().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";
|
||||
|
@ -90,22 +83,15 @@ public class DB2iDialect extends DB2Dialect {
|
|||
|
||||
@Override
|
||||
public LimitHandler getLimitHandler() {
|
||||
if ( getIVersion() >= 730) {
|
||||
return FetchLimitHandler.INSTANCE;
|
||||
}
|
||||
else {
|
||||
return LegacyDB2LimitHandler.INSTANCE;
|
||||
}
|
||||
return getIVersion().isSameOrAfter(7, 3)
|
||||
? FetchLimitHandler.INSTANCE : LegacyDB2LimitHandler.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
if ( getIVersion() >= 730) {
|
||||
return new DB2IdentityColumnSupport();
|
||||
}
|
||||
else {
|
||||
return new DB2390IdentityColumnSupport();
|
||||
}
|
||||
return getIVersion().isSameOrAfter(7, 3)
|
||||
? new DB2IdentityColumnSupport()
|
||||
: new DB2390IdentityColumnSupport();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,9 +21,9 @@ import org.hibernate.sql.exec.spi.JdbcOperation;
|
|||
*/
|
||||
public class DB2iSqlAstTranslator<T extends JdbcOperation> extends DB2SqlAstTranslator<T> {
|
||||
|
||||
private final int version;
|
||||
private final DatabaseVersion version;
|
||||
|
||||
public DB2iSqlAstTranslator(SessionFactoryImplementor sessionFactory, Statement statement, int version) {
|
||||
public DB2iSqlAstTranslator(SessionFactoryImplementor sessionFactory, Statement statement, DatabaseVersion version) {
|
||||
super( sessionFactory, statement );
|
||||
this.version = version;
|
||||
}
|
||||
|
@ -34,13 +34,13 @@ public class DB2iSqlAstTranslator<T extends JdbcOperation> extends DB2SqlAstTran
|
|||
// According to LegacyDB2LimitHandler, variable limit also isn't supported before 7.1
|
||||
return getQueryPartForRowNumbering() != queryPart && (
|
||||
useOffsetFetchClause( queryPart ) && !isRowsOnlyFetchClauseType( queryPart )
|
||||
|| version < 710 && ( queryPart.isRoot() && hasLimit() || !( queryPart.getFetchClauseExpression() instanceof Literal ) )
|
||||
|| version.isBefore(7, 10) && ( queryPart.isRoot() && hasLimit() || !( queryPart.getFetchClauseExpression() instanceof Literal ) )
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsOffsetClause() {
|
||||
return version >= 710;
|
||||
return version.isSameOrAfter(7, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.dialect;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import jakarta.persistence.TemporalType;
|
||||
|
||||
import org.hibernate.dialect.identity.DB2390IdentityColumnSupport;
|
||||
|
@ -27,6 +25,8 @@ import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
|
|||
import org.hibernate.sql.ast.tree.Statement;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperation;
|
||||
|
||||
import static org.hibernate.type.SqlTypes.TIMESTAMP_WITH_TIMEZONE;
|
||||
|
||||
/**
|
||||
* An SQL dialect for DB2 for z/OS, previously known as known as Db2 UDB for z/OS and Db2 UDB for z/OS and OS/390.
|
||||
*
|
||||
|
@ -34,46 +34,50 @@ import org.hibernate.sql.exec.spi.JdbcOperation;
|
|||
*/
|
||||
public class DB2zDialect extends DB2Dialect {
|
||||
|
||||
private final int version;
|
||||
private final DatabaseVersion version;
|
||||
|
||||
public DB2zDialect(DialectResolutionInfo info) {
|
||||
this( info.getDatabaseMajorVersion() * 100 + info.getDatabaseMinorVersion() * 10 );
|
||||
this( info.makeCopy() );
|
||||
registerKeywords( info );
|
||||
}
|
||||
|
||||
public DB2zDialect() {
|
||||
this( 700 );
|
||||
this( DatabaseVersion.make(7) );
|
||||
}
|
||||
|
||||
public DB2zDialect(int version) {
|
||||
public DB2zDialect(DatabaseVersion version) {
|
||||
super();
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
if ( version > 1000 ) {
|
||||
// See https://www.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/wnew/src/tpc/db2z_10_timestamptimezone.html
|
||||
registerColumnType( Types.TIMESTAMP_WITH_TIMEZONE, "timestamp with time zone" );
|
||||
@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) ) {
|
||||
return "timestamp with time zone";
|
||||
}
|
||||
return super.columnType(jdbcTypeCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeZoneSupport getTimeZoneSupport() {
|
||||
return getZVersion() > 1000 ? TimeZoneSupport.NATIVE : TimeZoneSupport.NONE;
|
||||
return getZVersion().isAfter(10) ? TimeZoneSupport.NATIVE : TimeZoneSupport.NONE;
|
||||
}
|
||||
|
||||
int getZVersion() {
|
||||
DatabaseVersion getZVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SequenceSupport getSequenceSupport() {
|
||||
return getZVersion() < 800
|
||||
return getZVersion().isBefore(8)
|
||||
? NoSequenceSupport.INSTANCE
|
||||
: DB2zSequenceSupport.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQuerySequencesString() {
|
||||
return getZVersion() < 800 ? null : "select * from sysibm.syssequences";
|
||||
return getZVersion().isBefore(8) ? null : "select * from sysibm.syssequences";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,9 +21,9 @@ import org.hibernate.sql.exec.spi.JdbcOperation;
|
|||
*/
|
||||
public class DB2zSqlAstTranslator<T extends JdbcOperation> extends DB2SqlAstTranslator<T> {
|
||||
|
||||
private final int version;
|
||||
private final DatabaseVersion version;
|
||||
|
||||
public DB2zSqlAstTranslator(SessionFactoryImplementor sessionFactory, Statement statement, int version) {
|
||||
public DB2zSqlAstTranslator(SessionFactoryImplementor sessionFactory, Statement statement, DatabaseVersion version) {
|
||||
super( sessionFactory, statement );
|
||||
this.version = version;
|
||||
}
|
||||
|
@ -34,14 +34,14 @@ public class DB2zSqlAstTranslator<T extends JdbcOperation> extends DB2SqlAstTran
|
|||
// Also, variable limit isn't supported before 12.0
|
||||
return getQueryPartForRowNumbering() != queryPart && (
|
||||
useOffsetFetchClause( queryPart ) && !isRowsOnlyFetchClauseType( queryPart )
|
||||
|| version < 1200 && queryPart.isRoot() && hasLimit()
|
||||
|| version < 1200 && queryPart.getFetchClauseExpression() != null && !( queryPart.getFetchClauseExpression() instanceof Literal )
|
||||
|| version.isBefore(12) && queryPart.isRoot() && hasLimit()
|
||||
|| version.isBefore(12) && queryPart.getFetchClauseExpression() != null && !( queryPart.getFetchClauseExpression() instanceof Literal )
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsOffsetClause() {
|
||||
return version >= 1200;
|
||||
return version.isSameOrAfter(12);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue