~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to src/org/hibernate/event/def/DirtyCollectionSearchVisitor.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//$Id: DirtyCollectionSearchVisitor.java 7675 2005-07-29 06:25:23Z oneovthafew $
 
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 processCollection(Object 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.isDirty() ) { //we need to check even if it was not initialized, because of delayed adds!
 
55
                                dirty=true;
 
56
                                return null; //NOTE: EARLY EXIT!
 
57
                        }
 
58
                }
 
59
 
 
60
                return null;
 
61
        }
 
62
 
 
63
        boolean includeEntityProperty(Object[] values, int i) {
 
64
                return propertyVersionability[i] && super.includeEntityProperty(values, i);
 
65
        }
 
66
}