From: Urberg, J. <ju...@ve...> - 2002-08-05 13:42:11
|
I always forget to copy these to the list... I guess I don't understand the whole caching thing then. Let's use the following example: I have a loan with a collection of borrowers. I issue a query to get all the borrowers for a loan. Then I issue a query (or a load) to get a loan. I would expect the following to happen: 1) the query against Borrower loads the cache in the ClassPersister for the Borrower 2) the query against Loan causes the borrower collection on the Loan to get evaluated 3) Hibernate looks in the Borrower's cache to see if there are any Borrower records that match the Loan. 3a) If there are matching Borrowers, Hibernate builds a real Collection class filled with matching Borrower's 3b) If there are no matches, Hibernate puts issues a query to get matching Borrowers (or adds a proxy if it's a lazy collection) That would also mean I could issue one query that joined loan and borrower and returned both in the result set (which loads both caches), ignore the result set, then do a load on the Loan (which builds the loan from the loan cache and then does steps 2 & 3. Thoughts? Regards, John -----Original Message----- From: Gavin_King/Cirrus%CI...@ci... [mailto:Gavin_King/Cirrus%CI...@ci...] Sent: Friday, August 02, 2002 8:15 PM To: hib...@li... Subject: RE: [Hibernate-devel] Getting Collections to pull data from the cache >At the point a collection is loaded from the database, Hibernate should >disassemble each object in the collection and store that either with the >collection's owner's cached value or in a cache in the collection's >CollectionPersistor. > >Is that correct? yes. essentially correct. After the collection is initialized, the CollectionPersister should disassemble the collection (ie. turn it into an array of elements or array of elements and indices). Then any contained objects should also be disassembled ie. entities -> an id components -> property array subcollections -> an id mutable types -> a clone currently this logic is already implemented for you, but in the wrong place (on ClassPersister): ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ private Object disassemble(Object object, Type type, SessionImplementor session) throws HibernateException, SQLException { if ( object==null ) { return null; } else if( type.isPersistentObjectType() ) { return session.getID(object); } else if( type.isComponentType() ) { AbstractComponentType ctype = (AbstractComponentType) type; Type[] types = ctype.getSubtypes(); Object[] values = ctype.getValues(object); for ( int i=0; i<types.length; i++ ) { values[i] = disassemble( values[i], types[i], session ); } return values; } else if ( type.isPersistentCollectionType() ) { PersistentCollection pc; if ( object instanceof PersistentCollection ) { pc = (PersistentCollection) object; } else { pc = session.getArrayHolder(object); } return session.getLoadedID(pc); } else { // a leaf return type.deepCopy(object, session); } } ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ We should probably move the assemble() / disassemble() methods to the Type interface. This would be much more object oriented and flexible than the above (a really perfect example of the worst kind of non-use of polymorphism - but I had my reasons at the time....) After disassembly, we would need to keep the disassembled state in either the owning object's cache entry (but this conflicts a bit with lazy collection initialization) or a cache owned by the CollectionPersister. ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Hibernate-devel mailing list Hib...@li... https://lists.sourceforge.net/lists/listinfo/hibernate-devel |