From: <one...@us...> - 2003-05-03 09:05:53
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader In directory sc8-pr-cvs1:/tmp/cvs-serv15675/loader Modified Files: Loader.java Log Message: code cleanups for paged queries + paged queries for HSQL Index: Loader.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/Loader.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Loader.java 3 May 2003 07:20:50 -0000 1.21 --- Loader.java 3 May 2003 09:05:45 -0000 1.22 *************** *** 361,380 **** */ protected final void advance(ResultSet rs, RowSelection selection, SessionImplementor session) throws SQLException { ! if (selection==null) { ! // we need the whole ResultSet from the beginning ! return; } else { ! Integer first = selection.getFirstRow(); ! if (first!=null && first.intValue()!=0 ) { ! if ( session.getFactory().useScrollableResultSets() ) { ! // we can go straight to the first required row ! rs.absolute( first.intValue() ); ! } ! else { ! // we need to step through the rows one row at a time (slow) ! for ( int m=0; m<first.intValue(); m++ ) rs.next(); ! } ! } } } --- 361,383 ---- */ protected final void advance(ResultSet rs, RowSelection selection, SessionImplementor session) throws SQLException { ! int firstRow = getFirstRow(selection); ! if ( firstRow!=0 ) { ! if ( session.getFactory().useScrollableResultSets() ) { ! // we can go straight to the first required row ! rs.absolute(firstRow); ! } ! else { ! // we need to step through the rows one row at a time (slow) ! for ( int m=0; m<firstRow; m++ ) rs.next(); ! } ! } ! } ! ! private int getFirstRow(RowSelection selection) { ! if ( selection==null || selection.getFirstRow()==null ) { ! return 0; } else { ! return selection.getFirstRow().intValue(); } } *************** *** 404,413 **** boolean scrollable = session.getFactory().useScrollableResultSets() && ( ! scroll || ( ! !usePagingSelect && ! selection!=null && ! selection.getFirstRow()!=null && ! selection.getFirstRow().intValue()!=0 ! ) ); --- 407,412 ---- boolean scrollable = session.getFactory().useScrollableResultSets() && ( ! scroll || ! ( !usePagingSelect && getFirstRow(selection)!=0 ) ); *************** *** 428,438 **** col += bindNamedParameters(st, namedParams, col, session); ! if (usePagingSelect) { ! int firstRow = (selection==null || selection.getFirstRow()==null ) ? 0 : selection.getFirstRow().intValue(); ! int lastRow = firstRow + selection.getMaxRows().intValue(); ! boolean reverse = session.getFactory().getDialect().reversePagingSelectOrder(); ! st.setInt( col + (reverse?1:0), firstRow ); ! st.setInt( col + (reverse?0:1), lastRow ); ! } } catch (SQLException sqle) { --- 427,431 ---- col += bindNamedParameters(st, namedParams, col, session); ! if (usePagingSelect) bindPagingSelectParameters(st, col, selection, session); } catch (SQLException sqle) { *************** *** 447,450 **** --- 440,452 ---- return st; + } + + private void bindPagingSelectParameters(PreparedStatement st, int index, RowSelection selection, SessionImplementor session) throws SQLException { + int firstRow = (selection==null || selection.getFirstRow()==null ) ? 0 : selection.getFirstRow().intValue(); + int lastRow = firstRow + selection.getMaxRows().intValue(); + boolean reverse = session.getFactory().getDialect().reversePagingSelectOrder(); + st.setInt( index + (reverse?1:0), firstRow ); + st.setInt( index + (reverse?0:1), lastRow ); + } |