@Override public String processSql(String sql, RowSelection selection) { if (LimitHelper.useLimit( this, selection )) { return sql + (LimitHelper.hasFirstRow( selection ) ? " offset ? rows fetch next ? rows only" : " fetch first ? rows only"); } else { // or return unaltered SQL return sql; } }
@Override public String processSql(String sql, RowSelection selection) { if ( LimitHelper.useLimit( this, selection ) ) { // useLimitOffset: whether "offset" is set or not; // if set, use "LIMIT offset, row_count" syntax; // if not, use "LIMIT row_count" final boolean useLimitOffset = LimitHelper.hasFirstRow( selection ); return sql + (useLimitOffset ? " limit ?, ?" : " limit ?"); } else { // or return unaltered SQL return sql; } } }
/** * Build LIMIT clause handler applicable for given selection criteria. Returns {@link org.hibernate.dialect.pagination.NoopLimitHandler} delegate * if dialect does not support LIMIT expression or processed query does not use pagination. * * @param selection Selection criteria. * @return LIMIT clause delegate. */ protected LimitHandler getLimitHandler(RowSelection selection) { final LimitHandler limitHandler = getFactory().getDialect().getLimitHandler(); return LimitHelper.useLimit( limitHandler, selection ) ? limitHandler : NoopLimitHandler.INSTANCE; }
/** * Build LIMIT clause handler applicable for given selection criteria. Returns {@link NoopLimitHandler} delegate * if dialect does not support LIMIT expression or processed query does not use pagination. * * @param selection Selection criteria. * * @return LIMIT clause delegate. */ protected LimitHandler getLimitHandler(RowSelection selection) { final LimitHandler limitHandler = getFactory().getDialect().getLimitHandler(); return LimitHelper.useLimit( limitHandler, selection ) ? limitHandler : NoopLimitHandler.INSTANCE; }
@Override public String processSql(String sql, RowSelection selection) { // SQLServer mandates the following rules to use OFFSET/LIMIT // * An 'ORDER BY' is required // * The 'OFFSET ...' clause is mandatory, cannot use 'FETCH ...' by itself. // * The 'TOP' clause isn't permitted with LIMIT/OFFSET. if ( hasOrderBy( sql ) ) { if ( !LimitHelper.useLimit( this, selection ) ) { return sql; } return applyOffsetFetch( selection, sql, getInsertPosition( sql ) ); } return super.processSql( sql, selection ); }
private ResultSet processResultSet( ResultSet rs, final RowSelection selection, final LimitHandler limitHandler, final boolean autodiscovertypes, final SharedSessionContractImplementor session ) throws SQLException, HibernateException { rs = wrapResultSetIfEnabled( rs, session ); if ( !limitHandler.supportsLimitOffset() || !LimitHelper.useLimit( limitHandler, selection ) ) { advance( rs, selection ); } if ( autodiscovertypes ) { autoDiscoverTypes( rs ); } return rs; }
/** * Execute given <tt>PreparedStatement</tt>, advance to the first result and return SQL <tt>ResultSet</tt>. */ protected final ResultSet getResultSet( final PreparedStatement st, final RowSelection selection, final LimitHandler limitHandler, final boolean autodiscovertypes, final SharedSessionContractImplementor session) throws SQLException, HibernateException { try { ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract( st ); rs = wrapResultSetIfEnabled( rs , session ); if ( !limitHandler.supportsLimitOffset() || !LimitHelper.useLimit( limitHandler, selection ) ) { advance( rs, selection ); } if ( autodiscovertypes ) { autoDiscoverTypes( rs ); } return rs; } catch (SQLException | HibernateException ex) { session.getJdbcCoordinator().getResourceRegistry().release( st ); session.getJdbcCoordinator().afterStatementExecution(); throw ex; } }
final Dialect dialect = getFactory().getDialect(); final RowSelection selection = queryParameters.getRowSelection(); final boolean useLimit = LimitHelper.useLimit( limitHandler, selection ); final boolean hasFirstRow = LimitHelper.hasFirstRow( selection ); final boolean useLimitOffset = hasFirstRow && useLimit && limitHandler.supportsLimitOffset();
final Dialect dialect = session.getJdbcServices().getJdbcEnvironment().getDialect(); final RowSelection selection = queryParameters.getRowSelection(); final boolean useLimit = LimitHelper.useLimit( limitHandler, selection ); final boolean hasFirstRow = LimitHelper.hasFirstRow( selection ); final boolean useLimitOffset = hasFirstRow && useLimit && limitHandler.supportsLimitOffset();
@Override public String processSql(String sql, RowSelection selection) { if (LimitHelper.useLimit( this, selection )) { return sql + (LimitHelper.hasFirstRow( selection ) ? " offset ? rows fetch next ? rows only" : " fetch first ? rows only"); } else { // or return unaltered SQL return sql; } }
@Override public String processSql(String sql, RowSelection selection) { if ( LimitHelper.useLimit( this, selection ) ) { // useLimitOffset: whether "offset" is set or not; // if set, use "LIMIT offset, row_count" syntax; // if not, use "LIMIT row_count" final boolean useLimitOffset = LimitHelper.hasFirstRow( selection ); return sql + (useLimitOffset ? " limit ?, ?" : " limit ?"); } else { // or return unaltered SQL return sql; } } }
@Override public String processSql(String sql, RowSelection selection) { // SQLServer mandates the following rules to use OFFSET/LIMIT // * An 'ORDER BY' is required // * The 'OFFSET ...' clause is mandatory, cannot use 'FETCH ...' by itself. // * The 'TOP' clause isn't permitted with LIMIT/OFFSET. if ( hasOrderBy( sql ) ) { if ( !LimitHelper.useLimit( this, selection ) ) { return sql; } return applyOffsetFetch( selection, sql, getInsertPosition( sql ) ); } return super.processSql( sql, selection ); }