⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dirtycollectionsearchvisitor.java

📁 用Java实现的23个常用设计模式源代码
💻 JAVA
字号:
//$Id: DirtyCollectionSearchVisitor.java,v 1.1.2.4 2003/11/27 16:09:59 oneovthafew Exp $
package net.sf.hibernate.impl;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.collection.PersistentCollection;
import net.sf.hibernate.type.PersistentCollectionType;

/**
 * Do we have a dirty collection here?
 * 1. if it is a new application-instantiated collection, return true (does not occur anymore!)
 * 2. if it is a component, recurse
 * 3. if it is a wrappered collection, ask the collection entry
 * 
 * @author Gavin King
 */
class DirtyCollectionSearchVisitor extends AbstractVisitor {
	
	private boolean dirty = false;

	DirtyCollectionSearchVisitor(SessionImpl session) {
		super(session);
	}
	
	boolean wasDirtyCollectionFound() {
		return dirty;
	}

	Object processCollection(Object collection, PersistentCollectionType type)
		throws HibernateException {
		
		if (collection!=null) {
			
			SessionImpl session = getSession();
			
			final PersistentCollection coll;
			if ( type.isArrayType() ) {
				 coll = session.getArrayHolder(collection);
				// if no array holder we found an unwrappered array (this can't occur,
				// because we now always call wrap() before getting to here)
				// return (ah==null) ? true : searchForDirtyCollections(ah, type);
			}
			else {
				// if not wrappered yet, its dirty (this can't occur, because
				// we now always call wrap() before getting to here)
				// return ( ! (obj instanceof PersistentCollection) ) ?
				//true : searchForDirtyCollections( (PersistentCollection) obj, type );
				coll = (PersistentCollection) collection;
			}
			
			if ( session.collectionIsDirty(coll) ) {
				dirty=true; 
				//TODO: abort the rest of the search!
			}
		}
		
		return null;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -