From: <one...@us...> - 2002-11-07 11:33:52
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/loader In directory usw-pr-cvs1:/tmp/cvs-serv1018/hibernate/loader Modified Files: Loader.java Log Message: improved handling of <key-many-to-many> in load process Index: Loader.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/loader/Loader.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Loader.java 7 Nov 2002 10:10:59 -0000 1.25 --- Loader.java 7 Nov 2002 11:33:48 -0000 1.26 *************** *** 123,131 **** for ( int i=0; i<cols; i++ ) { ! keys[i] = getKeyFromResultSet( persisters[i], suffixes[i], rs, session ); } // this call is side-effecty ! Object[] row = getRow(rs, persisters, suffixes, keys, hydrate, optionalObject, optionalObjectKey, optionalID, session); for ( int i=0; i<cols; i++ ) { --- 123,131 ---- for ( int i=0; i<cols; i++ ) { ! keys[i] = getKeyFromResultSet( persisters[i], suffixes[i], (i==cols-1) ? optionalID : null, rs, session ); } // this call is side-effecty ! Object[] row = getRow(rs, persisters, suffixes, keys, hydrate, optionalObject, optionalObjectKey, session); for ( int i=0; i<cols; i++ ) { *************** *** 179,192 **** /** * Read a row of <tt>Key</tt>s from the <tt>ResultSet</tt> into the given array. Warning: this ! * method is side-effecty. */ ! private Key getKeyFromResultSet(Loadable persister, String suffix, ResultSet rs, SessionImplementor session) throws HibernateException, SQLException { ! //TODO: we can cache these on this object, from the constructor ! String[] keyColNames = StringHelper.suffix( persister.getIdentifierColumnNames(), suffix ); ! StringHelper.unQuoteInPlace(keyColNames); ! Serializable id = (Serializable) persister.getIdentifierType().nullSafeGet(rs, keyColNames, session, null); return ( id==null ) ? null : new Key( id, persister ); } --- 179,196 ---- /** * Read a row of <tt>Key</tt>s from the <tt>ResultSet</tt> into the given array. Warning: this ! * method is side-effecty. If an <tt>id</tt> is given, don't bother going to the <tt>ResultSet</tt>. */ ! private Key getKeyFromResultSet(Loadable persister, String suffix, Serializable id, ResultSet rs, SessionImplementor session) throws HibernateException, SQLException { ! ! if (id==null) { ! //TODO: we can cache these on this object, from the constructor ! String[] keyColNames = StringHelper.suffix( persister.getIdentifierColumnNames(), suffix ); ! StringHelper.unQuoteInPlace(keyColNames); ! id = (Serializable) persister.getIdentifierType().nullSafeGet(rs, keyColNames, session, null); ! } ! return ( id==null ) ? null : new Key( id, persister ); } *************** *** 206,210 **** Object optionalObject, Key optionalObjectKey, - Serializable optionalID, SessionImplementor session ) throws HibernateException, SQLException { --- 210,213 ---- *************** *** 246,256 **** } else { - Serializable idInstance = key.getIdentifier(); - //Warning: the following code forces optionalID to refer to the last column of results!!!! - if ( i==cols-1 && optionalID!=null && optionalID.equals(idInstance) ) { - idInstance = optionalID; - } // instantiate a new instance ! object = session.getFactory().getPersister(instanceClass).instantiate(idInstance); } --- 249,254 ---- } else { // instantiate a new instance ! object = session.getFactory().getPersister(instanceClass).instantiate( key.getIdentifier() ); } |