Skip to content

Commit

Permalink
cleanups in implementations of ScrollableResults
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Jan 17, 2025
1 parent a9ea918 commit d2c78f3
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public AbstractScrollableResults(
this.persistenceContext = persistenceContext;
}


@Override
public final R get() throws HibernateException {
if ( closed ) {
Expand Down Expand Up @@ -85,26 +84,22 @@ protected void afterScrollOperation() {

@Override
public void setFetchSize(int fetchSize) {
getJdbcValues().setFetchSize(fetchSize);
getJdbcValues().setFetchSize( fetchSize );
}

@Override
public final void close() {
if ( this.closed ) {
// noop if already closed
return;
if ( !closed ) {
rowReader.finishUp( rowProcessingState );
jdbcValues.finishUp( persistenceContext );
getPersistenceContext().getJdbcCoordinator().afterStatementExecution();
closed = true;
}

rowReader.finishUp( rowProcessingState );
jdbcValues.finishUp( persistenceContext );

getPersistenceContext().getJdbcCoordinator().afterStatementExecution();

this.closed = true;
// noop if already closed
}

@Override
public boolean isClosed() {
return this.closed;
return closed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@
*/
package org.hibernate.internal;

import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.query.spi.ScrollableResultsImplementor;

/**
* @author Andrea Boriero
*/
public class EmptyScrollableResults implements ScrollableResultsImplementor {
public class EmptyScrollableResults<R> implements ScrollableResultsImplementor<R> {

public static final ScrollableResultsImplementor INSTANCE = new EmptyScrollableResults();
@SuppressWarnings("rawtypes")
private static final ScrollableResultsImplementor INSTANCE = new EmptyScrollableResults();

@SuppressWarnings("unchecked")
public static <R> EmptyScrollableResults<R> instance() {
return (EmptyScrollableResults<R>) INSTANCE;
}

@Override
public boolean isClosed() {
return true;
}

// @Override
// public int getNumberOfTypes() {
// return 0;
// }

@Override
public void close() {

}

@Override
Expand Down Expand Up @@ -61,12 +60,10 @@ public boolean first() {

@Override
public void beforeFirst() {

}

@Override
public void afterLast() {

}

@Override
Expand All @@ -93,112 +90,7 @@ public boolean setRowNumber(int rowNumber) {
public void setFetchSize(int fetchSize) {}

@Override
public Object[] get() {
return ArrayHelper.EMPTY_OBJECT_ARRAY;
}

// @Override
// public Object get(int i) {
// return null;
// }
//
// @Override
// public Type getType(int i) {
// return null;
// }
//
// @Override
// public Integer getInteger(int col) {
// return null;
// }
//
// @Override
// public Long getLong(int col) {
// return null;
// }
//
// @Override
// public Float getFloat(int col) {
// return null;
// }
//
// @Override
// public Boolean getBoolean(int col) {
// return null;
// }
//
// @Override
// public Double getDouble(int col) {
// return null;
// }
//
// @Override
// public Short getShort(int col) {
// return null;
// }
//
// @Override
// public Byte getByte(int col) {
// return null;
// }
//
// @Override
// public Character getCharacter(int col) {
// return null;
// }
//
// @Override
// public byte[] getBinary(int col) {
// return new byte[0];
// }
//
// @Override
// public String getText(int col) {
// return null;
// }
//
// @Override
// public Blob getBlob(int col) {
// return null;
// }
//
// @Override
// public Clob getClob(int col) {
// return null;
// }
//
// @Override
// public String getString(int col) {
// return null;
// }
//
// @Override
// public BigDecimal getBigDecimal(int col) {
// return null;
// }
//
// @Override
// public BigInteger getBigInteger(int col) {
// return null;
// }
//
// @Override
// public Date getDate(int col) {
// return null;
// }
//
// @Override
// public Locale getLocale(int col) {
// return null;
// }
//
// @Override
// public Calendar getCalendar(int col) {
// return null;
// }
//
// @Override
// public TimeZone getTimeZone(int col) {
// return null;
// }
public R get() {
throw new UnsupportedOperationException( "Empty result set" );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ else if ( beforeFirst ) {
}
}

boolean last = prepareCurrentRow();
final boolean last = prepareCurrentRow();

beforeFirst = false;
currentPosition++;
Expand Down Expand Up @@ -130,15 +130,12 @@ else if ( currentPosition == 1 ) {
// we are interested in processing
boolean firstPass = true;
final EntityKey lastKey = getEntityKey();

while ( getRowProcessingState().previous() ) {
EntityKey checkKey = getEntityKey();

final EntityKey checkKey = getEntityKey();
if ( firstPass ) {
firstPass = false;
keyToRead = checkKey;
}

if ( !lastKey.equals( checkKey ) ) {
break;
}
Expand All @@ -148,8 +145,7 @@ else if ( currentPosition == 1 ) {
// Read backwards until we read past the first physical sequential
// row with the key we are interested in loading
while ( getRowProcessingState().previous() ) {
EntityKey checkKey = getEntityKey();

final EntityKey checkKey = getEntityKey();
if ( !keyToRead.equals( checkKey ) ) {
break;
}
Expand Down Expand Up @@ -223,7 +219,6 @@ public boolean last() {
}
}
else {
final RowProcessingStateStandardImpl rowProcessingState = getRowProcessingState();
if ( isResultSetEmpty() || afterLast ) {
// should not be able to reach last without maxPosition being set
// unless there are no results
Expand All @@ -243,10 +238,8 @@ public boolean last() {
@Override
public boolean first() {
beforeFirst();
boolean more = next();

final boolean more = next();
afterScrollOperation();

return more;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,32 +117,30 @@ public boolean setRowNumber(int rowNumber) throws HibernateException {
}

private void prepareCurrentRow(boolean underlyingScrollSuccessful) {
if ( !underlyingScrollSuccessful ) {
currentRow = null;
return;
}

final PersistenceContext persistenceContext = getPersistenceContext().getPersistenceContext();
final LoadContexts loadContexts = persistenceContext.getLoadContexts();
loadContexts.register( getJdbcValuesSourceProcessingState() );
persistenceContext.beforeLoad();
try {
if ( underlyingScrollSuccessful ) {
final PersistenceContext persistenceContext = getPersistenceContext().getPersistenceContext();
final LoadContexts loadContexts = persistenceContext.getLoadContexts();
loadContexts.register( getJdbcValuesSourceProcessingState() );
persistenceContext.beforeLoad();
try {
currentRow = getRowReader().readRow( getRowProcessingState() );

getRowProcessingState().finishRowProcessing( true );
getJdbcValuesSourceProcessingState().finishUp( false );
try {
currentRow = getRowReader().readRow( getRowProcessingState() );
getRowProcessingState().finishRowProcessing( true );
getJdbcValuesSourceProcessingState().finishUp( false );
}
finally {
persistenceContext.afterLoad();
}
persistenceContext.initializeNonLazyCollections();
}
finally {
persistenceContext.afterLoad();
loadContexts.deregister( getJdbcValuesSourceProcessingState() );
}
persistenceContext.initializeNonLazyCollections();
afterScrollOperation();
}
finally {
loadContexts.deregister( getJdbcValuesSourceProcessingState() );
else {
currentRow = null;
}

afterScrollOperation();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ public List<R> performList(DomainQueryExecutionContext executionContext) {
@Override
public ScrollableResultsImplementor<R> performScroll(ScrollMode scrollMode, DomainQueryExecutionContext executionContext) {
if ( executionContext.getQueryOptions().getEffectiveLimit().getMaxRowsJpa() == 0 ) {
//noinspection unchecked
return EmptyScrollableResults.INSTANCE;
return EmptyScrollableResults.instance();
}
final List<JdbcParameterBinder> jdbcParameterBinders;
final JdbcParameterBindings jdbcParameterBindings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ else if ( elementsToSkip > 0 ) {
@Override
public ScrollableResultsImplementor<R> performScroll(ScrollMode scrollMode, DomainQueryExecutionContext executionContext) {
if ( executionContext.getQueryOptions().getEffectiveLimit().getMaxRowsJpa() == 0 ) {
return EmptyScrollableResults.INSTANCE;
return EmptyScrollableResults.instance();
}
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public List<R> performList(DomainQueryExecutionContext executionContext) {
@Override
public ScrollableResultsImplementor<R> performScroll(ScrollMode scrollMode, DomainQueryExecutionContext executionContext) {
if ( executionContext.getQueryOptions().getEffectiveLimit().getMaxRowsJpa() == 0 ) {
return EmptyScrollableResults.INSTANCE;
return EmptyScrollableResults.instance();
}
return withCacheableSqmInterpretation( executionContext, scrollMode, scrollInterpreter );
}
Expand Down

0 comments on commit d2c78f3

Please sign in to comment.