1
//$Id: DirtyCollectionSearchVisitor.java 7675 2005-07-29 06:25:23Z oneovthafew $
2
package org.hibernate.event.def;
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;
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
18
public class DirtyCollectionSearchVisitor extends AbstractVisitor {
20
private boolean dirty = false;
21
private boolean[] propertyVersionability;
23
DirtyCollectionSearchVisitor(EventSource session, boolean[] propertyVersionability) {
25
this.propertyVersionability = propertyVersionability;
28
boolean wasDirtyCollectionFound() {
32
Object processCollection(Object collection, CollectionType type)
33
throws HibernateException {
35
if (collection!=null) {
37
SessionImplementor session = getSession();
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);
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;
54
if ( persistentCollection.isDirty() ) { //we need to check even if it was not initialized, because of delayed adds!
56
return null; //NOTE: EARLY EXIT!
63
boolean includeEntityProperty(Object[] values, int i) {
64
return propertyVersionability[i] && super.includeEntityProperty(values, i);