HHH-5913 - Implement set of event listeners as a service

This commit is contained in:
Steve Ebersole 2011-03-26 21:31:53 -05:00
parent 5adf2960c2
commit e8ebe8e396
14 changed files with 278 additions and 93 deletions

View File

@ -23,6 +23,9 @@
*/
package org.hibernate.cfg;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.MapsId;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@ -32,9 +35,7 @@ import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.io.StringReader;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
@ -55,13 +56,15 @@ import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.MapsId;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.jboss.logging.Logger;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.hibernate.AnnotationException;
import org.hibernate.DuplicateMappingException;
import org.hibernate.EmptyInterceptor;
@ -89,36 +92,10 @@ import org.hibernate.engine.Mapping;
import org.hibernate.engine.NamedQueryDefinition;
import org.hibernate.engine.NamedSQLQueryDefinition;
import org.hibernate.engine.ResultSetMappingDefinition;
import org.hibernate.event.AutoFlushEventListener;
import org.hibernate.event.DeleteEventListener;
import org.hibernate.event.DirtyCheckEventListener;
import org.hibernate.event.EventListeners;
import org.hibernate.event.EventListenerRegistration;
import org.hibernate.event.EventType;
import org.hibernate.event.EvictEventListener;
import org.hibernate.event.FlushEntityEventListener;
import org.hibernate.event.FlushEventListener;
import org.hibernate.event.InitializeCollectionEventListener;
import org.hibernate.event.LoadEventListener;
import org.hibernate.event.LockEventListener;
import org.hibernate.event.MergeEventListener;
import org.hibernate.event.PersistEventListener;
import org.hibernate.event.PostCollectionRecreateEventListener;
import org.hibernate.event.PostCollectionRemoveEventListener;
import org.hibernate.event.PostCollectionUpdateEventListener;
import org.hibernate.event.PostDeleteEventListener;
import org.hibernate.event.PostInsertEventListener;
import org.hibernate.event.PostLoadEventListener;
import org.hibernate.event.PostUpdateEventListener;
import org.hibernate.event.PreCollectionRecreateEventListener;
import org.hibernate.event.PreCollectionRemoveEventListener;
import org.hibernate.event.PreCollectionUpdateEventListener;
import org.hibernate.event.PreDeleteEventListener;
import org.hibernate.event.PreInsertEventListener;
import org.hibernate.event.PreLoadEventListener;
import org.hibernate.event.PreUpdateEventListener;
import org.hibernate.event.RefreshEventListener;
import org.hibernate.event.ReplicateEventListener;
import org.hibernate.event.SaveOrUpdateEventListener;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.IdentifierGeneratorAggregator;
import org.hibernate.id.PersistentIdentifierGenerator;
@ -160,15 +137,12 @@ import org.hibernate.mapping.TypeDef;
import org.hibernate.mapping.UniqueKey;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.secure.JACCConfiguration;
<<<<<<< HEAD
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
=======
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistry;
>>>>>>> HHH-5913 - Implement set of event listeners as a service
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.tool.hbm2ddl.DatabaseMetadata;
import org.hibernate.tool.hbm2ddl.IndexMetadata;
import org.hibernate.tool.hbm2ddl.TableMetadata;
@ -179,9 +153,6 @@ import org.hibernate.type.Type;
import org.hibernate.type.TypeResolver;
import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.UserType;
import org.jboss.logging.Logger;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
/**
* An instance of <tt>Configuration</tt> allows the application
@ -1872,39 +1843,63 @@ public class Configuration implements Serializable {
private static final String LEGACY_VALIDATOR_EVENT_LISTENER = "org.hibernate.validator.event.ValidateEventListener";
private void enableLegacyHibernateValidator(ServiceRegistry serviceRegistry) {
boolean loadLegacyValidator = ConfigurationHelper.getBoolean( "hibernate.validator.autoregister_listeners", properties, false );
serviceRegistry.getService( StandardServiceInitiators.EventListenerRegistrationService.class )
.attachEventListenerRegistration( new LegacyHibernateValidatorEventListenerRegistration( properties ) );
}
Class validateEventListenerClass = null;
try {
validateEventListenerClass = serviceRegistry.getService( ClassLoaderService.class ).classForName( LEGACY_VALIDATOR_EVENT_LISTENER );
}
catch ( Exception ignored) {
public static class LegacyHibernateValidatorEventListenerRegistration implements EventListenerRegistration {
private final Properties configurationProperties;
public LegacyHibernateValidatorEventListenerRegistration(Properties configurationProperties) {
this.configurationProperties = configurationProperties;
}
if ( ! loadLegacyValidator || validateEventListenerClass == null) {
LOG.debugf( "Skipping legacy validator loading" );
return;
}
@Override
public void apply(ServiceRegistryImplementor serviceRegistry, Configuration configuration, Map<?, ?> configValues) {
boolean loadLegacyValidator = ConfigurationHelper.getBoolean( "hibernate.validator.autoregister_listeners", configurationProperties, false );
final Object validateEventListener;
try {
validateEventListener = validateEventListenerClass.newInstance();
}
catch ( Exception e ) {
throw new AnnotationException( "Unable to load Validator event listener", e );
}
Class validateEventListenerClass = null;
try {
validateEventListenerClass = serviceRegistry.getService( ClassLoaderService.class ).classForName( LEGACY_VALIDATOR_EVENT_LISTENER );
}
catch ( Exception ignored) {
}
EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
// todo : duplication strategy
if ( ! loadLegacyValidator || validateEventListenerClass == null) {
LOG.debugf( "Skipping legacy validator loading" );
return;
}
listenerRegistry.appendListeners( EventType.PRE_INSERT, (PreInsertEventListener) validateEventListener );
listenerRegistry.appendListeners( EventType.PRE_UPDATE, (PreUpdateEventListener) validateEventListener );
final Object validateEventListener;
try {
validateEventListener = validateEventListenerClass.newInstance();
}
catch ( Exception e ) {
throw new AnnotationException( "Unable to load Validator event listener", e );
}
EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
// todo : duplication strategy
listenerRegistry.appendListeners( EventType.PRE_INSERT, (PreInsertEventListener) validateEventListener );
listenerRegistry.appendListeners( EventType.PRE_UPDATE, (PreUpdateEventListener) validateEventListener );
}
}
private void enableBeanValidation(ServiceRegistry serviceRegistry) {
BeanValidationActivator.activateBeanValidation(
serviceRegistry.getService( EventListenerRegistry.class ),
getProperties()
serviceRegistry.getService( StandardServiceInitiators.EventListenerRegistrationService.class ).attachEventListenerRegistration(
new EventListenerRegistration() {
@Override
public void apply(
ServiceRegistryImplementor serviceRegistry,
Configuration configuration,
Map<?, ?> configValues) {
BeanValidationActivator.activateBeanValidation(
serviceRegistry.getService( EventListenerRegistry.class ),
getProperties()
);
}
}
);
}

View File

@ -25,8 +25,8 @@ package org.hibernate.event;
import java.util.Map;
import org.hibernate.cfg.Mappings;
import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.spi.ServiceRegistryImplementor;
/**
* Contract for performing event listener registration. This is completely a work in progress for now. The
@ -35,5 +35,5 @@ import org.hibernate.service.spi.ServiceRegistry;
* @author Steve Ebersole
*/
public interface EventListenerRegistration {
public void apply(ServiceRegistry serviceRegistry, Mappings mappings, Map<?,?> configValues);
public void apply(ServiceRegistryImplementor serviceRegistry, Configuration configuration, Map<?,?> configValues);
}

View File

@ -26,6 +26,7 @@ package org.hibernate.service;
import org.hibernate.engine.jdbc.batch.internal.BatchBuilderInitiator;
import org.hibernate.engine.jdbc.internal.JdbcServicesInitiator;
import org.hibernate.engine.transaction.internal.TransactionFactoryInitiator;
import org.hibernate.event.EventListenerRegistration;
import org.hibernate.persister.internal.PersisterClassResolverInitiator;
import org.hibernate.persister.internal.PersisterFactoryInitiator;
import org.hibernate.service.classloading.internal.ClassLoaderServiceInitiator;
@ -39,9 +40,11 @@ import org.hibernate.service.jmx.internal.JmxServiceInitiator;
import org.hibernate.service.jndi.internal.JndiServiceInitiator;
import org.hibernate.service.jta.platform.internal.JtaPlatformInitiator;
import org.hibernate.service.spi.BasicServiceInitiator;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author Steve Ebersole
@ -71,6 +74,49 @@ public class StandardServiceInitiators {
serviceInitiators.add( SessionFactoryServiceRegistryFactoryInitiator.INSTANCE );
serviceInitiators.add( EventListenerRegistrationServiceInitiator.INSTANCE );
return serviceInitiators;
}
// todo : completely temporary. See HHH-5562 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Acts as a service in the basic registry to which users/integrators can attach things that perform event listener
* registration. The event listeners live in the SessionFactory registry, but it has access to the basic registry.
* So when it starts up, it looks in the basic registry for this service and does the requested registrations.
*/
public static interface EventListenerRegistrationService extends Service {
public void attachEventListenerRegistration(EventListenerRegistration registration);
public Iterable<EventListenerRegistration> getEventListenerRegistrations();
}
public static class EventListenerRegistrationServiceImpl implements EventListenerRegistrationService {
private List<EventListenerRegistration> registrations = new ArrayList<EventListenerRegistration>();
@Override
public void attachEventListenerRegistration(EventListenerRegistration registration) {
registrations.add( registration );
}
@Override
public Iterable<EventListenerRegistration> getEventListenerRegistrations() {
return registrations;
}
}
public static class EventListenerRegistrationServiceInitiator implements BasicServiceInitiator<EventListenerRegistrationService> {
public static final EventListenerRegistrationServiceInitiator INSTANCE = new EventListenerRegistrationServiceInitiator();
@Override
public Class<EventListenerRegistrationService> getServiceInitiated() {
return EventListenerRegistrationService.class;
}
@Override
public EventListenerRegistrationService initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
return new EventListenerRegistrationServiceImpl();
}
}
}

View File

@ -0,0 +1,45 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, 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.service;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.service.event.internal.EventListenerServiceInitiator;
import org.hibernate.service.spi.SessionFactoryServiceInitiator;
/**
* @author Steve Ebersole
*/
public class StandardSessionFactoryServiceInitiators {
public static List<SessionFactoryServiceInitiator> LIST = buildStandardServiceInitiatorList();
private static List<SessionFactoryServiceInitiator> buildStandardServiceInitiatorList() {
final List<SessionFactoryServiceInitiator> serviceInitiators = new ArrayList<SessionFactoryServiceInitiator>();
serviceInitiators.add( EventListenerServiceInitiator.INSTANCE );
return serviceInitiators;
}
}

View File

@ -29,6 +29,9 @@ import java.util.HashMap;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.event.EventListenerRegistration;
import org.hibernate.event.EventType;
import org.hibernate.event.def.DefaultAutoFlushEventListener;
import org.hibernate.event.def.DefaultDeleteEventListener;
@ -49,9 +52,12 @@ import org.hibernate.event.def.DefaultReplicateEventListener;
import org.hibernate.event.def.DefaultSaveEventListener;
import org.hibernate.event.def.DefaultSaveOrUpdateEventListener;
import org.hibernate.event.def.DefaultUpdateEventListener;
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.event.spi.DuplicationStrategy;
import org.hibernate.service.event.spi.EventListenerRegistrationException;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.StandardServiceInitiators.EventListenerRegistrationService;
import static org.hibernate.event.EventType.AUTO_FLUSH;
import static org.hibernate.event.EventType.DELETE;
@ -409,7 +415,7 @@ public class EventListenerRegistryImpl implements EventListenerRegistry {
}
private static <T> void prepareListeners(EventType<T> type, Map<EventType,EventListenerGroupImpl> map) {
prepareListeners( type, null, map );
prepareListeners( type, null, map );
}
private static <T> void prepareListeners(EventType<T> type, T defaultListener, Map<EventType,EventListenerGroupImpl> map) {
@ -419,4 +425,19 @@ public class EventListenerRegistryImpl implements EventListenerRegistry {
}
map.put( type, listeners );
}
public static EventListenerRegistryImpl buildEventListenerRegistry(
SessionFactoryImplementor sessionFactory,
Configuration configuration,
ServiceRegistryImplementor serviceRegistry) {
final EventListenerRegistryImpl registry = new EventListenerRegistryImpl();
final EventListenerRegistrationService registrationService = serviceRegistry.getService( EventListenerRegistrationService.class );
for ( EventListenerRegistration registration : registrationService.getEventListenerRegistrations() ) {
registration.apply( serviceRegistry, configuration, null );
}
return registry;
}
}

View File

@ -23,18 +23,18 @@
*/
package org.hibernate.service.event.internal;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.service.spi.ServiceInitiator;
import org.hibernate.service.spi.ServiceRegistry;
import java.util.Map;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceInitiator;
/**
* Service initiator for {@link EventListenerRegistry}
*
* @author Steve Ebersole
*/
public class EventListenerServiceInitiator implements ServiceInitiator<EventListenerRegistry> {
public class EventListenerServiceInitiator implements SessionFactoryServiceInitiator<EventListenerRegistry> {
public static final EventListenerServiceInitiator INSTANCE = new EventListenerServiceInitiator();
@Override
@ -43,7 +43,11 @@ public class EventListenerServiceInitiator implements ServiceInitiator<EventList
}
@Override
public EventListenerRegistry initiateService(Map configurationValues, ServiceRegistry registry) {
public EventListenerRegistry initiateService(
SessionFactoryImplementor sessionFactory,
Configuration configuration,
ServiceRegistryImplementor registry) {
return new EventListenerRegistryImpl();
}
}

View File

@ -26,7 +26,7 @@ package org.hibernate.service.event.spi;
import java.io.Serializable;
import org.hibernate.event.EventType;
import org.hibernate.service.spi.Service;
import org.hibernate.service.Service;
/**
* Service for accessing each {@link EventListenerGroup} by {@link EventType}, as well as convenience
@ -35,7 +35,6 @@ import org.hibernate.service.spi.Service;
* @author Steve Ebersole
*/
public interface EventListenerRegistry extends Service, Serializable {
// todo : rename this to getEventListenerGroup
public <T> EventListenerGroup<T> getEventListenerGroup(EventType<T> eventType);
public void addDuplicationStrategy(DuplicationStrategy strategy);

View File

@ -0,0 +1,54 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, 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.service.spi;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.service.Service;
/**
* @author Steve Ebersole
*/
public interface SessionFactoryServiceInitiator<R extends Service> {
/**
* Obtains the service role initiated by this initiator. Should be unique within a registry
*
* @return The service role.
*/
public Class<R> getServiceInitiated();
/**
* Initiates the managed service.
* <p/>
* Note for implementors: signature is guaranteed to change once redesign of SessionFactory building is complete
*
* @param sessionFactory The session factory. Note the the session factory is still in flux; care needs to be taken
* in regards to what you call.
* @param configuration The configuration.
* @param registry The service registry. Can be used to locate services needed to fulfill initiation.
*
* @return The initiated service.
*/
public R initiateService(SessionFactoryImplementor sessionFactory, Configuration configuration, ServiceRegistryImplementor registry);
}

View File

@ -34,7 +34,8 @@ import org.hibernate.event.Destructible;
import org.hibernate.event.EventType;
import org.hibernate.event.Initializable;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.junit.Test;
@ -62,7 +63,7 @@ public class CallbackTest extends BaseCoreFunctionalTestCase {
}
@Override
protected void applyServices(ServiceRegistryImpl serviceRegistry) {
protected void applyServices(BasicServiceRegistryImpl serviceRegistry) {
super.applyServices( serviceRegistry );
serviceRegistry.getService( EventListenerRegistry.class ).setListeners( EventType.DELETE, listener );
}

View File

@ -41,7 +41,7 @@ import org.hibernate.event.def.DefaultPersistEventListener;
import org.hibernate.internal.util.collections.IdentityMap;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -65,7 +65,7 @@ public abstract class AbstractJPATest extends BaseCoreFunctionalTestCase {
}
@Override
protected void applyServices(ServiceRegistryImpl serviceRegistry) {
protected void applyServices(BasicServiceRegistryImpl serviceRegistry) {
super.applyServices( serviceRegistry );
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );

View File

@ -23,16 +23,21 @@
*/
package org.hibernate.test.keymanytoone.bidir.component;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.event.EventListenerRegistration;
import org.hibernate.event.EventType;
import org.hibernate.event.LoadEvent;
import org.hibernate.event.LoadEventListener;
import org.hibernate.event.def.DefaultLoadEventListener;
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.service.internal.ServiceRegistryImpl;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.junit.Test;
@ -57,11 +62,22 @@ public class EagerKeyManyToOneTest extends BaseCoreFunctionalTestCase {
}
@Override
protected void applyServices(ServiceRegistryImpl serviceRegistry) {
protected void applyServices(BasicServiceRegistryImpl serviceRegistry) {
super.applyServices( serviceRegistry );
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
eventListenerRegistry.prependListeners( EventType.LOAD, new CustomLoadListener() );
// (they are different service registries!)
serviceRegistry.getService( StandardServiceInitiators.EventListenerRegistrationService.class ).attachEventListenerRegistration(
new EventListenerRegistration() {
@Override
public void apply(
ServiceRegistryImplementor serviceRegistry,
Configuration configuration,
Map<?, ?> configValues) {
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
eventListenerRegistry.prependListeners( EventType.LOAD, new CustomLoadListener() );
}
}
);
}
@Test

View File

@ -99,6 +99,7 @@ import org.hibernate.mapping.PersistentClass;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.secure.JACCConfiguration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl;
@ -882,7 +883,8 @@ public class Ejb3Configuration implements Serializable, Referenceable {
configure( (Properties)null, null );
NamingHelper.bind(this);
// todo : temporary -> HHH-5562
new JpaEventListenerRegistration().apply( serviceRegistry, cfg.createMappings(), cfg.getProperties() );
serviceRegistry.getService( StandardServiceInitiators.EventListenerRegistrationService.class )
.attachEventListenerRegistration( new JpaEventListenerRegistration() );
return new EntityManagerFactoryImpl(
transactionType,
discardOnClose,

View File

@ -29,6 +29,7 @@ import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Mappings;
import org.hibernate.ejb.AvailableSettings;
import org.hibernate.event.EventListenerRegistration;
@ -43,7 +44,7 @@ import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.event.spi.DuplicationStrategy;
import org.hibernate.service.event.spi.EventListenerGroup;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.service.spi.ServiceRegistryImplementor;
/**
* Prepare the HEM-specific event listeners.
@ -81,7 +82,7 @@ public class JpaEventListenerRegistration implements EventListenerRegistration {
@Override
@SuppressWarnings( {"unchecked"})
public void apply(ServiceRegistry serviceRegistry, Mappings mappings, Map<?,?> configValues) {
public void apply(ServiceRegistryImplementor serviceRegistry, Configuration configuration, Map<?, ?> configValues) {
boolean isSecurityEnabled = configValues.containsKey( AvailableSettings.JACC_ENABLED );
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
@ -133,8 +134,8 @@ public class JpaEventListenerRegistration implements EventListenerRegistration {
// todo : we may need to account for callback handlers previously set (shared across EMFs)
final EntityCallbackHandler callbackHandler = new EntityCallbackHandler();
Iterator classes = mappings.iterateClasses();
ReflectionManager reflectionManager = mappings.getReflectionManager();
Iterator classes = configuration.getClassMappings();
ReflectionManager reflectionManager = configuration.getReflectionManager();
while ( classes.hasNext() ) {
PersistentClass clazz = (PersistentClass) classes.next();
if ( clazz.getClassName() == null ) {
@ -159,7 +160,7 @@ public class JpaEventListenerRegistration implements EventListenerRegistration {
}
}
private Object instantiate(String listenerImpl, ServiceRegistry serviceRegistry) {
private Object instantiate(String listenerImpl, ServiceRegistryImplementor serviceRegistry) {
try {
return serviceRegistry.getService( ClassLoaderService.class ).classForName( listenerImpl ).newInstance();
}

View File

@ -25,12 +25,13 @@ package org.hibernate.envers.event;
import java.util.Map;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Mappings;
import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.event.EventListenerRegistration;
import org.hibernate.event.EventType;
import org.hibernate.service.event.spi.EventListenerRegistry;
import org.hibernate.service.spi.ServiceRegistry;
import org.hibernate.service.spi.ServiceRegistryImplementor;
/**
* See "transitory" notes on {@link EventListenerRegistration}
@ -39,7 +40,7 @@ import org.hibernate.service.spi.ServiceRegistry;
*/
public class EnversEventListenerRegistration implements EventListenerRegistration {
@Override
public void apply(ServiceRegistry serviceRegistry, Mappings mappings, Map<?, ?> configValues) {
public void apply(ServiceRegistryImplementor serviceRegistry, Configuration configuration, Map<?, ?> configValues) {
EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
listenerRegistry.addDuplicationStrategy( EnversListenerDuplicationStrategy.INSTANCE );