HHH-12369 Fix for integer overflow in limit handler when using Integer.MAX_VALUE for maxResults on DB2
This commit is contained in:
parent
656c43cfed
commit
18a2b16889
|
@ -169,6 +169,13 @@ public abstract class AbstractLimitHandler implements LimitHandler {
|
|||
protected final int getMaxOrLimit(RowSelection selection) {
|
||||
final int firstRow = convertToFirstRowValue( LimitHelper.getFirstRow( selection ) );
|
||||
final int lastRow = selection.getMaxRows();
|
||||
return useMaxForLimit() ? lastRow + firstRow : lastRow;
|
||||
final int maxRows = useMaxForLimit() ? lastRow + firstRow : lastRow;
|
||||
// Use Integer.MAX_VALUE on overflow
|
||||
if ( maxRows < 0 ) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
else {
|
||||
return maxRows;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,14 @@ public class NoopLimitHandler extends AbstractLimitHandler {
|
|||
@Override
|
||||
public void setMaxRows(RowSelection selection, PreparedStatement statement) throws SQLException {
|
||||
if ( LimitHelper.hasMaxRows( selection ) ) {
|
||||
statement.setMaxRows( selection.getMaxRows() + convertToFirstRowValue( LimitHelper.getFirstRow( 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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue