From: Gavin_King/Cirrus%<CI...@ci...> - 2002-08-03 01:31:08
|
>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. |