[hibernate-commits] Hibernate SVN: r19223 - core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Apr 13 12:02:13 EDT 2010


Author: stliu
Date: 2010-04-13 12:02:13 -0400 (Tue, 13 Apr 2010)
New Revision: 19223

Modified:
   core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/FetchingScrollableResultsImpl.java
Log:
JBPAPP-4095 HHH-5096 FetchingScrollableResultsImpl.last() does not move to the last result if cursor is after the last result

Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/FetchingScrollableResultsImpl.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/FetchingScrollableResultsImpl.java	2010-04-13 16:01:56 UTC (rev 19222)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/FetchingScrollableResultsImpl.java	2010-04-13 16:02:13 UTC (rev 19223)
@@ -24,6 +24,7 @@
  */
 package org.hibernate.impl;
 
+import org.apache.tools.ant.taskdefs.condition.IsReference;
 import org.hibernate.HibernateException;
 import org.hibernate.MappingException;
 import org.hibernate.exception.JDBCExceptionHelper;
@@ -74,7 +75,11 @@
 			currentPosition = maxPosition.intValue() + 1;
 			return false;
 		}
-
+		if ( isResultSetEmpty() ) {
+			currentRow = null;
+			currentPosition = 0;
+			return false;
+		}
 		Object row = getLoader().loadSequentialRowsForward(
 				getResultSet(),
 				getSession(),
@@ -183,13 +188,16 @@
 	public boolean last() throws HibernateException {
 		boolean more = false;
 		if ( maxPosition != null ) {
+			if ( currentPosition > maxPosition.intValue() ) {
+				more = previous();
+			}
 			for ( int i = currentPosition; i < maxPosition.intValue(); i++ ) {
 				more = next();
 			}
 		}
 		else {
 			try {
-				if ( getResultSet().isAfterLast() ) {
+				if ( isResultSetEmpty() || getResultSet().isAfterLast() ) {
 					// should not be able to reach last without maxPosition being set
 					// unless there are no results
 					return false;
@@ -313,4 +321,15 @@
 		}
 		return scroll( rowNumber - currentPosition );
 	}
+	
+	private boolean isResultSetEmpty() {
+		try {
+			return currentPosition == 0 && !getResultSet().isBeforeFirst()
+					&& !getResultSet().isAfterLast();
+		} catch ( SQLException e ) {
+			throw JDBCExceptionHelper
+					.convert( getSession().getFactory().getSQLExceptionConverter(), e,
+							"Could not determine if resultset is empty due to exception calling isBeforeFirst or isAfterLast()" );
+		}
+	}
 }



More information about the hibernate-commits mailing list