类 MergeContext
- java.lang.Object
-
- org.hibernate.event.internal.MergeContext
-
- 所有已实现的接口:
Map
public class MergeContext extends Object implements Map
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 viaSession.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. Ifput(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,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.- Methods that return collections (e.g.,
keySet(),values(),entrySet()) return an unmodifiable view of the collection; - If
managedEntityorput(Object mergeEntity, Object managedEntity, boolean isOperatedOn)is executed and this MergeMap already contains a cross-reference formergeEntity, thenmanagedEntitymust be the same as what is already associated withmergeEntityin this MergeContext. - If
putAll(Map map)is executed, the previous restriction applies to each entry in the Map; - The
remove(Object)operation is not supported; The only way to remove data from a MergeContext is by callingclear(); - the Map returned by
invertMap()will only contain the managed-to-merge entity cross-reference to its "newest" (most recently added) merge entity.
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.
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:setOperatedOn(Object mergeEntity, boolean isOperatedOn)- 作者:
- Gail Badner
-
-
构造器概要
构造器 构造器 说明 MergeContext(EventSource session, EntityCopyObserver entityCopyObserver)
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidclear()Clears the MergeContext.booleancontainsKey(Object mergeEntity)Returns true if this MergeContext contains a cross-reference for the specified merge entity to a managed entity result.booleancontainsValue(Object managedEntity)Returns true if this MergeContext contains a cross-reference from the specified managed entity to a merge entity.SetentrySet()Returns an unmodifiable set view of the merge-to-managed entity cross-references contained in this MergeContext.Objectget(Object mergeEntity)Returns the managed entity associated with the specified merge Entity.MapinvertMap()Returns an unmodifiable map view of the managed-to-merge entity cross-references.booleanisEmpty()Returns true if this MergeContext contains no merge-to-managed entity cross-references.booleanisOperatedOn(Object mergeEntity)Returns true if the listener is performing the merge operation on the specified merge entity.SetkeySet()Returns an unmodifiable set view of the merge entities contained in this MergeContextObjectput(Object mergeEntity, Object managedEntity)Associates the specified merge entity with the specified managed entity result in this MergeContext.Objectput(Object mergeEntity, Object managedEntity, boolean isOperatedOn)Associates the specified merge entity with the specified managed entity in this MergeContext.voidputAll(Map map)Copies all of the mappings from the specified Map to this MergeContext.Objectremove(Object mergeEntity)The remove operation is not supported.voidsetOperatedOn(Object mergeEntity, boolean isOperatedOn)Set flag to indicate if the listener is performing the merge operation on the specified merge entity.intsize()Returns the number of merge-to-managed entity cross-references in this MergeContextCollectionvalues()Returns an unmodifiable Set view of managed entities contained in this MergeContext.-
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
从接口继承的方法 java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
构造器详细资料
-
MergeContext
public MergeContext(EventSource session, EntityCopyObserver entityCopyObserver)
-
-
方法详细资料
-
containsKey
public boolean containsKey(Object mergeEntity)
Returns true if this MergeContext contains a cross-reference for the specified merge entity to a managed entity result.- 指定者:
containsKey在接口中Map- 参数:
mergeEntity- must be non-null- 返回:
- true if this MergeContext contains a cross-reference for the specified merge entity
- 抛出:
NullPointerException- if mergeEntity is null
-
containsValue
public boolean containsValue(Object managedEntity)
Returns true if this MergeContext contains a cross-reference from the specified managed entity to a merge entity.- 指定者:
containsValue在接口中Map- 参数:
managedEntity- must be non-null- 返回:
- true if this MergeContext contains a cross-reference from the specified managed entity to a merge entity
- 抛出:
NullPointerException- if managedEntity is null
-
entrySet
public Set entrySet()
Returns an unmodifiable set view of the merge-to-managed entity cross-references contained in this MergeContext.
-
get
public Object get(Object mergeEntity)
Returns the managed entity associated with the specified merge Entity.- 指定者:
get在接口中Map- 参数:
mergeEntity- the merge entity; must be non-null- 返回:
- the managed entity associated with the specified merge Entity
- 抛出:
NullPointerException- if mergeEntity is null
-
isEmpty
public boolean isEmpty()
Returns true if this MergeContext contains no merge-to-managed entity cross-references.
-
keySet
public Set keySet()
Returns an unmodifiable set view of the merge entities contained in this MergeContext
-
put
public Object put(Object mergeEntity, Object managedEntity)
Associates the specified merge entity with the specified managed entity result in this MergeContext. If this MergeContext already contains a cross-reference formergeEntitywhen this method is called, thenmanagedEntitymust be the same as what is already associated withmergeEntity. This method assumes that the merge process is not yet operating onmergeEntity. Later whenmergeEntityenters the merge process,setOperatedOn(Object, boolean)should be called.- 指定者:
put在接口中Map- 参数:
mergeEntity- the merge entity; must be non-nullmanagedEntity- the managed entity result; must be non-null- 返回:
- previous managed entity associated with specified merge entity, or null if there was no mapping for mergeEntity.
- 抛出:
NullPointerException- if mergeEntity or managedEntity is nullIllegalArgumentException- ifmanagedEntityis not the same as the previous managed entity associated withmerge entityIllegalStateException- if internal cross-references are out of sync,
-
put
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 formergeEntitywhen this method is called, thenmanagedEntitymust be the same as what is already associated withmergeEntity.- 参数:
mergeEntity- the merge entity; must be non-nullmanagedEntity- the managed entity; must be non-nullisOperatedOn- indicates if the merge operation is performed on the mergeEntity.- 返回:
- previous managed entity associated with specified merge entity, or null if there was no mapping for mergeEntity.
- 抛出:
NullPointerException- if mergeEntity or managedEntity is nullIllegalArgumentException- ifmanagedEntityis not the same as the previous managed entity associated withmergeEntityIllegalStateException- if internal cross-references are out of sync,
-
putAll
public void putAll(Map map)
Copies all of the mappings from the specified Map to this MergeContext. The key and value for each entry inmapis subject to the same restrictions asput(Object mergeEntity, Object managedEntity). This method assumes that the merge process is not yet operating on any merge entity- 指定者:
putAll在接口中Map- 参数:
map- keys and values must be non-null- 抛出:
NullPointerException- if any key or value is nullIllegalArgumentException- if a key inmapwas already in this MergeContext but associated value inmapis different from the previous value in this MergeContext.IllegalStateException- if internal cross-references are out of sync,
-
remove
public Object remove(Object mergeEntity)
The remove operation is not supported.- 指定者:
remove在接口中Map- 参数:
mergeEntity- the merge entity.- 抛出:
UnsupportedOperationException- if called.
-
size
public int size()
Returns the number of merge-to-managed entity cross-references in this MergeContext
-
values
public Collection values()
Returns an unmodifiable Set view of managed entities contained in this MergeContext.
-
isOperatedOn
public boolean isOperatedOn(Object mergeEntity)
Returns true if the listener is performing the merge operation on the specified merge entity.- 参数:
mergeEntity- the merge entity; must be non-null- 返回:
- true if the listener is performing the merge operation on the specified merge entity; false, if there is no mapping for mergeEntity.
- 抛出:
NullPointerException- if mergeEntity is null
-
setOperatedOn
public void setOperatedOn(Object mergeEntity, boolean isOperatedOn)
Set flag to indicate if the listener is performing the merge operation on the specified merge entity.- 参数:
mergeEntity- must be non-null and this MergeContext must contain a cross-reference for mergeEntity to a managed entity- 抛出:
NullPointerException- if mergeEntity is nullIllegalStateException- if this MergeContext does not contain a a cross-reference for mergeEntity
-
invertMap
public Map 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.- 返回:
- an unmodifiable map view of the managed-to-merge entity cross-references.
-
-