Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008-2014, Red Hat Inc. 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 Inc.
*
* 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.internal;
import java.util.Collection;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
import org.jboss.logging.Logger;
import org.hibernate.event.spi.EntityCopyObserver;
import org.hibernate.event.spi.EventSource;
import org.hibernate.pretty.MessageHelper;
/**
* 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 {@link 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 {@link #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,
* {@link 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.
*
*
Methods that return collections (e.g., {@link #keySet()},
* {@link #values()}, {@link #entrySet()}) return an
* unnmodifiable view of the collection;
*
If {@link #put(Object mergeEntity, Object) managedEntity} or
* {@link #put(Object mergeEntity, Object managedEntity, boolean isOperatedOn)}
* is executed and this MergeMap already contains a cross-reference for
* mergeEntity, then managedEntity must be the
* same as what is already associated with mergeEntity in this
* MergeContext.
*
*
If {@link #putAll(Map map)} is executed, the previous restriction
* applies to each entry in the Map;
*
The {@link #remove(Object)} operation is not supported;
* The only way to remove data from a MergeContext is by calling
* {@link #clear()};
*
the Map returned by {@link #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.
* {@link 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:
* {@link MergeContext#setOperatedOn(Object mergeEntity, boolean isOperatedOn)
*
* @author Gail Badner
*/
class MergeContext implements Map {
private static final Logger LOG = Logger.getLogger( MergeContext.class );
private final EventSource session;
private final EntityCopyObserver entityCopyObserver;
private Map