From: <one...@us...> - 2003-01-18 09:03:57
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader In directory sc8-pr-cvs1:/tmp/cvs-serv29740/sf/hibernate/loader Modified Files: EntityLoader.java Loader.java OuterJoinLoader.java SimpleEntityLoader.java Log Message: implemented outerjoin fetching for single-column queries Index: EntityLoader.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/EntityLoader.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** EntityLoader.java 15 Jan 2003 12:49:01 -0000 1.5 --- EntityLoader.java 18 Jan 2003 09:03:54 -0000 1.6 *************** *** 8,12 **** import net.sf.hibernate.HibernateException; import net.sf.hibernate.MappingException; - import net.sf.hibernate.collection.CollectionPersister; import net.sf.hibernate.engine.SessionFactoryImplementor; import net.sf.hibernate.engine.SessionImplementor; --- 8,11 ---- *************** *** 58,70 **** } - protected CollectionPersister getCollectionPersister() { - return null; - } - public Object load(SessionImplementor session, Serializable id, Object object) throws HibernateException, SQLException { List list = loadEntity(session, new Object[] { id }, idType, object, id, false); if ( list.size()==1 ) { final int len = classPersisters.length; ! return ( len==1 ) ? list.get(0) : ( (Object[]) list.get(0) )[len-1]; } else if ( list.size()==0 ) { --- 57,65 ---- } public Object load(SessionImplementor session, Serializable id, Object object) throws HibernateException, SQLException { List list = loadEntity(session, new Object[] { id }, idType, object, id, false); if ( list.size()==1 ) { final int len = classPersisters.length; ! return ( (Object[]) list.get(0) )[len-1]; } else if ( list.size()==0 ) { Index: Loader.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/Loader.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Loader.java 15 Jan 2003 12:49:01 -0000 1.5 --- Loader.java 18 Jan 2003 09:03:54 -0000 1.6 *************** *** 71,92 **** return true; } - /** - * The return types of a find() query - */ - protected Type[] getReturnTypes() { - return null; - } - /** - * The column names holding returned scalar values - */ - public String[][] getScalarColumnNames() { - return null; - } - /** - * A hack to allow scalar values in a find() query - */ - protected boolean hasScalarValues() { - return false; - } /** --- 71,74 ---- *************** *** 134,145 **** } - String[][] names = null; - Type[] returnTypes = null; - final boolean scalars = hasScalarValues(); - if (scalars) { - returnTypes = getReturnTypes(); - names = getScalarColumnNames(); - } - final List results = new ArrayList(); //new net.sf.hibernate.collections.List(this); --- 116,119 ---- *************** *** 182,201 **** } ! if (!scalars) { ! //hacky!! ! results.add( ( cols==1 ) ? row[0] : row ); ! } ! else { ! int queryCols = returnTypes.length; ! if ( queryCols==1 ) { ! results.add( returnTypes[0].nullSafeGet( rs, names[0], session, null ) ); ! } ! else { ! Object[] queryRow = new Object[queryCols]; ! for ( int i=0; i<queryCols; i++ ) ! queryRow[i] = returnTypes[i].nullSafeGet( rs, names[i], session, null ); ! results.add(queryRow); ! } ! } if (collection) optionalCollection.readFrom( rs, getCollectionPersister(), optionalCollectionOwner ); --- 156,161 ---- } ! ! results.add( getResultColumnOrRow(row, rs, session) ); if (collection) optionalCollection.readFrom( rs, getCollectionPersister(), optionalCollectionOwner ); *************** *** 225,228 **** --- 185,192 ---- } + protected Object getResultColumnOrRow(Object[] row, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { + return row; + } + /** * Read a row of <tt>Key</tt>s from the <tt>ResultSet</tt> into the given array. Warning: this *************** *** 510,514 **** * Called by subclasses that implement queries */ ! public final List find( final SessionImplementor session, final Object[] values, --- 474,478 ---- * Called by subclasses that implement queries */ ! protected List find( final SessionImplementor session, final Object[] values, Index: OuterJoinLoader.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/OuterJoinLoader.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** OuterJoinLoader.java 15 Jan 2003 12:49:01 -0000 1.6 --- OuterJoinLoader.java 18 Jan 2003 09:03:54 -0000 1.7 *************** *** 26,30 **** * join. */ ! public abstract class OuterJoinLoader extends Loader { public static final int EAGER = 1; --- 26,30 ---- * join. */ ! public /*abstract*/ class OuterJoinLoader extends Loader { public static final int EAGER = 1; *************** *** 39,46 **** protected String sql; protected String[] suffixes; ! protected final OuterJoinGenerator outerJoinGenerator; ! public OuterJoinLoader(Dialect dialect) ! { outerJoinGenerator = dialect.getOuterJoinGenerator(); } --- 39,45 ---- protected String sql; protected String[] suffixes; ! protected final OuterJoinGenerator outerJoinGenerator; ! public OuterJoinLoader(Dialect dialect) { outerJoinGenerator = dialect.getOuterJoinGenerator(); } *************** *** 48,54 **** public static final class OuterJoinableAssociation { //Object persister; // a class or collection persister! ! Loadable subpersister; ! String[] foreignKeyColumns; // belong to persister ! String subalias; } --- 47,53 ---- public static final class OuterJoinableAssociation { //Object persister; // a class or collection persister! ! public Loadable subpersister; ! public String[] foreignKeyColumns; // belong to persister ! public String subalias; } *************** *** 56,60 **** * For an entity class, return a list of associations to be fetched by outerjoin */ ! protected final List walkTree(Loadable persister, String alias, SessionFactoryImplementor session) throws MappingException { List associations = new ArrayList(); walkTree(persister, alias, associations, new HashSet(), session); --- 55,59 ---- * For an entity class, return a list of associations to be fetched by outerjoin */ ! public final List walkTree(Loadable persister, String alias, SessionFactoryImplementor session) throws MappingException { List associations = new ArrayList(); walkTree(persister, alias, associations, new HashSet(), session); *************** *** 72,85 **** Type type = persister.getElementType(); - String[] columns = StringHelper.prefix( persister.getElementColumnNames(), alias + '.' ); if ( type.isEntityType() ) { EntityType etype = (EntityType) type; if ( autoEager( persister.enableJoinedFetch(), etype, session ) ) { // fetch many-to-many by outerjoin depending value of outer-join in mapping walkTree(etype, columns, persister, associations, new HashSet(), session); } } else if ( type.isComponentType() ) { ! walkTree( (AbstractComponentType) type, columns, persister, alias, associations, new HashSet(), session); } --- 71,84 ---- Type type = persister.getElementType(); if ( type.isEntityType() ) { EntityType etype = (EntityType) type; if ( autoEager( persister.enableJoinedFetch(), etype, session ) ) { // fetch many-to-many by outerjoin depending value of outer-join in mapping + String[] columns = StringHelper.prefix( persister.getElementColumnNames(), alias + '.' ); walkTree(etype, columns, persister, associations, new HashSet(), session); } } else if ( type.isComponentType() ) { ! walkTree( (AbstractComponentType) type, persister.getElementColumnNames(), persister, alias, associations, new HashSet(), session); } *************** *** 142,147 **** if ( types[i].isEntityType() ) { EntityType etype = (EntityType) types[i]; ! if ( autoEager( act.enableJoinedFetch(i), etype, session ) ) ! walkTree(etype, range, persister, associations, classPersisters, session); } else if ( types[i].isComponentType() ) { --- 141,148 ---- if ( types[i].isEntityType() ) { EntityType etype = (EntityType) types[i]; ! if ( autoEager( act.enableJoinedFetch(i), etype, session ) ) { ! String[] columns = StringHelper.prefix( range, alias + '.' ); ! walkTree(etype, columns, persister, associations, classPersisters, session); ! } } else if ( types[i].isComponentType() ) { *************** *** 195,199 **** * Generate a select list of columns containing all properties of the entity classes */ ! protected final String selectString(List associations) { StringBuffer buf = new StringBuffer(100); for ( int i=0; i<associations.size(); i++ ) { --- 196,200 ---- * Generate a select list of columns containing all properties of the entity classes */ ! public final String selectString(List associations) { StringBuffer buf = new StringBuffer(100); for ( int i=0; i<associations.size(); i++ ) { *************** *** 286,289 **** --- 287,305 ---- } + protected CollectionPersister getCollectionPersister() { + return null; + } + + public String outerJoinsAfterFrom(List associations) { + return outerJoinGenerator.outerJoinStringAfterFrom(associations); + } + + public String outerJoinsAfterWhere(List associations) { + return outerJoinGenerator.outerJoinStringAfterWhere(associations); + } + + public void setSuffixed(String[] suffixes) { + this.suffixes = suffixes; + } } Index: SimpleEntityLoader.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/SimpleEntityLoader.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SimpleEntityLoader.java 15 Jan 2003 12:49:01 -0000 1.5 --- SimpleEntityLoader.java 18 Jan 2003 09:03:54 -0000 1.6 *************** *** 54,58 **** List list = loadEntity(session, new Object[] { id }, idType, object, id, false); if ( list.size()==1 ) { ! return list.get(0); } else if ( list.size()==0 ) { --- 54,58 ---- List list = loadEntity(session, new Object[] { id }, idType, object, id, false); if ( list.size()==1 ) { ! return ( (Object[]) list.get(0) )[0]; } else if ( list.size()==0 ) { |