KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > event > def > DirtyCollectionSearchVisitor


1 //$Id: DirtyCollectionSearchVisitor.java,v 1.6 2005/06/17 19:36:08 oneovthafew Exp $
2
package org.hibernate.event.def;
3
4 import org.hibernate.HibernateException;
5 import org.hibernate.collection.PersistentCollection;
6 import org.hibernate.engine.SessionImplementor;
7 import org.hibernate.event.EventSource;
8 import org.hibernate.type.CollectionType;
9
10 /**
11  * Do we have a dirty collection here?
12  * 1. if it is a new application-instantiated collection, return true (does not occur anymore!)
13  * 2. if it is a component, recurse
14  * 3. if it is a wrappered collection, ask the collection entry
15  *
16  * @author Gavin King
17  */

18 public class DirtyCollectionSearchVisitor extends AbstractVisitor {
19
20     private boolean dirty = false;
21     private boolean[] propertyVersionability;
22
23     DirtyCollectionSearchVisitor(EventSource session, boolean[] propertyVersionability) {
24         super(session);
25         this.propertyVersionability = propertyVersionability;
26     }
27
28     boolean wasDirtyCollectionFound() {
29         return dirty;
30     }
31
32     Object JavaDoc processCollection(Object JavaDoc collection, CollectionType type)
33         throws HibernateException {
34
35         if (collection!=null) {
36
37             SessionImplementor session = getSession();
38
39             final PersistentCollection persistentCollection;
40             if ( type.isArrayType() ) {
41                  persistentCollection = session.getPersistenceContext().getCollectionHolder(collection);
42                 // if no array holder we found an unwrappered array (this can't occur,
43
// because we now always call wrap() before getting to here)
44
// return (ah==null) ? true : searchForDirtyCollections(ah, type);
45
}
46             else {
47                 // if not wrappered yet, its dirty (this can't occur, because
48
// we now always call wrap() before getting to here)
49
// return ( ! (obj instanceof PersistentCollection) ) ?
50
//true : searchForDirtyCollections( (PersistentCollection) obj, type );
51
persistentCollection = (PersistentCollection) collection;
52             }
53
54             if ( persistentCollection.wasInitialized() && persistentCollection.isDirty() ) {
55                 dirty=true;
56                 return null; //NOTE: EARLY EXIT!
57
}
58         }
59
60         return null;
61     }
62
63     boolean includeEntityProperty(Object JavaDoc[] values, int i) {
64         return propertyVersionability[i] && super.includeEntityProperty(values, i);
65     }
66 }
67
Popular Tags