HHH-5913 - Implement set of event listeners as a service
This commit is contained in:
parent
c28b553f21
commit
42c609cfdd
|
@ -1855,7 +1855,10 @@ public class Configuration implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(ServiceRegistryImplementor serviceRegistry, Configuration configuration, Map<?, ?> configValues) {
|
public void apply(
|
||||||
|
EventListenerRegistry eventListenerRegistry,
|
||||||
|
Configuration configuration, Map<?, ?> configValues, ServiceRegistryImplementor serviceRegistry
|
||||||
|
) {
|
||||||
boolean loadLegacyValidator = ConfigurationHelper.getBoolean( "hibernate.validator.autoregister_listeners", configurationProperties, false );
|
boolean loadLegacyValidator = ConfigurationHelper.getBoolean( "hibernate.validator.autoregister_listeners", configurationProperties, false );
|
||||||
|
|
||||||
Class validateEventListenerClass = null;
|
Class validateEventListenerClass = null;
|
||||||
|
@ -1891,13 +1894,11 @@ public class Configuration implements Serializable {
|
||||||
new EventListenerRegistration() {
|
new EventListenerRegistration() {
|
||||||
@Override
|
@Override
|
||||||
public void apply(
|
public void apply(
|
||||||
ServiceRegistryImplementor serviceRegistry,
|
EventListenerRegistry eventListenerRegistry,
|
||||||
Configuration configuration,
|
Configuration configuration,
|
||||||
Map<?, ?> configValues) {
|
Map<?, ?> configValues,
|
||||||
BeanValidationActivator.activateBeanValidation(
|
ServiceRegistryImplementor serviceRegistry) {
|
||||||
serviceRegistry.getService( EventListenerRegistry.class ),
|
BeanValidationActivator.activateBeanValidation( eventListenerRegistry, getProperties() );
|
||||||
getProperties()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -32,7 +32,6 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.event.EventListeners;
|
|
||||||
import org.hibernate.internal.util.ReflectHelper;
|
import org.hibernate.internal.util.ReflectHelper;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.service.event.spi.EventListenerRegistry;
|
import org.hibernate.service.event.spi.EventListenerRegistry;
|
||||||
|
|
|
@ -26,6 +26,7 @@ package org.hibernate.event;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
|
import org.hibernate.service.event.spi.EventListenerRegistry;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,5 +36,10 @@ import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface EventListenerRegistration {
|
public interface EventListenerRegistration {
|
||||||
public void apply(ServiceRegistryImplementor serviceRegistry, Configuration configuration, Map<?,?> configValues);
|
public void apply(
|
||||||
|
EventListenerRegistry eventListenerRegistry,
|
||||||
|
Configuration configuration,
|
||||||
|
Map<?, ?> configValues,
|
||||||
|
ServiceRegistryImplementor serviceRegistry
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,6 @@ import org.hibernate.event.def.DefaultReplicateEventListener;
|
||||||
import org.hibernate.event.def.DefaultSaveEventListener;
|
import org.hibernate.event.def.DefaultSaveEventListener;
|
||||||
import org.hibernate.event.def.DefaultSaveOrUpdateEventListener;
|
import org.hibernate.event.def.DefaultSaveOrUpdateEventListener;
|
||||||
import org.hibernate.event.def.DefaultUpdateEventListener;
|
import org.hibernate.event.def.DefaultUpdateEventListener;
|
||||||
import org.hibernate.service.StandardServiceInitiators;
|
|
||||||
import org.hibernate.service.event.spi.DuplicationStrategy;
|
import org.hibernate.service.event.spi.DuplicationStrategy;
|
||||||
import org.hibernate.service.event.spi.EventListenerRegistrationException;
|
import org.hibernate.service.event.spi.EventListenerRegistrationException;
|
||||||
import org.hibernate.service.event.spi.EventListenerRegistry;
|
import org.hibernate.service.event.spi.EventListenerRegistry;
|
||||||
|
@ -432,9 +431,11 @@ public class EventListenerRegistryImpl implements EventListenerRegistry {
|
||||||
ServiceRegistryImplementor serviceRegistry) {
|
ServiceRegistryImplementor serviceRegistry) {
|
||||||
final EventListenerRegistryImpl registry = new EventListenerRegistryImpl();
|
final EventListenerRegistryImpl registry = new EventListenerRegistryImpl();
|
||||||
|
|
||||||
final EventListenerRegistrationService registrationService = serviceRegistry.getService( EventListenerRegistrationService.class );
|
final EventListenerRegistrationService registrationService = serviceRegistry.getService(
|
||||||
|
EventListenerRegistrationService.class
|
||||||
|
);
|
||||||
for ( EventListenerRegistration registration : registrationService.getEventListenerRegistrations() ) {
|
for ( EventListenerRegistration registration : registrationService.getEventListenerRegistrations() ) {
|
||||||
registration.apply( serviceRegistry, configuration, null );
|
registration.apply( registry, configuration, null, serviceRegistry );
|
||||||
}
|
}
|
||||||
|
|
||||||
return registry;
|
return registry;
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class EventListenerServiceInitiator implements SessionFactoryServiceIniti
|
||||||
SessionFactoryImplementor sessionFactory,
|
SessionFactoryImplementor sessionFactory,
|
||||||
Configuration configuration,
|
Configuration configuration,
|
||||||
ServiceRegistryImplementor registry) {
|
ServiceRegistryImplementor registry) {
|
||||||
return new EventListenerRegistryImpl();
|
return EventListenerRegistryImpl.buildEventListenerRegistry( sessionFactory, configuration, registry );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -72,9 +72,10 @@ public class CallbackTest extends BaseCoreFunctionalTestCase {
|
||||||
new EventListenerRegistration() {
|
new EventListenerRegistration() {
|
||||||
@Override
|
@Override
|
||||||
public void apply(
|
public void apply(
|
||||||
ServiceRegistryImplementor serviceRegistry,
|
EventListenerRegistry eventListenerRegistry,
|
||||||
Configuration configuration,
|
Configuration configuration,
|
||||||
Map<?, ?> configValues) {
|
Map<?, ?> configValues, ServiceRegistryImplementor serviceRegistry
|
||||||
|
) {
|
||||||
serviceRegistry.getService( EventListenerRegistry.class ).setListeners( EventType.DELETE, listener );
|
serviceRegistry.getService( EventListenerRegistry.class ).setListeners( EventType.DELETE, listener );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,10 +75,10 @@ public abstract class AbstractJPATest extends BaseCoreFunctionalTestCase {
|
||||||
new EventListenerRegistration() {
|
new EventListenerRegistration() {
|
||||||
@Override
|
@Override
|
||||||
public void apply(
|
public void apply(
|
||||||
ServiceRegistryImplementor serviceRegistry,
|
EventListenerRegistry eventListenerRegistry,
|
||||||
Configuration configuration,
|
Configuration configuration,
|
||||||
Map<?, ?> configValues) {
|
Map<?, ?> configValues,
|
||||||
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
|
ServiceRegistryImplementor serviceRegistry) {
|
||||||
eventListenerRegistry.setListeners( EventType.PERSIST, buildPersistEventListeners() );
|
eventListenerRegistry.setListeners( EventType.PERSIST, buildPersistEventListeners() );
|
||||||
eventListenerRegistry.setListeners( EventType.PERSIST_ONFLUSH, buildPersisOnFlushEventListeners() );
|
eventListenerRegistry.setListeners( EventType.PERSIST_ONFLUSH, buildPersisOnFlushEventListeners() );
|
||||||
eventListenerRegistry.setListeners( EventType.AUTO_FLUSH, buildAutoFlushEventListeners() );
|
eventListenerRegistry.setListeners( EventType.AUTO_FLUSH, buildAutoFlushEventListeners() );
|
||||||
|
|
|
@ -70,10 +70,10 @@ public class EagerKeyManyToOneTest extends BaseCoreFunctionalTestCase {
|
||||||
new EventListenerRegistration() {
|
new EventListenerRegistration() {
|
||||||
@Override
|
@Override
|
||||||
public void apply(
|
public void apply(
|
||||||
ServiceRegistryImplementor serviceRegistry,
|
EventListenerRegistry eventListenerRegistry,
|
||||||
Configuration configuration,
|
Configuration configuration,
|
||||||
Map<?, ?> configValues) {
|
Map<?, ?> configValues,
|
||||||
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
|
ServiceRegistryImplementor serviceRegistry) {
|
||||||
eventListenerRegistry.prependListeners( EventType.LOAD, new CustomLoadListener() );
|
eventListenerRegistry.prependListeners( EventType.LOAD, new CustomLoadListener() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Mappings;
|
|
||||||
import org.hibernate.ejb.AvailableSettings;
|
import org.hibernate.ejb.AvailableSettings;
|
||||||
import org.hibernate.event.EventListenerRegistration;
|
import org.hibernate.event.EventListenerRegistration;
|
||||||
import org.hibernate.event.EventType;
|
import org.hibernate.event.EventType;
|
||||||
|
@ -82,7 +81,10 @@ public class JpaEventListenerRegistration implements EventListenerRegistration {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
public void apply(ServiceRegistryImplementor serviceRegistry, Configuration configuration, Map<?, ?> configValues) {
|
public void apply(
|
||||||
|
EventListenerRegistry eventListenerRegistry,
|
||||||
|
Configuration configuration, Map<?, ?> configValues, ServiceRegistryImplementor serviceRegistry
|
||||||
|
) {
|
||||||
boolean isSecurityEnabled = configValues.containsKey( AvailableSettings.JACC_ENABLED );
|
boolean isSecurityEnabled = configValues.containsKey( AvailableSettings.JACC_ENABLED );
|
||||||
|
|
||||||
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
|
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
|
||||||
|
|
|
@ -26,7 +26,6 @@ package org.hibernate.envers.event;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Mappings;
|
|
||||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||||
import org.hibernate.event.EventListenerRegistration;
|
import org.hibernate.event.EventListenerRegistration;
|
||||||
import org.hibernate.event.EventType;
|
import org.hibernate.event.EventType;
|
||||||
|
@ -40,7 +39,10 @@ import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
*/
|
*/
|
||||||
public class EnversEventListenerRegistration implements EventListenerRegistration {
|
public class EnversEventListenerRegistration implements EventListenerRegistration {
|
||||||
@Override
|
@Override
|
||||||
public void apply(ServiceRegistryImplementor serviceRegistry, Configuration configuration, Map<?, ?> configValues) {
|
public void apply(
|
||||||
|
EventListenerRegistry eventListenerRegistry,
|
||||||
|
Configuration configuration, Map<?, ?> configValues, ServiceRegistryImplementor serviceRegistry
|
||||||
|
) {
|
||||||
EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
|
EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
|
||||||
listenerRegistry.addDuplicationStrategy( EnversListenerDuplicationStrategy.INSTANCE );
|
listenerRegistry.addDuplicationStrategy( EnversListenerDuplicationStrategy.INSTANCE );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue