HHH-9106 : Merging multiple representations of the same entity

This commit is contained in:
Gail Badner 2014-06-13 19:18:45 -07:00
parent 7791a7048a
commit 7d4ca57c8b
8 changed files with 23 additions and 26 deletions

View File

@ -28,8 +28,9 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import org.jboss.logging.Logger;
import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.EventSource;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.collections.IdentitySet; import org.hibernate.internal.util.collections.IdentitySet;
import org.hibernate.pretty.MessageHelper; import org.hibernate.pretty.MessageHelper;
@ -42,7 +43,9 @@ import org.hibernate.pretty.MessageHelper;
* @author Gail Badner * @author Gail Badner
*/ */
public class EntityCopyAllowedLoggedObserver extends EntityCopyAllowedObserver { public class EntityCopyAllowedLoggedObserver extends EntityCopyAllowedObserver {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( EntityCopyAllowedLoggedObserver.class ); private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class, EntityCopyAllowedLoggedObserver.class.getName()
);
// Tracks the number of entity copies per entity name. // Tracks the number of entity copies per entity name.
private Map<String, Integer> countsByEntityName; private Map<String, Integer> countsByEntityName;

View File

@ -23,15 +23,7 @@
*/ */
package org.hibernate.event.internal; package org.hibernate.event.internal;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.EventSource;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.collections.IdentitySet;
import org.hibernate.pretty.MessageHelper;
/** /**
* An {@link EntityCopyObserver} implementation that allows multiple representations of * An {@link EntityCopyObserver} implementation that allows multiple representations of

View File

@ -21,19 +21,19 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.jpa.event.internal.core; package org.hibernate.ejb.event;
import org.hibernate.event.internal.EntityCopyAllowedLoggedObserver; import org.hibernate.event.internal.EntityCopyAllowedLoggedObserver;
import org.hibernate.event.internal.EntityCopyAllowedObserver; import org.hibernate.event.internal.EntityCopyAllowedObserver;
import org.hibernate.event.internal.EntityCopyObserver; import org.hibernate.event.internal.EntityCopyObserver;
/** /**
* Overrides {@link JpaMergeEventListener} that allows merging multiple representations * Overrides {@link EJB3MergeEventListener} that allows merging multiple representations
* of the same persistent entity. * of the same persistent entity.
* *
* @author Gail Badner * @author Gail Badner
*/ */
public class JpaEntityCopyAllowedMergeEventListener extends JpaMergeEventListener { public class EJB3EntityCopyAllowedMergeEventListener extends EJB3MergeEventListener {
@Override @Override
protected EntityCopyObserver createEntityCopyObserver() { protected EntityCopyObserver createEntityCopyObserver() {

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.jpa.test.emops; package org.hibernate.ejb.test.emops;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Entity; import javax.persistence.Entity;

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.jpa.test.emops; package org.hibernate.ejb.test.emops;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.jpa.test.emops; package org.hibernate.ejb.test.emops;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Entity; import javax.persistence.Entity;

View File

@ -21,18 +21,20 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.jpa.test.emops; package org.hibernate.ejb.test.emops;
import java.util.List; import java.util.List;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.junit.Test; import org.junit.Test;
import org.hibernate.SessionFactory;
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.hibernate.ejb.event.EJB3EntityCopyAllowedMergeEventListener;
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.event.spi.EventType; import org.hibernate.event.spi.EventType;
import org.hibernate.jpa.event.internal.core.JpaEntityCopyAllowedMergeEventListener;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@ -42,7 +44,7 @@ import static org.junit.Assert.assertSame;
/** /**
* Tests merging multiple detached representations of the same entity using * Tests merging multiple detached representations of the same entity using
* {@link org.hibernate.jpa.event.internal.core.JpaEntityCopyAllowedMergeEventListener}. * {@link org.hibernate.ejb.event.EJB3EntityCopyAllowedMergeEventListener}.
* *
* @author Gail Badner * @author Gail Badner
*/ */
@ -52,10 +54,10 @@ public class MergeMultipleEntityRepresentationsAllowedTest extends BaseEntityMan
@Override @Override
protected void afterEntityManagerFactoryBuilt() { protected void afterEntityManagerFactoryBuilt() {
super.afterEntityManagerFactoryBuilt(); super.afterEntityManagerFactoryBuilt();
SessionFactory sf = ( (HibernateEntityManagerFactory) entityManagerFactory() ).getSessionFactory();
SessionFactoryImplementor sfi = entityManagerFactory().unwrap( SessionFactoryImplementor.class ); EventListenerRegistry registry =
EventListenerRegistry registry = sfi.getServiceRegistry().getService( EventListenerRegistry.class ); ( (SessionFactoryImplementor) sf ).getServiceRegistry().getService( EventListenerRegistry.class );
registry.setListeners( EventType.MERGE, new JpaEntityCopyAllowedMergeEventListener() ); registry.setListeners( EventType.MERGE, new EJB3EntityCopyAllowedMergeEventListener() );
} }
@Test @Test

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.jpa.test.emops; package org.hibernate.ejb.test.emops;
import java.util.List; import java.util.List;
@ -29,7 +29,7 @@ import javax.persistence.EntityManager;
import org.junit.Test; import org.junit.Test;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import static junit.framework.TestCase.fail; import static junit.framework.TestCase.fail;