Top Description Fields Constructors Methods
org.hibernate.event.internal

public Class MergeContext

extends Object
implements Map
Class Inheritance
All Implemented Interfaces
java.util.Map
Imports
java.util.Collection, .Collections, .IdentityHashMap, .Map, .Set, org.hibernate.event.spi.EntityCopyObserver, .EventSource, org.hibernate.pretty.MessageHelper, org.jboss.logging.Logger

MergeContext is a Map implementation that is intended to be used by a merge event listener to keep track of each entity being merged and their corresponding managed result. Entities to be merged may to be added to the MergeContext before the merge operation has cascaded to that entity. "Merge entity" and "mergeEntity" method parameter refer to an entity that is (or will be) merged via org.hibernate.event.spi.EventSource#merge(Object mergeEntity). "Managed entity" and "managedEntity" method parameter refer to the managed entity that is the result of merging an entity. A merge entity can be transient, detached, or managed. If it is managed, then it must be the same as its associated entity result. If put(Object mergeEntity, Object managedEntity) is called, and this MergeContext already contains an entry with a different entity as the key, but with the same (managedEntity) value, this means that multiple entity representations for the same persistent entity are being merged. If this happens, org.hibernate.event.spi.EntityCopyObserver#entityCopyDetected( Object managedEntity, Object mergeEntity1, Object mergeEntity2, org.hibernate.event.spi.EventSource) will be called. It is up to that method to determine the property course of action for this situation. There are several restrictions.

The following method is intended to be used by a merge event listener (and other classes) in the same package to add a merge entity and its corresponding managed entity to a MergeContext and indicate if the merge operation is being performed on the merge entity yet.

MergeContext#put(Object mergeEntity, Object managedEntity, boolean isOperatedOn)

The following method is intended to be used by a merge event listener (and other classes) in the same package to indicate whether the merge operation is being performed on a merge entity already in the MergeContext: MergeContext#setOperatedOn(Object mergeEntity, boolean isOperatedOn)

Author
Gail Badner

Field Summary

Modifier and TypeField and Description
private final EntityCopyObserver
private static final Logger
private Map<Object, Object>
private Map<Object, Boolean>
private Map<Object, Object>
private final EventSource
session

Deprecated as a consequence of EventSource being deprecated.

Constructor Summary

AccessConstructor and Description
public
MergeContext(EventSource session, EntityCopyObserver entityCopyObserver)

Deprecated as a consequence of EventSource being deprecated.

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Implements java.util.Map.clear.

Clears the MergeContext.
public boolean

Returns:

true if this MergeContext contains a cross-reference for the specified merge entity
containsKey
(Object
must be non-null
mergeEntity
)

Implements java.util.Map.containsKey.

Returns true if this MergeContext contains a cross-reference for the specified merge entity to a managed entity result.
public boolean

Returns:

true if this MergeContext contains a cross-reference from the specified managed entity to a merge entity
containsValue
(Object
must be non-null
managedEntity
)

Implements java.util.Map.containsValue.

Returns true if this MergeContext contains a cross-reference from the specified managed entity to a merge entity.
public Set<E>

Returns:

an unmodifiable set view of the merge-to-managed entity cross-references contained in this MergeContext
entrySet
()

Implements java.util.Map.entrySet.

Returns an unmodifiable set view of the merge-to-managed entity cross-references contained in this MergeContext.
public Object

Returns:

the managed entity associated with the specified merge Entity
get
(Object
the merge entity; must be non-null
mergeEntity
)

Implements java.util.Map.get.

Returns the managed entity associated with the specified merge Entity.
public Map<K, V>

Returns:

an unmodifiable map view of the managed-to-merge entity cross-references.
invertMap
()

Returns an unmodifiable map view of the managed-to-merge entity cross-references.

public boolean

Returns:

true if this MergeContext contains no merge-to-managed entity cross-references.
isEmpty
()

Implements java.util.Map.isEmpty.

Returns true if this MergeContext contains no merge-to-managed entity cross-references.
public boolean

Returns:

true if the listener is performing the merge operation on the specified merge entity; false, if there is no mapping for mergeEntity.
isOperatedOn
(Object
the merge entity; must be non-null
mergeEntity
)

Returns true if the listener is performing the merge operation on the specified merge entity.

public Set<E>

Returns:

an unmodifiable set view of the merge entities contained in this MergeContext
keySet
()

Implements java.util.Map.keySet.

Returns an unmodifiable set view of the merge entities contained in this MergeContext
private String
public Object

Returns:

previous managed entity associated with specified merge entity, or null if there was no mapping for mergeEntity.
put
(Object
the merge entity; must be non-null
mergeEntity
,
Object
the managed entity result; must be non-null
managedEntity
)

Implements java.util.Map.put.

Associates the specified merge entity with the specified managed entity result in this MergeContext.
public Object

Returns:

previous managed entity associated with specified merge entity, or null if there was no mapping for mergeEntity.
put
(Object
the merge entity; must be non-null
mergeEntity
,
Object
the managed entity; must be non-null
managedEntity
,
boolean
indicates if the merge operation is performed on the mergeEntity.
isOperatedOn
)

Associates the specified merge entity with the specified managed entity in this MergeContext.

public void
putAll(Map<K, V>
keys and values must be non-null
map
)

Implements java.util.Map.putAll.

Copies all of the mappings from the specified Map to this MergeContext.
public Object
remove(Object
the merge entity.
mergeEntity
)

Implements java.util.Map.remove.

The remove operation is not supported.
public void
setOperatedOn(Object
must be non-null and this MergeContext must contain a cross-reference for mergeEntity to a managed entity
mergeEntity
,
boolean isOperatedOn)

Set flag to indicate if the listener is performing the merge operation on the specified merge entity.

public int

Returns:

the number of merge-to-managed entity cross-references in this MergeContext
size
()

Implements java.util.Map.size.

Returns the number of merge-to-managed entity cross-references in this MergeContext
public Collection<E>

Returns:

an unmodifiable Set view of managed entities contained in this MergeContext
values
()

Implements java.util.Map.values.

Returns an unmodifiable Set view of managed entities contained in this MergeContext.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

entityCopyObserverback to summary
private final EntityCopyObserver entityCopyObserver
LOGback to summary
private static final Logger LOG
managedToMergeEntityXrefback to summary
private Map<Object, Object> managedToMergeEntityXref
mergeEntityToOperatedOnFlagMapback to summary
private Map<Object, Boolean> mergeEntityToOperatedOnFlagMap
mergeToManagedEntityXrefback to summary
private Map<Object, Object> mergeToManagedEntityXref
sessionback to summary
private final EventSource session

Deprecated

as a consequence of EventSource being deprecated. See corresponding docs for further information.

Constructor Detail

MergeContextback to summary
public MergeContext(EventSource session, EntityCopyObserver entityCopyObserver)

Deprecated

as a consequence of EventSource being deprecated. See corresponding docs for further information.

Method Detail

clearback to summary
public void clear()

Implements java.util.Map.clear.

Clears the MergeContext.

containsKeyback to summary
public boolean containsKey(Object mergeEntity)

Implements java.util.Map.containsKey.

Returns true if this MergeContext contains a cross-reference for the specified merge entity to a managed entity result.

Parameters
mergeEntity:Object

must be non-null

Returns:boolean

true if this MergeContext contains a cross-reference for the specified merge entity

Exceptions
NullPointerException:
if mergeEntity is null
containsValueback to summary
public boolean containsValue(Object managedEntity)

Implements java.util.Map.containsValue.

Returns true if this MergeContext contains a cross-reference from the specified managed entity to a merge entity.

Parameters
managedEntity:Object

must be non-null

Returns:boolean

true if this MergeContext contains a cross-reference from the specified managed entity to a merge entity

Exceptions
NullPointerException:
if managedEntity is null
entrySetback to summary
public Set<E> entrySet()

Implements java.util.Map.entrySet.

Returns an unmodifiable set view of the merge-to-managed entity cross-references contained in this MergeContext.

Returns:Set<E>

an unmodifiable set view of the merge-to-managed entity cross-references contained in this MergeContext

See Also
Collections#unmodifiableSet(java.util.Set)
getback to summary
public Object get(Object mergeEntity)

Implements java.util.Map.get.

Returns the managed entity associated with the specified merge Entity.

Parameters
mergeEntity:Object

the merge entity; must be non-null

Returns:Object

the managed entity associated with the specified merge Entity

Exceptions
NullPointerException:
if mergeEntity is null
invertMapback to summary
public Map<K, V> invertMap()

Returns an unmodifiable map view of the managed-to-merge entity cross-references. The returned Map will contain a cross-reference from each managed entity to the most recently associated merge entity that was most recently put in the MergeContext.

Returns:Map<K, V>

an unmodifiable map view of the managed-to-merge entity cross-references.

See Also
Collections#unmodifiableMap(java.util.Map)
isEmptyback to summary
public boolean isEmpty()

Implements java.util.Map.isEmpty.

Returns true if this MergeContext contains no merge-to-managed entity cross-references.

Returns:boolean

true if this MergeContext contains no merge-to-managed entity cross-references.

isOperatedOnback to summary
public boolean isOperatedOn(Object mergeEntity)

Returns true if the listener is performing the merge operation on the specified merge entity.

Parameters
mergeEntity:Object

the merge entity; must be non-null

Returns:boolean

true if the listener is performing the merge operation on the specified merge entity; false, if there is no mapping for mergeEntity.

Exceptions
NullPointerException:
if mergeEntity is null
keySetback to summary
public Set<E> keySet()

Implements java.util.Map.keySet.

Returns an unmodifiable set view of the merge entities contained in this MergeContext

Returns:Set<E>

an unmodifiable set view of the merge entities contained in this MergeContext

See Also
Collections#unmodifiableSet(java.util.Set)
printEntityback to summary
private String printEntity(Object entity)
putback to summary
public Object put(Object mergeEntity, Object managedEntity)

Implements java.util.Map.put.

Associates the specified merge entity with the specified managed entity result in this MergeContext. If this MergeContext already contains a cross-reference for mergeEntity when this method is called, then managedEntity must be the same as what is already associated with mergeEntity.

This method assumes that the merge process is not yet operating on mergeEntity. Later when mergeEntity enters the merge process, setOperatedOn(Object, boolean) should be called.

Parameters
mergeEntity:Object

the merge entity; must be non-null

managedEntity:Object

the managed entity result; must be non-null

Returns:Object

previous managed entity associated with specified merge entity, or null if there was no mapping for mergeEntity.

Exceptions
NullPointerException:
if mergeEntity or managedEntity is null
IllegalArgumentException:
if managedEntity is not the same as the previous managed entity associated with merge entity
IllegalStateException:
if internal cross-references are out of sync,
putback to summary
public Object put(Object mergeEntity, Object managedEntity, boolean isOperatedOn)

Associates the specified merge entity with the specified managed entity in this MergeContext. If this MergeContext already contains a cross-reference for mergeEntity when this method is called, then managedEntity must be the same as what is already associated with mergeEntity.

Parameters
mergeEntity:Object

the merge entity; must be non-null

managedEntity:Object

the managed entity; must be non-null

isOperatedOn:boolean

indicates if the merge operation is performed on the mergeEntity.

Returns:Object

previous managed entity associated with specified merge entity, or null if there was no mapping for mergeEntity.

Exceptions
NullPointerException:
if mergeEntity or managedEntity is null
IllegalArgumentException:
if managedEntity is not the same as the previous managed entity associated with mergeEntity
IllegalStateException:
if internal cross-references are out of sync,
putAllback to summary
public void putAll(Map<K, V> map)

Implements java.util.Map.putAll.

Copies all of the mappings from the specified Map to this MergeContext. The key and value for each entry in map is subject to the same restrictions as put(Object mergeEntity, Object managedEntity). This method assumes that the merge process is not yet operating on any merge entity

Parameters
map:Map<K, V>

keys and values must be non-null

Exceptions
NullPointerException:
if any key or value is null
IllegalArgumentException:
if a key in map was already in this MergeContext but associated value in map is different from the previous value in this MergeContext.
IllegalStateException:
if internal cross-references are out of sync,
removeback to summary
public Object remove(Object mergeEntity)

Implements java.util.Map.remove.

The remove operation is not supported.

Parameters
mergeEntity:Object

the merge entity.

Returns:Object

Doc from java.util.Map.remove.

the previous value associated with key, or null if there was no mapping for key.

Exceptions
UnsupportedOperationException:
if called.
setOperatedOnback to summary
public void setOperatedOn(Object mergeEntity, boolean isOperatedOn)

Set flag to indicate if the listener is performing the merge operation on the specified merge entity.

Parameters
mergeEntity:Object

must be non-null and this MergeContext must contain a cross-reference for mergeEntity to a managed entity

Exceptions
NullPointerException:
if mergeEntity is null
IllegalStateException:
if this MergeContext does not contain a a cross-reference for mergeEntity
sizeback to summary
public int size()

Implements java.util.Map.size.

Returns the number of merge-to-managed entity cross-references in this MergeContext

Returns:int

the number of merge-to-managed entity cross-references in this MergeContext

valuesback to summary
public Collection<E> values()

Implements java.util.Map.values.

Returns an unmodifiable Set view of managed entities contained in this MergeContext.

Returns:Collection<E>

an unmodifiable Set view of managed entities contained in this MergeContext

See Also
Collections#unmodifiableSet(java.util.Set)