org.hibernate.community.dialect.DB2iLegacySqlAstTranslator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-community-dialects Show documentation
Show all versions of hibernate-community-dialects Show documentation
Hibernate's community supported dialects
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.community.dialect;
import org.hibernate.dialect.DatabaseVersion;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.sqm.ComparisonOperator;
import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.ast.tree.expression.Expression;
import org.hibernate.sql.ast.tree.expression.Literal;
import org.hibernate.sql.ast.tree.select.QueryPart;
import org.hibernate.sql.exec.spi.JdbcOperation;
import static org.hibernate.community.dialect.DB2iLegacyDialect.DB2_LUW_VERSION9;
/**
* A SQL AST translator for DB2i.
*
* @author Christian Beikov
*/
public class DB2iLegacySqlAstTranslator extends DB2LegacySqlAstTranslator {
private final DatabaseVersion version;
public DB2iLegacySqlAstTranslator(SessionFactoryImplementor sessionFactory, Statement statement, DatabaseVersion version) {
super( sessionFactory, statement );
this.version = version;
}
@Override
protected boolean shouldEmulateFetchClause(QueryPart queryPart) {
// Check if current query part is already row numbering to avoid infinite recursion
if ( getQueryPartForRowNumbering() == queryPart ) {
return false;
}
// Percent fetches or ties fetches aren't supported in DB2
if ( useOffsetFetchClause( queryPart ) && !isRowsOnlyFetchClauseType( queryPart ) ) {
return true;
}
// According to LegacyDB2LimitHandler, variable limit also isn't supported before 7.10
return version.isBefore(7, 10)
&& queryPart.getFetchClauseExpression() != null
&& !( queryPart.getFetchClauseExpression() instanceof Literal );
}
@Override
protected boolean supportsOffsetClause() {
return version.isSameOrAfter(7, 10);
}
@Override
protected void renderComparison(Expression lhs, ComparisonOperator operator, Expression rhs) {
renderComparisonStandard( lhs, operator, rhs );
}
@Override
public DatabaseVersion getDB2Version() {
return DB2_LUW_VERSION9;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy