HHH-15352 add ScrollableResults.setFetchSize()

This commit is contained in:
Gavin King 2022-06-20 11:27:34 +02:00
parent f1ca6d9e5e
commit 6404704311
7 changed files with 37 additions and 1 deletions

View File

@ -135,4 +135,16 @@ public interface ScrollableResults<R> extends AutoCloseable, Closeable {
* @return true if there is a row at that row number * @return true if there is a row at that row number
*/ */
boolean setRowNumber(int rowNumber); boolean setRowNumber(int rowNumber);
/**
* Gives the JDBC driver a hint as to the number of rows that
* should be fetched from the database when more rows are needed.
* If {@code 0}, the JDBC driver's default setting will be used.
*
* @see java.sql.ResultSet#setFetchSize(int)
* @see org.hibernate.cfg.AvailableSettings#STATEMENT_FETCH_SIZE
*
* @since 6.1.1
*/
void setFetchSize(int fetchSize);
} }

View File

@ -945,8 +945,9 @@ public interface AvailableSettings {
* from the database when more rows are needed. If {@code 0}, the JDBC driver's * from the database when more rows are needed. If {@code 0}, the JDBC driver's
* default settings will be used. * default settings will be used.
* *
* @see java.sql.ResultSet#setFetchSize(int) * @see java.sql.PreparedStatement#setFetchSize(int)
* @see org.hibernate.boot.SessionFactoryBuilder#applyJdbcFetchSize(int) * @see org.hibernate.boot.SessionFactoryBuilder#applyJdbcFetchSize(int)
* @see org.hibernate.ScrollableResults#setFetchSize(int)
*/ */
String STATEMENT_FETCH_SIZE = "hibernate.jdbc.fetch_size"; String STATEMENT_FETCH_SIZE = "hibernate.jdbc.fetch_size";

View File

@ -85,6 +85,11 @@ public abstract class AbstractScrollableResults<R> implements ScrollableResultsI
getPersistenceContext().afterScrollOperation(); getPersistenceContext().afterScrollOperation();
} }
@Override
public void setFetchSize(int fetchSize) {
getJdbcValues().setFetchSize(fetchSize);
}
@Override @Override
public final void close() { public final void close() {
if ( this.closed ) { if ( this.closed ) {

View File

@ -91,6 +91,9 @@ public class EmptyScrollableResults implements ScrollableResultsImplementor {
return false; return false;
} }
@Override
public void setFetchSize(int fetchSize) {}
@Override @Override
public Object[] get() { public Object[] get() {
return ArrayHelper.EMPTY_OBJECT_ARRAY; return ArrayHelper.EMPTY_OBJECT_ARRAY;

View File

@ -227,4 +227,7 @@ public class JdbcValuesCacheHit extends AbstractJdbcValues {
protected void release() { protected void release() {
cachedData = null; cachedData = null;
} }
@Override
public void setFetchSize(int fetchSize) {}
} }

View File

@ -324,4 +324,14 @@ public class JdbcValuesResultSetImpl extends AbstractJdbcValues {
public Object[] getCurrentRowValuesArray() { public Object[] getCurrentRowValuesArray() {
return currentRowJdbcValues; return currentRowJdbcValues;
} }
@Override
public void setFetchSize(int fetchSize) {
try {
resultSetAccess.getResultSet().setFetchSize(fetchSize);
}
catch (SQLException e) {
throw makeExecutionException( "Error calling ResultSet.setFetchSize()", e );
}
}
} }

View File

@ -78,4 +78,6 @@ public interface JdbcValues {
* Give implementations a chance to finish processing * Give implementations a chance to finish processing
*/ */
void finishUp(SharedSessionContractImplementor session); void finishUp(SharedSessionContractImplementor session);
void setFetchSize(int fetchSize);
} }