MergeContext is a specialized Map implementation used by a
merge event listener
to keep track of each entity being merged and its corresponding managed result.
An entity to be merged may to be added to the MergeContext before the
merge operation cascades to the entity.
mergeEntity method parameter) is an
entity being merged via EventSource#merge(Object mergeEntity).
managedEntity method parameter) is
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 is identical to its resulting managed entity.
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 (managed entity) value, this means that multiple entity
representations for the same persistent entity are being merged. In this
situation, EntityCopyObserver#entityCopyDetected(
Object managedEntity, Object mergeEntity1, Object mergeEntity2, EventSource)
is called to determine an appropriate resolution.
There are several restrictions.
keySet(), values(),
entrySet()) return an unmodifiable view of the collection.
managedEntity or
put(Object mergeEntity, Object managedEntity, boolean isOperatedOn)
is executed and this MergeContext already contains a cross reference
for mergeEntity, then managedEntity must be identical to the
entity already associated with mergeEntity.
putAll(Map map) is executed, the previous restriction applies to
each entry in the Map.
remove(Object) operation is not supported; the only way to
remove data from a MergeContext is by calling clear().
invertMap() will only contain the "newest"
(most recently added) managed-to-merge cross-reference to its merge entity.
The following method is intended to be used by an implementation of
org. 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 MergeEventListener to
indicate whether the merge operation is being performed on a merge entity already
in the MergeContext:
MergeContext#setOperatedOn(Object mergeEntity, boolean isOperatedOn)
| Modifier and Type | Field and Description |
|---|---|
| private final EntityCopyObserver | |
| private final Map | |
| private final Map | |
| private final Map | |
| private final EventSource |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public boolean | Returns: true if this MergeContext contains a cross-reference for the specified merge entitymust be non-null mergeEntity)Implements java. |
| public boolean | Returns: true if this MergeContext contains a cross-reference from the specified managed entity to a merge entitymust be non-null managedEntity)Implements java. |
| public Set | Returns: an unmodifiable set view of the merge-to-managed entity cross-references contained in this MergeContextImplements java. |
| public Object | Returns: the managed entity associated with the specified merge Entitythe merge entity; must be non-null mergeEntity)Implements java. |
| public Map | Returns: an unmodifiable map view of the managed-to-merge entity cross-references.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.Implements java. |
| 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.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 | Returns: an unmodifiable set view of the merge entities contained in this MergeContextImplements java. |
| private String | |
| public Object | Returns: previous managed entity associated with specified merge entity, or null if there was no mapping for mergeEntity.the merge entity; must be non-null mergeEntity, Object the managed entity result; must be non-null managedEntity)Implements java. |
| public Object | Returns: previous managed entity associated with specified merge entity, or null if there was no mapping for mergeEntity.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<?, ?>
keys and values must be non-null map)Implements java. |
| public Object | remove(Object
the merge entity. mergeEntity)Implements java. |
| 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 MergeContextImplements java. |
| public Collection | Returns: an unmodifiable Set view of managed entities contained in this MergeContextImplements java. |
| entityCopyObserver | back to summary |
|---|---|
| private final EntityCopyObserver entityCopyObserver | |
| managedToMergeEntityXref | back to summary |
|---|---|
| private final Map<Object, Object> managedToMergeEntityXref | |
| mergeEntityToOperatedOnFlagMap | back to summary |
|---|---|
| private final Map<Object, Boolean> mergeEntityToOperatedOnFlagMap | |
| mergeToManagedEntityXref | back to summary |
|---|---|
| private final Map<Object, Object> mergeToManagedEntityXref | |
| session | back to summary |
|---|---|
| private final EventSource session | |
| MergeContext | back to summary |
|---|---|
| public MergeContext(EventSource session, EntityCopyObserver entityCopyObserver) | |
| clear | back to summary |
|---|---|
| public void clear() Implements java. Clears the MergeContext. | |
| containsKey | back to summary |
|---|---|
| public boolean containsKey(Object mergeEntity) Implements java. Returns true if this MergeContext contains a cross-reference for the specified merge entity to a managed entity result.
| |
| containsValue | back to summary |
|---|---|
| public boolean containsValue(Object managedEntity) Implements java. Returns true if this MergeContext contains a cross-reference from the specified managed entity to a merge entity.
| |
| entrySet | back to summary |
|---|---|
| public Set Implements java. Returns an unmodifiable set view of the merge-to-managed entity cross-references contained in this MergeContext. | |
| get | back to summary |
|---|---|
| public Object get(Object mergeEntity) Implements java. Returns the managed entity associated with the specified merge Entity.
| |
| invertMap | back to summary |
|---|---|
| public Map 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.
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements java. Returns true if this MergeContext contains no merge-to-managed entity cross-references.
| |
| isOperatedOn | back to summary |
|---|---|
| public boolean isOperatedOn(Object mergeEntity) Returns true if the listener is performing the merge operation on the specified merge entity.
| |
| keySet | back to summary |
|---|---|
| public Set Implements java. Returns an unmodifiable set view of the merge entities contained in this MergeContext
| |
| printEntity | back to summary |
|---|---|
| private String printEntity(Object entity) | |
| put | back to summary |
|---|---|
| public Object put(Object mergeEntity, Object managedEntity) Implements java. Associates the specified merge entity with the specified managed entity result in this MergeContext.
If this MergeContext already contains a cross-reference for
This method assumes that the merge process is not yet operating on
| |
| put | back 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
| |
| putAll | back to summary |
|---|---|
| public void putAll(Map<?, ?> map) Implements java. Copies all of the mappings from the specified Map to this MergeContext.
The key and value for each entry in
| |
| remove | back to summary |
|---|---|
| public Object remove(Object mergeEntity) Implements java. The remove operation is not supported.
| |
| setOperatedOn | back 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.
| |
| size | back to summary |
|---|---|
| public int size() Implements java. Returns the number of merge-to-managed entity cross-references in this MergeContext
| |
| values | back to summary |
|---|---|
| public Collection Implements java. Returns an unmodifiable Set view of managed entities contained in this MergeContext.
| |