[hibernate-commits] Hibernate SVN: r16625 - core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/event/def.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed May 27 16:26:32 EDT 2009


Author: gbadner
Date: 2009-05-27 16:26:32 -0400 (Wed, 27 May 2009)
New Revision: 16625

Added:
   core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/event/def/EventCache.java
Removed:
   core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/event/def/CopyCache.java
Modified:
   core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/event/def/DefaultMergeEventListener.java
Log:
JBPAPP-1797 HHH-3810 : rename CopyCache to EventCache to be more generic


Deleted: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/event/def/CopyCache.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/event/def/CopyCache.java	2009-05-27 12:01:15 UTC (rev 16624)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/event/def/CopyCache.java	2009-05-27 20:26:32 UTC (rev 16625)
@@ -1,244 +0,0 @@
-//$Id: $
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- *
- */
-package org.hibernate.event.def;
-
-import java.util.Map;
-import java.util.Set;
-import java.util.Iterator;
-import java.util.Collection;
-
-import org.hibernate.util.IdentityMap;
-import org.hibernate.AssertionFailure;
-
-/**
- * CopyCache is intended to be the Map implementation used by
- * {@link DefaultMergeEventListener} to keep track of entities and their copies
- * being merged into the session. This implementation also tracks whether a
- * an entity in the CopyCache is included in the merge. This allows a
- * an entity and its copy to be added to a CopyCache before merge has cascaded
- * to that entity.
- *
- * @author Gail Badner
- */
-class CopyCache implements Map {
-	private Map entityToCopyMap = IdentityMap.instantiate(10);
-		// key is an entity involved with the merge;
-		// value can be either a copy of the entity or the entity itself
-
-	private Map entityToIncludeInMergeFlagMap = IdentityMap.instantiate(10);
-	    // key is an entity involved with the merge;
-	    // value is a flag indicating if the entity is included in the merge
-
-	/**
-	 * Clears the CopyCache.
-	 */
-	public void clear() {
-		entityToCopyMap.clear();
-		entityToIncludeInMergeFlagMap.clear();
-	}
-
-	/**
-	 * Returns true if this CopyCache contains a mapping for the specified entity.
-	 * @param entity must be non-null
-	 * @return true if this CopyCache contains a mapping for the specified entity
-	 * @throws NullPointerException if entity is null
-	 */
-	public boolean containsKey(Object entity) {
-		if ( entity == null ) {
-			throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
-		}
-		return entityToCopyMap.containsKey( entity );
-	}
-
-	/**
-	 * Returns true if this CopyCache maps one or more entities to the specified copy.
-	 * @param copy must be non-null
-	 * @return true if this CopyCache maps one or more entities to the specified copy
-	 * @throws NullPointerException if copy is null
-	 */
-	public boolean containsValue(Object copy) {
-		if ( copy == null ) {
-			throw new NullPointerException( "null copies are not supported by " + getClass().getName() );
-		}
-		return entityToCopyMap.containsValue( copy );
-	}
-
-	/**
-	 * Returns a set view of the entity-to-copy mappings contained in this CopyCache.
-	 * @return set view of the entity-to-copy mappings contained in this CopyCache
-	 */
-	public Set entrySet() {
-		return entityToCopyMap.entrySet();
-	}
-
-	/**
-	 * Returns the copy to which this CopyCache maps the specified entity.
-	 * @param entity must be non-null
-	 * @return the copy to which this CopyCache maps the specified entity
-	 * @throws NullPointerException if entity is null
-	 */
-	public Object get(Object entity) {
-		if ( entity == null ) {
-			throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
-		}
-		return entityToCopyMap.get( entity );
-	}
-
-	/**
-	 * Returns true if this CopyCache contains no entity-copy mappings.
-	 * @return true if this CopyCache contains no entity-copy mappings
-	 */
-	public boolean isEmpty() {
-		return entityToCopyMap.isEmpty();
-	}
-
-	/**
-	 * Returns a set view of the entities contained in this CopyCache
-	 * @return a set view of the entities contained in this CopyCache
-	 */
-	public Set keySet() {
-		return entityToCopyMap.keySet();
-	}
-
-	/**
-	 * Associates the specified entity with the specified copy in this CopyCache;
-	 * @param entity must be non-null
-	 * @param copy must be non- null
-	 * @return previous copy associated with specified entity, or null if
-	 * there was no mapping for entity.
-	 * @throws NullPointerException if entity or copy is null
-	 */
-	public Object put(Object entity, Object copy) {
-		if ( entity == null || copy == null ) {
-			throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
-		}
-		entityToIncludeInMergeFlagMap.put( entity, Boolean.FALSE );
-		return entityToCopyMap.put( entity, copy );
-	}
-
-	/**
-	 * Associates the specified entity with the specified copy in this CopyCache;
-	 * @param entity must be non-null
-	 * @param copy must be non- null
-	 * @param isIncludedInMerge indicates if the entity is included in merge
-	 *
-	 * @return previous copy associated with specified entity, or null if
-	 * there was no mapping for entity.
-	 * @throws NullPointerException if entity or copy is null
-	 */
-	/* package-private */ Object put(Object entity, Object copy, boolean isIncludedInMerge) {
-		if ( entity == null || copy == null ) {
-			throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
-		}
-		entityToIncludeInMergeFlagMap.put( entity, Boolean.valueOf( isIncludedInMerge ) );
-		return entityToCopyMap.put( entity, copy );
-	}
-
-	/**
-	 * Copies all of the mappings from the specified map to this CopyCache
-	 * @param map keys and values must be non-null
-	 * @throws NullPointerException if any map keys or values are null
-	 */
-	public void putAll(Map map) {
-		for ( Iterator it=map.entrySet().iterator(); it.hasNext(); ) {
-			Map.Entry entry = ( Map.Entry ) it.next();
-			if ( entry.getKey() == null || entry.getValue() == null ) {
-				throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
-			}
-			entityToCopyMap.put( entry.getKey(), entry.getValue() );
-			entityToIncludeInMergeFlagMap.put( entry.getKey(), Boolean.FALSE );
-		}
-	}
-
-	/**
-	 * Removes the mapping for this entity from this CopyCache if it is present
-	 * @param entity must be non-null
-	 * @return previous value associated with specified entity, or null if there was no mapping for entity.
-	 * @throws NullPointerException if entity is null
-	 */
-	public Object remove(Object entity) {
-		if ( entity == null ) {
-			throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
-		}
-		entityToIncludeInMergeFlagMap.remove( entity );
-		return entityToCopyMap.remove( entity );
-	}
-
-	/**
-	 * Returns the number of entity-copy mappings in this CopyCache
-	 * @return the number of entity-copy mappings in this CopyCache
-	 */
-	public int size() {
-		return entityToCopyMap.size();
-	}
-
-	/**
-	 * Returns a collection view of the entity copies contained in this CopyCache.
-	 * @return a collection view of the entity copies contained in this CopyCache
-	 */
-	public Collection values() {
-		return entityToCopyMap.values();
-	}
-
-	/**
-	 * Returns true if the specified entity is included in the merge.
-	 * @param entity must be non-null
-	 * @return true if the specified entity is included in the merge.
-	 * @throws NullPointerException if entity is null
-	 */
-	public boolean isIncludedInMerge(Object entity) {
-		if ( entity == null ) {
-			throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
-		}
-		return ( ( Boolean ) entityToIncludeInMergeFlagMap.get( entity ) ).booleanValue();
-	}
-
-	/**
-	 * Set flag to indicate if an entity is included in the merge.
-	 * @param entity must be non-null and this CopyCache must contain a mapping for this entity
-	 * @return true if the specified entity is included in the merge
-	 * @throws NullPointerException if entity is null
-	 * @throws AssertionFailure if this CopyCache does not contain a mapping for the specified entity
-	 */
-	/* package-private */ void setIncludedInMerge(Object entity, boolean isIncludedInMerge) {
-		if ( entity == null ) {
-			throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
-		}
-		if ( ! entityToIncludeInMergeFlagMap.containsKey( entity ) ||
-			! entityToCopyMap.containsKey( entity ) ) {
-			throw new AssertionFailure( "called CopyCache.setInMergeProcess() for entity not found in CopyCache" );
-		}
-		entityToIncludeInMergeFlagMap.put( entity, Boolean.valueOf( isIncludedInMerge ) );
-	}
-
-	/**
-	 * Returns the copy-entity mappings
-	 * @return the copy-entity mappings
-	 */
-	public Map getMergeMap() {
-		return IdentityMap.invert( entityToCopyMap );
-	}
-}
\ No newline at end of file

Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/event/def/DefaultMergeEventListener.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/event/def/DefaultMergeEventListener.java	2009-05-27 12:01:15 UTC (rev 16624)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/event/def/DefaultMergeEventListener.java	2009-05-27 20:26:32 UTC (rev 16625)
@@ -71,7 +71,7 @@
 	private static final Log log = LogFactory.getLog(DefaultMergeEventListener.class);
 
 	protected Map getMergeMap(Object anything) {
-		return ( ( CopyCache ) anything ).getMergeMap();
+		return ( ( EventCache ) anything ).invertMap();
 	}
 
 	/**
@@ -81,7 +81,7 @@
 	 * @throws HibernateException
 	 */
 	public void onMerge(MergeEvent event) throws HibernateException {
-		CopyCache copyCache = new CopyCache();
+		EventCache copyCache = new EventCache();
 		onMerge( event, copyCache );
 		// TODO: iteratively get transient entities and retry merge until one of the following conditions:
 		//       1) transientCopyCache.size() == 0
@@ -111,8 +111,8 @@
 		copyCache = null;
 	}
 
-	protected CopyCache getTransientCopyCache(MergeEvent event, CopyCache copyCache) {
-		CopyCache transientCopyCache = new CopyCache();
+	protected EventCache getTransientCopyCache(MergeEvent event, EventCache copyCache) {
+		EventCache transientCopyCache = new EventCache();
 		for ( Iterator it=copyCache.entrySet().iterator(); it.hasNext(); ) {
 			Map.Entry mapEntry = ( Map.Entry ) it.next();
 			Object entity = mapEntry.getKey();
@@ -132,7 +132,7 @@
 				);
 			}
 			else if ( copyEntry.getStatus() == Status.SAVING ) {
-				transientCopyCache.put( entity, copy, copyCache.isIncludedInMerge( entity ) );
+				transientCopyCache.put( entity, copy, copyCache.isOperatedOn( entity ) );
 			}
 			else if ( copyEntry.getStatus() != Status.MANAGED && copyEntry.getStatus() != Status.READ_ONLY ) {
 				throw new AssertionFailure( "Merged entity does not have status set to MANAGED or READ_ONLY; "+copy+" status="+copyEntry.getStatus() );
@@ -141,7 +141,7 @@
 		return transientCopyCache;
 	}
 
-	protected void retryMergeTransientEntities(MergeEvent event, Map transientCopyCache, CopyCache copyCache) {
+	protected void retryMergeTransientEntities(MergeEvent event, Map transientCopyCache, EventCache copyCache) {
 		// TODO: The order in which entities are saved may matter (e.g., a particular transient entity
 		//       may need to be saved before other transient entities can be saved;
 		//       Keep retrying the batch of transient entities until either:
@@ -170,7 +170,7 @@
 	 */
 	public void onMerge(MergeEvent event, Map copiedAlready) throws HibernateException {
 
-		final CopyCache copyCache = ( CopyCache ) copiedAlready;
+		final EventCache copyCache = ( EventCache ) copiedAlready;
 		final EventSource source = event.getSession();
 		final Object original = event.getOriginal();
 
@@ -193,14 +193,14 @@
 			}
 
 			if ( copyCache.containsKey( entity ) &&
-					( copyCache.isIncludedInMerge( entity ) ) ) {
+					( copyCache.isOperatedOn( entity ) ) ) {
 				log.trace("already in merge process");
 				event.setResult( entity );				
 			}
 			else {
 				if ( copyCache.containsKey( entity ) ) {
 					log.trace("already in copyCache; setting in merge process");					
-					copyCache.setIncludedInMerge( entity, true );
+					copyCache.setOperatedOn( entity, true );
 				}
 				event.setEntity( entity );
 				int entityState = -1;
@@ -262,7 +262,7 @@
 		final EventSource source = event.getSession();
 		final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
 
-		( ( CopyCache ) copyCache ).put( entity, entity, true  );  //before cascade!
+		( ( EventCache ) copyCache ).put( entity, entity, true  );  //before cascade!
 		
 		cascadeOnMerge(source, persister, entity, copyCache);
 		copyValues(persister, entity, entity, source, copyCache);
@@ -296,7 +296,7 @@
 			persister.setIdentifier( copyCache.get( entity ), id, source.getEntityMode() );
 		}
 		else {
-			( ( CopyCache ) copyCache ).put( entity, persister.instantiate( id, source.getEntityMode() ), true ); //before cascade!
+			( ( EventCache ) copyCache ).put( entity, persister.instantiate( id, source.getEntityMode() ), true ); //before cascade!
 			//TODO: should this be Session.instantiate(Persister, ...)?
 		}
 		final Object copy = copyCache.get( entity );
@@ -334,7 +334,7 @@
 						"' from original entity is not in copyCache; " + propertyName + " =["+propertyFromEntity+"]");
 				throw ex;
 			}
-			if ( ( ( CopyCache ) copyCache ).isIncludedInMerge( propertyFromEntity ) ) {
+			if ( ( ( EventCache ) copyCache ).isOperatedOn( propertyFromEntity ) ) {
 				log.trace( "property '" + copyEntry.getEntityName() + "." + propertyName +
 						"' from original entity is in copyCache and is in the process of being merged; " +
 						propertyName + " =["+propertyFromEntity+"]");
@@ -398,7 +398,7 @@
 			entityIsTransient(event, copyCache);
 		}
 		else {
-			( ( CopyCache ) copyCache ).put( entity, result, true ); //before cascade!
+			( ( EventCache ) copyCache ).put( entity, result, true ); //before cascade!
 	
 			final Object target = source.getPersistenceContext().unproxy(result);
 			if ( target == entity ) {

Copied: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/event/def/EventCache.java (from rev 16624, core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/event/def/CopyCache.java)
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/event/def/EventCache.java	                        (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/event/def/EventCache.java	2009-05-27 20:26:32 UTC (rev 16625)
@@ -0,0 +1,253 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ *
+ */
+package org.hibernate.event.def;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.Collection;
+
+import org.hibernate.util.IdentityMap;
+import org.hibernate.AssertionFailure;
+
+/**
+ * EventCache is a Map implementation that can be used by an event
+ * listener to keep track of entities involved in the operation
+ * being performed. This implementation allows entities to be added
+ * to the EventCache before the operation has cascaded to that
+ * entity.
+ * <p/>
+ * The following methods can be used by event listeners (and other
+ * classes) in the same package to add entities to an EventCache
+ * and indicate if the operation is being performed on the entity:<p/>
+ * {@link EventCache#put(Object entity, Object copy, boolean isOperatedOn)}
+ * <p/>
+ * The following method can be used by event listeners (and other
+ * classes) in the same package to indicate that the operation is being
+ * performed on an entity already in the EventCache:
+ * {@link EventCache#setOperatedOn(Object entity, boolean isOperatedOn)
+ *
+ * @author Gail Badner
+ */
+class EventCache implements Map {
+	private Map entityToCopyMap = IdentityMap.instantiate(10);
+		// key is an entity involved with the operation performed by the listener;
+		// value can be either a copy of the entity or the entity itself
+
+	private Map entityToOperatedOnFlagMap = IdentityMap.instantiate(10);
+	    // key is an entity involved with the operation performed by the listener;
+	    // value is a flag indicating if the listener explicitly operates on the entity
+
+	/**
+	 * Clears the EventCache.
+	 */
+	public void clear() {
+		entityToCopyMap.clear();
+		entityToOperatedOnFlagMap.clear();
+	}
+
+	/**
+	 * Returns true if this EventCache contains a mapping for the specified entity.
+	 * @param entity must be non-null
+	 * @return true if this EventCache contains a mapping for the specified entity
+	 * @throws NullPointerException if entity is null
+	 */
+	public boolean containsKey(Object entity) {
+		if ( entity == null ) {
+			throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+		}
+		return entityToCopyMap.containsKey( entity );
+	}
+
+	/**
+	 * Returns true if this EventCache maps one or more entities to the specified copy.
+	 * @param copy must be non-null
+	 * @return true if this EventCache maps one or more entities to the specified copy
+	 * @throws NullPointerException if copy is null
+	 */
+	public boolean containsValue(Object copy) {
+		if ( copy == null ) {
+			throw new NullPointerException( "null copies are not supported by " + getClass().getName() );
+		}
+		return entityToCopyMap.containsValue( copy );
+	}
+
+	/**
+	 * Returns a set view of the entity-to-copy mappings contained in this EventCache.
+	 * @return set view of the entity-to-copy mappings contained in this EventCache
+	 */
+	public Set entrySet() {
+		return entityToCopyMap.entrySet();
+	}
+
+	/**
+	 * Returns the copy to which this EventCache maps the specified entity.
+	 * @param entity must be non-null
+	 * @return the copy to which this EventCache maps the specified entity
+	 * @throws NullPointerException if entity is null
+	 */
+	public Object get(Object entity) {
+		if ( entity == null ) {
+			throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+		}
+		return entityToCopyMap.get( entity );
+	}
+
+	/**
+	 * Returns true if this EventCache contains no entity-copy mappings.
+	 * @return true if this EventCache contains no entity-copy mappings
+	 */
+	public boolean isEmpty() {
+		return entityToCopyMap.isEmpty();
+	}
+
+	/**
+	 * Returns a set view of the entities contained in this EventCache
+	 * @return a set view of the entities contained in this EventCache
+	 */
+	public Set keySet() {
+		return entityToCopyMap.keySet();
+	}
+
+	/**
+	 * Associates the specified entity with the specified copy in this EventCache;
+	 * @param entity must be non-null
+	 * @param copy must be non- null
+	 * @return previous copy associated with specified entity, or null if
+	 * there was no mapping for entity.
+	 * @throws NullPointerException if entity or copy is null
+	 */
+	public Object put(Object entity, Object copy) {
+		if ( entity == null || copy == null ) {
+			throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
+		}
+		entityToOperatedOnFlagMap.put( entity, Boolean.FALSE );
+		return entityToCopyMap.put( entity, copy );
+	}
+
+	/**
+	 * Associates the specified entity with the specified copy in this EventCache;
+	 * @param entity must be non-null
+	 * @param copy must be non- null
+	 * @param isOperatedOn indicates if the operation is performed on the entity
+	 *
+	 * @return previous copy associated with specified entity, or null if
+	 * there was no mapping for entity.
+	 * @throws NullPointerException if entity or copy is null
+	 */
+	/* package-private */ Object put(Object entity, Object copy, boolean isOperatedOn) {
+		if ( entity == null || copy == null ) {
+			throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
+		}
+		entityToOperatedOnFlagMap.put( entity, Boolean.valueOf( isOperatedOn ) );
+		return entityToCopyMap.put( entity, copy );
+	}
+
+	/**
+	 * Copies all of the mappings from the specified map to this EventCache
+	 * @param map keys and values must be non-null
+	 * @throws NullPointerException if any map keys or values are null
+	 */
+	public void putAll(Map map) {
+		for ( Iterator it=map.entrySet().iterator(); it.hasNext(); ) {
+			Map.Entry entry = ( Map.Entry ) it.next();
+			if ( entry.getKey() == null || entry.getValue() == null ) {
+				throw new NullPointerException( "null entities and copies are not supported by " + getClass().getName() );
+			}
+			entityToCopyMap.put( entry.getKey(), entry.getValue() );
+			entityToOperatedOnFlagMap.put( entry.getKey(), Boolean.FALSE );
+		}
+	}
+
+	/**
+	 * Removes the mapping for this entity from this EventCache if it is present
+	 * @param entity must be non-null
+	 * @return previous value associated with specified entity, or null if there was no mapping for entity.
+	 * @throws NullPointerException if entity is null
+	 */
+	public Object remove(Object entity) {
+		if ( entity == null ) {
+			throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+		}
+		entityToOperatedOnFlagMap.remove( entity );
+		return entityToCopyMap.remove( entity );
+	}
+
+	/**
+	 * Returns the number of entity-copy mappings in this EventCache
+	 * @return the number of entity-copy mappings in this EventCache
+	 */
+	public int size() {
+		return entityToCopyMap.size();
+	}
+
+	/**
+	 * Returns a collection view of the entity copies contained in this EventCache.
+	 * @return a collection view of the entity copies contained in this EventCache
+	 */
+	public Collection values() {
+		return entityToCopyMap.values();
+	}
+
+	/**
+	 * Returns true if the listener is performing the operation on the specified entity.
+	 * @param entity must be non-null
+	 * @return true if the listener is performing the operation on the specified entity.
+	 * @throws NullPointerException if entity is null
+	 */
+	public boolean isOperatedOn(Object entity) {
+		if ( entity == null ) {
+			throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+		}
+		return ( ( Boolean ) entityToOperatedOnFlagMap.get( entity ) ).booleanValue();
+	}
+
+	/**
+	 * Set flag to indicate if the listener is performing the operation on the specified entity.
+	 * @param entity must be non-null and this EventCache must contain a mapping for this entity
+	 * @return true if the listener is performing the operation on the specified entity
+	 * @throws NullPointerException if entity is null
+	 * @throws AssertionFailure if this EventCache does not contain a mapping for the specified entity
+	 */
+	/* package-private */ void setOperatedOn(Object entity, boolean isOperatedOn) {
+		if ( entity == null ) {
+			throw new NullPointerException( "null entities are not supported by " + getClass().getName() );
+		}
+		if ( ! entityToOperatedOnFlagMap.containsKey( entity ) ||
+			! entityToCopyMap.containsKey( entity ) ) {
+			throw new AssertionFailure( "called EventCache.setOperatedOn() for entity not found in EventCache" );
+		}
+		entityToOperatedOnFlagMap.put( entity, Boolean.valueOf( isOperatedOn ) );
+	}
+
+	/**
+	 * Returns the copy-entity mappings
+	 * @return the copy-entity mappings
+	 */
+	public Map invertMap() {
+		return IdentityMap.invert( entityToCopyMap );
+	}
+}
\ No newline at end of file




More information about the hibernate-commits mailing list