Merge branch 'master' of github.com:hibernate/hibernate-core

This commit is contained in:
Steve Ebersole 2011-04-06 14:00:14 -05:00
commit 0d04cc15c6
2 changed files with 39 additions and 11 deletions

View File

@ -1685,6 +1685,18 @@ public abstract class Loader {
return dialect.supportsLimit() && hasMaxRows( selection );
}
private ScrollMode getScrollMode(boolean scroll, boolean hasFirstRow, boolean useLimitOffSet, QueryParameters queryParameters) {
final boolean canScroll = getFactory().getSettings().isScrollableResultSetsEnabled();
if ( canScroll ) {
if ( scroll ) {
return queryParameters.getScrollMode();
}
if ( hasFirstRow && !useLimitOffSet ) {
return ScrollMode.SCROLL_INSENSITIVE;
}
}
return null;
}
/**
* Obtain a <tt>PreparedStatement</tt> with all parameters pre-bound.
* Bind JDBC-style <tt>?</tt> parameters, named parameters, and
@ -1701,24 +1713,23 @@ public abstract class Loader {
final RowSelection selection = queryParameters.getRowSelection();
boolean useLimit = useLimit( selection, dialect );
boolean hasFirstRow = getFirstRow( selection ) > 0;
boolean useOffset = hasFirstRow && useLimit && dialect.supportsLimitOffset();
boolean useLimitOffset = hasFirstRow && useLimit && dialect.supportsLimitOffset();
boolean callable = queryParameters.isCallable();
final boolean canScroll = getFactory().getSettings().isScrollableResultSetsEnabled();
final boolean useScrollableResultSetToSkip = hasFirstRow &&
!useOffset &&
getFactory().getSettings().isScrollableResultSetsEnabled();
final ScrollMode scrollMode =
canScroll
? scroll || useScrollableResultSetToSkip
? queryParameters.getScrollMode()
: ScrollMode.SCROLL_INSENSITIVE
: null;
!useLimitOffset && canScroll;
final ScrollMode scrollMode = getScrollMode( scroll, hasFirstRow, useLimit, queryParameters );
//
// if(canScroll && ( scroll || useScrollableResultSetToSkip )){
// scrollMode = scroll ? queryParameters.getScrollMode() : ScrollMode.SCROLL_INSENSITIVE;
// }else{
// scrollMode = null;
// }
if ( useLimit ) {
sql = dialect.getLimitString(
sql.trim(), //use of trim() here is ugly?
useOffset ? getFirstRow(selection) : 0,
useLimitOffset ? getFirstRow(selection) : 0,
getMaxOrLimit(selection, dialect)
);
}

View File

@ -91,6 +91,23 @@ public class PaginationTest extends BaseCoreFunctionalTestCase {
cleanupTestData();
}
@Test
public void testOffset(){
prepareTestData();
Session session = openSession();
session.beginTransaction();
List result;
result = generateBaseHQLQuery( session )
.setFirstResult( 3 )
.list();
result = generateBaseCriteria( session )
.setFirstResult( 3 )
.list();
session.getTransaction().commit();
session.close();
cleanupTestData();
}
@Test
@RequiresDialectFeature(