From: <one...@us...> - 2003-05-03 07:20:54
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader In directory sc8-pr-cvs1:/tmp/cvs-serv15927/loader Modified Files: Loader.java Log Message: applied paged SQL SELECT patch by David White Index: Loader.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/Loader.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Loader.java 25 Apr 2003 05:56:33 -0000 1.20 --- Loader.java 3 May 2003 07:20:50 -0000 1.21 *************** *** 11,17 **** import java.util.Map; - import org.apache.commons.logging.Log; - import org.apache.commons.logging.LogFactory; - import net.sf.hibernate.HibernateException; import net.sf.hibernate.LockMode; --- 11,14 ---- *************** *** 23,31 **** import net.sf.hibernate.engine.RowSelection; import net.sf.hibernate.engine.SessionImplementor; - import net.sf.hibernate.util.JDBCExceptionReporter; - import net.sf.hibernate.util.StringHelper; import net.sf.hibernate.persister.Loadable; import net.sf.hibernate.sql.Alias; import net.sf.hibernate.type.Type; /** --- 20,30 ---- import net.sf.hibernate.engine.RowSelection; import net.sf.hibernate.engine.SessionImplementor; import net.sf.hibernate.persister.Loadable; import net.sf.hibernate.sql.Alias; import net.sf.hibernate.type.Type; + import net.sf.hibernate.util.JDBCExceptionReporter; + import net.sf.hibernate.util.StringHelper; + import org.apache.commons.logging.Log; + import org.apache.commons.logging.LogFactory; /** *************** *** 161,164 **** --- 160,164 ---- } + results.add( getResultColumnOrRow(row, rs, session) ); *************** *** 193,197 **** } ! protected Object getResultColumnOrRow(Object[] row, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { return row; } --- 193,198 ---- } ! protected Object getResultColumnOrRow(Object[] row, ResultSet rs, SessionImplementor session) ! throws SQLException, HibernateException { return row; } *************** *** 204,208 **** throws HibernateException, SQLException { - if (id==null) { //TODO: we can cache these on this object, from the constructor --- 205,208 ---- *************** *** 257,261 **** if ( !persisters[i].getMappedClass().isAssignableFrom( object.getClass() ) ) ! throw new WrongClassException( "loaded object was of wrong class", key.getIdentifier(), persisters[i].getMappedClass() ); } --- 257,261 ---- if ( !persisters[i].getMappedClass().isAssignableFrom( object.getClass() ) ) ! throw new WrongClassException( "loaded object was of wrong class", key.getIdentifier(), persisters[i].getMappedClass() ); } *************** *** 294,298 **** * Hydrate an object from the SQL <tt>ResultSet</tt> */ ! private void loadFromResultSet(ResultSet rs, Object object, Serializable id, String suffix, SessionImplementor session) throws SQLException, HibernateException { if ( log.isTraceEnabled() ) log.trace("Initializing object from ResultSet: " + id); --- 294,299 ---- * Hydrate an object from the SQL <tt>ResultSet</tt> */ ! private void loadFromResultSet(ResultSet rs, Object object, Serializable id, String suffix, SessionImplementor session) ! throws SQLException, HibernateException { if ( log.isTraceEnabled() ) log.trace("Initializing object from ResultSet: " + id); *************** *** 310,314 **** * Determine the concrete class of an instance in the <tt>ResultSet</tt> */ ! private Class getInstanceClass(ResultSet rs, Loadable persister, String suffix, Serializable id, SessionImplementor session) throws HibernateException, SQLException { Class topClass = persister.getMappedClass(); --- 311,316 ---- * Determine the concrete class of an instance in the <tt>ResultSet</tt> */ ! private Class getInstanceClass(ResultSet rs, Loadable persister, String suffix, Serializable id, SessionImplementor session) ! throws HibernateException, SQLException { Class topClass = persister.getMappedClass(); *************** *** 337,341 **** * Unmarshall the fields of a persistent instance from a result set */ ! private Object[] hydrate(ResultSet rs, Serializable id, Object object, Loadable persister, SessionImplementor session, String suffix) throws SQLException, HibernateException { if ( log.isTraceEnabled() ) log.trace("Hydrating entity: " + persister.getClassName() + '#' + id); --- 339,344 ---- * Unmarshall the fields of a persistent instance from a result set */ ! private Object[] hydrate(ResultSet rs, Serializable id, Object object, Loadable persister, SessionImplementor session, String suffix) ! throws SQLException, HibernateException { if ( log.isTraceEnabled() ) log.trace("Hydrating entity: " + persister.getClassName() + '#' + id); *************** *** 377,380 **** --- 380,391 ---- } + private boolean usePagingSelect(RowSelection selection, SessionImplementor session) { + return session.getFactory().getDialect().supportsPagingSelect() && ( + selection!=null && + selection.getMaxRows()!=null + ); + } + + /** * Obtain a <tt>PreparedStatement</tt> and bind JDBC-style <tt>?</tt> and named parameters *************** *** 382,397 **** protected final PreparedStatement prepareQueryStatement( String sql, ! Object[] ! values, Type[] types, Map namedParams, RowSelection selection, ! boolean scroll, SessionImplementor session ) throws SQLException, HibernateException { ! boolean scrollable = selection!=null && ! ( ( selection.getFirstRow()!=null && selection.getFirstRow().intValue()!=0 ) || scroll ) && ! session.getFactory().useScrollableResultSets(); PreparedStatement st = session.getBatcher().prepareQueryStatement(sql, scrollable); --- 393,416 ---- protected final PreparedStatement prepareQueryStatement( String sql, ! Object[] values, Type[] types, Map namedParams, RowSelection selection, ! boolean scroll, SessionImplementor session ) throws SQLException, HibernateException { + + boolean usePagingSelect = usePagingSelect(selection, session); ! boolean scrollable = session.getFactory().useScrollableResultSets() && ( ! scroll || ( ! !usePagingSelect && ! selection!=null && ! selection.getFirstRow()!=null && ! selection.getFirstRow().intValue()!=0 ! ) ! ); ! ! if (usePagingSelect) sql = session.getFactory().getDialect().getPagingSelect(sql); PreparedStatement st = session.getBatcher().prepareQueryStatement(sql, scrollable); *************** *** 407,412 **** } ! if (namedParams!=null) bindNamedParameters(st, namedParams, col, session); ! } catch (SQLException sqle) { --- 426,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) { *************** *** 436,444 **** * advance to the first result and return an SQL <tt>ResultSet</tt> */ ! private final ResultSet getResultSet(PreparedStatement st, RowSelection selection, SessionImplementor session) throws SQLException, HibernateException { try { ! setMaxRows(st, selection); ResultSet rs = st.executeQuery(); ! advance(rs, selection, session); return rs; } --- 462,474 ---- * advance to the first result and return an SQL <tt>ResultSet</tt> */ ! protected final ResultSet getResultSet(PreparedStatement st, RowSelection selection, SessionImplementor session) ! throws SQLException, HibernateException { ! ! boolean usePagingSelect = usePagingSelect(selection, session); ! try { ! if (!usePagingSelect) setMaxRows(st, selection); ResultSet rs = st.executeQuery(); ! if (!usePagingSelect) advance(rs, selection, session); return rs; } *************** *** 450,454 **** } ! protected final void closePreparedStatement(PreparedStatement st, RowSelection selection, SessionImplementor session) throws SQLException, HibernateException { try { if (selection!=null) { --- 480,485 ---- } ! protected final void closePreparedStatement(PreparedStatement st, RowSelection selection, SessionImplementor session) ! throws SQLException, HibernateException { try { if (selection!=null) { *************** *** 466,470 **** * superclass and should be implemented by subclasses (queries) which allow named parameters. */ ! protected void bindNamedParameters(PreparedStatement st, Map namedParams, int start, SessionImplementor session) throws SQLException, HibernateException {} /** --- 497,502 ---- * superclass and should be implemented by subclasses (queries) which allow named parameters. */ ! protected int bindNamedParameters(PreparedStatement st, Map namedParams, int start, SessionImplementor session) ! throws SQLException, HibernateException { return 0; } /** |