HHH-14642 finish ScrollableResultsImpl

This commit is contained in:
nathan.xu 2021-06-02 22:06:17 -04:00 committed by Christian Beikov
parent 2dc07c2ffe
commit f9534ead03
5 changed files with 104 additions and 54 deletions

View File

@ -7,7 +7,6 @@
package org.hibernate.internal; package org.hibernate.internal;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.sql.results.internal.RowProcessingStateStandardImpl; import org.hibernate.sql.results.internal.RowProcessingStateStandardImpl;
import org.hibernate.sql.results.jdbc.internal.JdbcValuesSourceProcessingStateStandardImpl; import org.hibernate.sql.results.jdbc.internal.JdbcValuesSourceProcessingStateStandardImpl;
@ -85,73 +84,26 @@ public class ScrollableResultsImpl<R> extends AbstractScrollableResults<R> {
final boolean hasResult = getRowProcessingState().last(); final boolean hasResult = getRowProcessingState().last();
prepareCurrentRow( hasResult ); prepareCurrentRow( hasResult );
return hasResult; return hasResult;
// todo (6.0) : need these scrollable ResultSet "re-positioning"-style methods on the JdbcValues stuff
// try {
// final boolean result = getResultSet().last();
// prepareCurrentRow( result );
// return result;
// }
// catch (SQLException sqle) {
// throw convert( sqle, "could not advance using last()" );
// }
} }
@Override @Override
public void afterLast() { public void afterLast() {
throw new NotYetImplementedFor6Exception(); getRowProcessingState().afterLast();
// todo (6.0) : need these scrollable ResultSet "re-positioning"-style methods on the JdbcValues stuff
// try {
// getResultSet().afterLast();
// }
// catch (SQLException sqle) {
// throw convert( sqle, "exception calling afterLast()" );
// }
} }
@Override @Override
public void beforeFirst() { public void beforeFirst() {
throw new NotYetImplementedFor6Exception(); getRowProcessingState().beforeFirst();
// todo (6.0) : need these scrollable ResultSet "re-positioning"-style methods on the JdbcValues stuff
// try {
// getResultSet().beforeFirst();
// }
// catch (SQLException sqle) {
// throw convert( sqle, "exception calling beforeFirst()" );
// }
} }
@Override @Override
public boolean isFirst() { public boolean isFirst() {
throw new NotYetImplementedFor6Exception(); return getRowProcessingState().isFirst();
// todo (6.0) : need these scrollable ResultSet "re-positioning"-style methods on the JdbcValues stuff
// try {
// return getResultSet().isFirst();
// }
// catch (SQLException sqle) {
// throw convert( sqle, "exception calling isFirst()" );
// }
} }
@Override @Override
public boolean isLast() { public boolean isLast() {
throw new NotYetImplementedFor6Exception(); return getRowProcessingState().isLast();
// todo (6.0) : need these scrollable ResultSet "re-positioning"-style methods on the JdbcValues stuff
// try {
// return getResultSet().isLast();
// }
// catch (SQLException sqle) {
// throw convert( sqle, "exception calling isLast()" );
// }
} }
@Override @Override

View File

@ -87,6 +87,18 @@ public class RowProcessingStateStandardImpl implements RowProcessingState {
return jdbcValues.getPosition(); return jdbcValues.getPosition();
} }
public boolean isBeforeFirst() {
return jdbcValues.isBeforeFirst( this );
}
public void beforeFirst() {
jdbcValues.beforeFirst( this );
}
public boolean isFirst() {
return jdbcValues.isFirst( this );
}
public boolean first() { public boolean first() {
return jdbcValues.first( this ); return jdbcValues.first( this );
} }
@ -95,6 +107,18 @@ public class RowProcessingStateStandardImpl implements RowProcessingState {
return jdbcValues.last( this ); return jdbcValues.last( this );
} }
public boolean isLast() {
return jdbcValues.isLast( this );
}
public void afterLast() {
jdbcValues.afterLast( this );
}
public boolean isAfterLast() {
return jdbcValues.isAfterLast( this );
}
@Override @Override
public Object getJdbcValue(int position) { public Object getJdbcValue(int position) {
return jdbcValues.getCurrentRowValuesArray()[ position ]; return jdbcValues.getCurrentRowValuesArray()[ position ];

View File

@ -151,6 +151,16 @@ public class JdbcValuesCacheHit extends AbstractJdbcValues {
return position < 0; return position < 0;
} }
@Override
public void beforeFirst(RowProcessingState rowProcessingState) {
position = -1;
}
@Override
public boolean isFirst(RowProcessingState rowProcessingState) {
return position == 0;
}
@Override @Override
public boolean first(RowProcessingState rowProcessingState) { public boolean first(RowProcessingState rowProcessingState) {
position = 0; position = 0;
@ -162,6 +172,21 @@ public class JdbcValuesCacheHit extends AbstractJdbcValues {
return position >= numberOfRows; return position >= numberOfRows;
} }
@Override
public void afterLast(RowProcessingState rowProcessingState) {
position = numberOfRows;
}
@Override
public boolean isLast(RowProcessingState rowProcessingState) {
if ( numberOfRows == 0 ) {
return position == 0;
}
else {
return position == numberOfRows - 1;
}
}
@Override @Override
public boolean last(RowProcessingState rowProcessingState) { public boolean last(RowProcessingState rowProcessingState) {
if ( numberOfRows == 0 ) { if ( numberOfRows == 0 ) {

View File

@ -7,6 +7,7 @@
package org.hibernate.sql.results.jdbc.internal; package org.hibernate.sql.results.jdbc.internal;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Arrays;
import org.hibernate.CacheMode; import org.hibernate.CacheMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
@ -165,7 +166,28 @@ public class JdbcValuesResultSetImpl extends AbstractJdbcValues {
return resultSetAccess.getResultSet().isBeforeFirst(); return resultSetAccess.getResultSet().isBeforeFirst();
} }
catch (SQLException e) { catch (SQLException e) {
throw makeExecutionException( "Error calling ResultSet#isBeforeFirst", e ); throw makeExecutionException( "Error calling ResultSet#isBeforeFirst()", e );
}
}
@Override
public void beforeFirst(RowProcessingState rowProcessingState) {
try {
resultSetAccess.getResultSet().beforeFirst();
Arrays.fill( currentRowJdbcValues, null );
}
catch (SQLException e) {
throw makeExecutionException( "Error calling ResultSet#beforeFirst()", e );
}
}
@Override
public boolean isFirst(RowProcessingState rowProcessingState) {
try {
return resultSetAccess.getResultSet().isFirst();
}
catch (SQLException e) {
throw makeExecutionException( "Error calling ResultSet#isFirst()", e );
} }
} }
@ -194,7 +216,28 @@ public class JdbcValuesResultSetImpl extends AbstractJdbcValues {
return resultSetAccess.getResultSet().isAfterLast(); return resultSetAccess.getResultSet().isAfterLast();
} }
catch (SQLException e) { catch (SQLException e) {
throw makeExecutionException( "Error calling ResultSet#isAfterLast", e ); throw makeExecutionException( "Error calling ResultSet#isAfterLast()", e );
}
}
@Override
public void afterLast(RowProcessingState rowProcessingState) {
try {
resultSetAccess.getResultSet().afterLast();
Arrays.fill( currentRowJdbcValues, null );
}
catch (SQLException e) {
throw makeExecutionException( "Error calling ResultSet#afterLast()", e );
}
}
@Override
public boolean isLast(RowProcessingState rowProcessingState) {
try {
return resultSetAccess.getResultSet().isLast();
}
catch (SQLException e) {
throw makeExecutionException( "Error calling ResultSet#isLast()", e );
} }
} }

View File

@ -54,9 +54,15 @@ public interface JdbcValues {
int getPosition(); int getPosition();
boolean isBeforeFirst(RowProcessingState rowProcessingState); boolean isBeforeFirst(RowProcessingState rowProcessingState);
void beforeFirst(RowProcessingState rowProcessingState);
boolean isFirst(RowProcessingState rowProcessingState);
boolean first(RowProcessingState rowProcessingState); boolean first(RowProcessingState rowProcessingState);
boolean isAfterLast(RowProcessingState rowProcessingState); boolean isAfterLast(RowProcessingState rowProcessingState);
void afterLast(RowProcessingState rowProcessingState);
boolean isLast(RowProcessingState rowProcessingState);
boolean last(RowProcessingState rowProcessingState); boolean last(RowProcessingState rowProcessingState);
/** /**