/** * Should limit be applied? * * @param limitHandler The limit handler * @param selection The row selection * * @return Whether limiting is indicated */ public static boolean useLimit(LimitHandler limitHandler, RowSelection selection) { return limitHandler.supportsLimit() && hasMaxRows( selection ); }
@Override public String processSql(String sql, RowSelection selection) { final String soff = " offset " + selection.getFirstRow(); final String slim = " fetch first " + getMaxOrLimit( selection ) + " rows only"; final StringBuilder sb = new StringBuilder( sql.length() + soff.length() + slim.length() ) .append( sql ); if (LimitHelper.hasFirstRow( selection )) { sb.append( soff ); } if (LimitHelper.hasMaxRows( selection )) { sb.append( slim ); } return sb.toString(); }
/** * Default implementation of binding parameter values needed by the LIMIT clause. * * @param selection the selection criteria for rows. * @param statement Statement to which to bind limit parameter values. * @param index Index from which to start binding. * @return The number of parameter values bound. * @throws SQLException Indicates problems binding parameter values. */ protected final int bindLimitParameters(RowSelection selection, PreparedStatement statement, int index) throws SQLException { if ( !supportsVariableLimit() || !LimitHelper.hasMaxRows( selection ) ) { return 0; } final int firstRow = convertToFirstRowValue( LimitHelper.getFirstRow( selection ) ); final int lastRow = getMaxOrLimit( selection ); final boolean hasFirstRow = supportsLimitOffset() && ( firstRow > 0 || forceLimitUsage() ); final boolean reverse = bindLimitParametersInReverseOrder(); if ( hasFirstRow ) { statement.setInt( index + ( reverse ? 1 : 0 ), firstRow ); } statement.setInt( index + ( reverse || !hasFirstRow ? 0 : 1 ), lastRow ); return hasFirstRow ? 2 : 1; }
@Override public void setMaxRows(RowSelection selection, PreparedStatement statement) throws SQLException { if ( LimitHelper.hasMaxRows( selection ) ) { int maxRows = selection.getMaxRows() + convertToFirstRowValue( LimitHelper.getFirstRow( selection ) ); // Use Integer.MAX_VALUE on overflow if ( maxRows < 0 ) { statement.setMaxRows( Integer.MAX_VALUE ); } else { statement.setMaxRows( maxRows ); } } } }
@Override public String processSql(String sql, RowSelection selection) { final boolean useLimitOffset = supportsLimit() && supportsLimitOffset() && LimitHelper.hasFirstRow( selection ) && LimitHelper.hasMaxRows( selection ); return dialect.getLimitString( sql, useLimitOffset ? LimitHelper.getFirstRow( selection ) : 0, getMaxOrLimit( selection ) ); } }
if ( LimitHelper.hasMaxRows( selection ) ) { maxRows = selection.getMaxRows(); LOG.tracef( "Limiting ResultSet processing to just %s rows", maxRows );
private List doTheLoad(String sql, QueryParameters queryParameters, SharedSessionContractImplementor session) throws SQLException { final RowSelection selection = queryParameters.getRowSelection(); final int maxRows = LimitHelper.hasMaxRows( selection ) ? selection.getMaxRows() : Integer.MAX_VALUE; final List<AfterLoadAction> afterLoadActions = new ArrayList<>(); final SqlStatementWrapper wrapper = executeQueryStatement( sql, queryParameters, false, afterLoadActions, session ); final ResultSet rs = wrapper.getResultSet(); final Statement st = wrapper.getStatement(); try { return processResultSet( rs, queryParameters, session, false, null, maxRows, afterLoadActions ); } finally { session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( st ); session.getJdbcCoordinator().afterStatementExecution(); } } }
private void doTheLoad(String sql, QueryParameters queryParameters, SharedSessionContractImplementor session) throws SQLException { final RowSelection selection = queryParameters.getRowSelection(); final int maxRows = LimitHelper.hasMaxRows( selection ) ? selection.getMaxRows() : Integer.MAX_VALUE; final List<AfterLoadAction> afterLoadActions = Collections.emptyList(); final SqlStatementWrapper wrapper = executeQueryStatement( sql, queryParameters, false, afterLoadActions, session ); final ResultSet rs = wrapper.getResultSet(); final Statement st = wrapper.getStatement(); try { processResultSet( rs, queryParameters, session, true, null, maxRows, afterLoadActions ); } finally { session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( st ); session.getJdbcCoordinator().afterStatementExecution(); } }
final int maxRows = LimitHelper.hasMaxRows( selection ) ? selection.getMaxRows() : Integer.MAX_VALUE;
/** * Should limit be applied? * * @param limitHandler The limit handler * @param selection The row selection * * @return Whether limiting is indicated */ public static boolean useLimit(LimitHandler limitHandler, RowSelection selection) { return limitHandler.supportsLimit() && hasMaxRows( selection ); }
@Override public String processSql(String sql, RowSelection selection) { final String soff = " offset " + selection.getFirstRow(); final String slim = " fetch first " + getMaxOrLimit( selection ) + " rows only"; final StringBuilder sb = new StringBuilder( sql.length() + soff.length() + slim.length() ) .append( sql ); if (LimitHelper.hasFirstRow( selection )) { sb.append( soff ); } if (LimitHelper.hasMaxRows( selection )) { sb.append( slim ); } return sb.toString(); }
@Override public String getProcessedSql() { boolean hasOffset = supportsLimit() && supportsLimitOffset() && LimitHelper.hasFirstRow( selection ) && LimitHelper.hasMaxRows( selection ); return OracleDistinctLimits.getOracleDistinctLimitString(sql, hasOffset); } };
@Override public String getProcessedSql() { boolean hasOffset = supportsLimit() && supportsLimitOffset() && LimitHelper.hasFirstRow( selection ) && LimitHelper.hasMaxRows( selection ); return OracleDistinctLimits.getOracleDistinctLimitString(sql, hasOffset); } };
@Override protected LimitHandler getLimitHandler(String sql, RowSelection selection) { Dialect dialect = this.getFactory().getDialect(); if (dialect instanceof DistinctLimitDialect && LimitHelper.hasMaxRows(selection)) { return ((DistinctLimitDialect)dialect).buildDistinctLimitHandler(sql, selection); } return super.getLimitHandler(sql, selection); }
@Override public String getProcessedSql() { boolean hasOffset = supportsLimit() && supportsLimitOffset() && LimitHelper.hasFirstRow( selection ) && LimitHelper.hasMaxRows( selection ); return OracleDistinctLimits.getOracleDistinctLimitString(sql, hasOffset); } };
/** * Default implementation of binding parameter values needed by the LIMIT clause. * * @param selection the selection criteria for rows. * @param statement Statement to which to bind limit parameter values. * @param index Index from which to start binding. * @return The number of parameter values bound. * @throws SQLException Indicates problems binding parameter values. */ protected final int bindLimitParameters(RowSelection selection, PreparedStatement statement, int index) throws SQLException { if ( !supportsVariableLimit() || !LimitHelper.hasMaxRows( selection ) ) { return 0; } final int firstRow = convertToFirstRowValue( LimitHelper.getFirstRow( selection ) ); final int lastRow = getMaxOrLimit( selection ); final boolean hasFirstRow = supportsLimitOffset() && ( firstRow > 0 || forceLimitUsage() ); final boolean reverse = bindLimitParametersInReverseOrder(); if ( hasFirstRow ) { statement.setInt( index + ( reverse ? 1 : 0 ), firstRow ); } statement.setInt( index + ( reverse || !hasFirstRow ? 0 : 1 ), lastRow ); return hasFirstRow ? 2 : 1; }
@Override public void setMaxRows(RowSelection selection, PreparedStatement statement) throws SQLException { if ( LimitHelper.hasMaxRows( selection ) ) { int maxRows = selection.getMaxRows() + convertToFirstRowValue( LimitHelper.getFirstRow( selection ) ); // Use Integer.MAX_VALUE on overflow if ( maxRows < 0 ) { statement.setMaxRows( Integer.MAX_VALUE ); } else { statement.setMaxRows( maxRows ); } } } }
@Override public String processSql(String sql, RowSelection selection) { final boolean useLimitOffset = supportsLimit() && supportsLimitOffset() && LimitHelper.hasFirstRow( selection ) && LimitHelper.hasMaxRows( selection ); return dialect.getLimitString( sql, useLimitOffset ? LimitHelper.getFirstRow( selection ) : 0, getMaxOrLimit( selection ) ); } }
private List doTheLoad(String sql, QueryParameters queryParameters, SessionImplementor session) throws SQLException { final RowSelection selection = queryParameters.getRowSelection(); final int maxRows = LimitHelper.hasMaxRows( selection ) ? selection.getMaxRows() : Integer.MAX_VALUE; final List<AfterLoadAction> afterLoadActions = new ArrayList<AfterLoadAction>(); final SqlStatementWrapper wrapper = executeQueryStatement( sql, queryParameters, false, afterLoadActions, session ); final ResultSet rs = wrapper.getResultSet(); final Statement st = wrapper.getStatement(); try { return processResultSet( rs, queryParameters, session, false, null, maxRows, afterLoadActions ); } finally { session.getJdbcCoordinator().getResourceRegistry().release( st ); session.getJdbcCoordinator().afterStatementExecution(); } } }