diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java index 49a059e61628..5e89c54ff454 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java @@ -151,8 +151,6 @@ import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; -import org.hibernate.jpa.event.internal.CallbackDefinitionResolverLegacyImpl; -import org.hibernate.jpa.event.spi.CallbackType; import org.hibernate.loader.PropertyPath; import org.hibernate.mapping.Any; import org.hibernate.mapping.Component; @@ -825,8 +823,6 @@ else if ( InheritanceType.SINGLE_TABLE.equals( inheritanceState.getType() ) ) { entityBinder.processComplementaryTableDefinitions( clazzToProcess.getAnnotation( org.hibernate.annotations.Table.class ) ); entityBinder.processComplementaryTableDefinitions( clazzToProcess.getAnnotation( org.hibernate.annotations.Tables.class ) ); entityBinder.processComplementaryTableDefinitions( tabAnn ); - - bindCallbacks( clazzToProcess, persistentClass, context ); } /** @@ -1410,32 +1406,6 @@ private static void bindTypeDef(TypeDef defAnn, MetadataBuildingContext context) } - private static void bindCallbacks(XClass entityClass, PersistentClass persistentClass, - MetadataBuildingContext context) { - ReflectionManager reflectionManager = context.getBootstrapContext().getReflectionManager(); - - for ( CallbackType callbackType : CallbackType.values() ) { - persistentClass.addCallbackDefinitions( CallbackDefinitionResolverLegacyImpl.resolveEntityCallbacks( - reflectionManager, entityClass, callbackType ) ); - } - - context.getMetadataCollector().addSecondPass( new SecondPass() { - @Override - public void doSecondPass(Map persistentClasses) throws MappingException { - for ( @SuppressWarnings("unchecked") Iterator propertyIterator = persistentClass.getDeclaredPropertyIterator(); - propertyIterator.hasNext(); ) { - Property property = propertyIterator.next(); - if ( property.isComposite() ) { - for ( CallbackType callbackType : CallbackType.values() ) { - property.addCallbackDefinitions( CallbackDefinitionResolverLegacyImpl.resolveEmbeddableCallbacks( - reflectionManager, persistentClass.getMappedClass(), property, callbackType ) ); - } - } - } - } - } ); - } - public static void bindFetchProfilesForClass(XClass clazzToProcess, MetadataBuildingContext context) { bindFetchProfiles( clazzToProcess, context ); } @@ -1480,6 +1450,7 @@ private static void bindFetchProfile(FetchProfile fetchProfileAnnotation, Metada } } + private static void bindDiscriminatorColumnToRootPersistentClass( RootClass rootClass, Ejb3DiscriminatorColumn discriminatorColumn, diff --git a/hibernate-core/src/main/java/org/hibernate/event/spi/EventEngine.java b/hibernate-core/src/main/java/org/hibernate/event/spi/EventEngine.java index 7456828649fa..48bb777680a8 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/spi/EventEngine.java +++ b/hibernate-core/src/main/java/org/hibernate/event/spi/EventEngine.java @@ -9,6 +9,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import java.util.function.Consumer; @@ -22,6 +23,9 @@ import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.jpa.event.internal.CallbackRegistryImplementor; import org.hibernate.jpa.event.internal.CallbacksFactory; +import org.hibernate.jpa.event.spi.CallbackBuilder; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.Property; import org.hibernate.service.spi.Stoppable; /** @@ -35,6 +39,7 @@ public class EventEngine { private final EventListenerRegistry listenerRegistry; private final CallbackRegistryImplementor callbackRegistry; + private final CallbackBuilder callbackBuilder; public EventEngine( MetadataImplementor mappings, @@ -43,8 +48,33 @@ public EventEngine( // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // resolve (JPA) callback handlers - this.callbackRegistry = CallbacksFactory.buildCallbackRegistry( sessionFactory.getSessionFactoryOptions(), - sessionFactory.getServiceRegistry(), mappings.getEntityBindings() ); + this.callbackRegistry = CallbacksFactory.buildCallbackRegistry( sessionFactory.getSessionFactoryOptions() ); + this.callbackBuilder = CallbacksFactory.buildCallbackBuilder( + sessionFactory.getSessionFactoryOptions(), + sessionFactory.getServiceRegistry(), + mappings.getMetadataBuildingOptions().getReflectionManager() + ); + + for ( PersistentClass persistentClass : mappings.getEntityBindings() ) { + if ( persistentClass.getClassName() == null ) { + // we can have dynamic (non-java class) mapping + continue; + } + + this.callbackBuilder.buildCallbacksForEntity( persistentClass.getMappedClass(), callbackRegistry ); + + for ( Iterator propertyIterator = persistentClass.getDeclaredPropertyIterator(); propertyIterator.hasNext(); ) { + final Property property = propertyIterator.next(); + + if ( property.isComposite() ) { + this.callbackBuilder.buildCallbacksForEmbeddable( + property, + persistentClass.getMappedClass(), + callbackRegistry + ); + } + } + } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -162,5 +192,7 @@ public void stop() { } callbackRegistry.release(); + + callbackBuilder.release(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackDefinitionResolverLegacyImpl.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackBuilderLegacyImpl.java similarity index 71% rename from hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackDefinitionResolverLegacyImpl.java rename to hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackBuilderLegacyImpl.java index 9b0b6e0d43b0..d7fac04bc1f6 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackDefinitionResolverLegacyImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackBuilderLegacyImpl.java @@ -19,39 +19,88 @@ import javax.persistence.MappedSuperclass; import javax.persistence.PersistenceException; +import org.hibernate.MappingException; import org.hibernate.annotations.common.reflection.ReflectionManager; import org.hibernate.annotations.common.reflection.XClass; import org.hibernate.annotations.common.reflection.XMethod; import org.hibernate.internal.util.ReflectHelper; -import org.hibernate.jpa.event.spi.CallbackDefinition; +import org.hibernate.jpa.event.spi.Callback; +import org.hibernate.jpa.event.spi.CallbackBuilder; import org.hibernate.jpa.event.spi.CallbackType; -import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.property.access.spi.Getter; +import org.hibernate.resource.beans.spi.ManagedBeanRegistry; import org.jboss.logging.Logger; /** - * Resolves JPA callback definitions using a HCANN ReflectionManager. - *

- * "legacy" in that we want to move to Jandex instead. + * EntityCallbackBuilder implementation using HCANN ReflectionManager. "legacy" in that + * we want to move to Jandex instead. * * @author Steve Ebersole */ -public final class CallbackDefinitionResolverLegacyImpl { - private static final Logger log = Logger.getLogger( CallbackDefinitionResolverLegacyImpl.class ); +final class CallbackBuilderLegacyImpl implements CallbackBuilder { + private static final Logger log = Logger.getLogger( CallbackBuilderLegacyImpl.class ); + + private final ManagedBeanRegistry managedBeanRegistry; + private final ReflectionManager reflectionManager; + + CallbackBuilderLegacyImpl(ManagedBeanRegistry managedBeanRegistry, ReflectionManager reflectionManager) { + this.managedBeanRegistry = managedBeanRegistry; + this.reflectionManager = reflectionManager; + } + + @Override + public void buildCallbacksForEntity(Class entityClass, CallbackRegistrar callbackRegistrar) { + for ( CallbackType callbackType : CallbackType.values() ) { + if ( callbackRegistrar.hasRegisteredCallbacks( entityClass, callbackType ) ) { + // this most likely means we have a class mapped multiple times using the hbm.xml + // "entity name" feature + if ( log.isDebugEnabled() ) { + log.debugf( + "CallbackRegistry reported that Class [%s] already had %s callbacks registered; " + + "assuming this means the class was mapped twice " + + "(using hbm.xml entity-name support) - skipping subsequent registrations", + entityClass.getName(), + callbackType.getCallbackAnnotation().getSimpleName() + ); + } + continue; + } + final Callback[] callbacks = resolveEntityCallbacks( entityClass, callbackType, reflectionManager ); + callbackRegistrar.registerCallbacks( entityClass, callbacks ); + } + } + + @Override + public void buildCallbacksForEmbeddable( + Property embeddableProperty, Class entityClass, CallbackRegistrar callbackRegistrar) { + for ( CallbackType callbackType : CallbackType.values() ) { + final Callback[] callbacks = resolveEmbeddableCallbacks( + entityClass, + embeddableProperty, + callbackType, + reflectionManager + ); + callbackRegistrar.registerCallbacks( entityClass, callbacks ); + } + } + + @Override + public void release() { + // nothing to do + } @SuppressWarnings({"unchecked", "WeakerAccess"}) - public static List resolveEntityCallbacks(ReflectionManager reflectionManager, - XClass entityClass, CallbackType callbackType) { - List callbackDefinitions = new ArrayList<>(); + public Callback[] resolveEntityCallbacks(Class entityClass, CallbackType callbackType, ReflectionManager reflectionManager) { + List callbacks = new ArrayList<>(); List callbacksMethodNames = new ArrayList<>(); List orderedListeners = new ArrayList<>(); - XClass currentClazz = entityClass; + XClass currentClazz = reflectionManager.toXClass( entityClass ); boolean stopListeners = false; boolean stopDefaultListeners = false; do { - CallbackDefinition callbackDefinition = null; + Callback callback = null; List methods = currentClazz.getDeclaredMethods(); for ( final XMethod xMethod : methods ) { if ( xMethod.isAnnotationPresent( callbackType.getCallbackAnnotation() ) ) { @@ -59,8 +108,8 @@ public static List resolveEntityCallbacks(ReflectionManager final String methodName = method.getName(); if ( !callbacksMethodNames.contains( methodName ) ) { //overridden method, remove the superclass overridden method - if ( callbackDefinition == null ) { - callbackDefinition = new EntityCallback.Definition( method, callbackType ); + if ( callback == null ) { + callback = new EntityCallback( method, callbackType ); Class returnType = method.getReturnType(); Class[] args = method.getParameterTypes(); if ( returnType != Void.TYPE || args.length != 0 ) { @@ -78,7 +127,7 @@ public static List resolveEntityCallbacks(ReflectionManager entityClass.getName() ); } - callbackDefinitions.add( 0, callbackDefinition ); //superclass first + callbacks.add( 0, callback ); //superclass first callbacksMethodNames.add( 0, methodName ); } else { @@ -119,7 +168,7 @@ public static List resolveEntityCallbacks(ReflectionManager } for ( Class listener : orderedListeners ) { - CallbackDefinition callbackDefinition = null; + Callback callback = null; if ( listener != null ) { XClass xListener = reflectionManager.toXClass( listener ); callbacksMethodNames = new ArrayList<>(); @@ -130,8 +179,12 @@ public static List resolveEntityCallbacks(ReflectionManager final String methodName = method.getName(); if ( !callbacksMethodNames.contains( methodName ) ) { //overridden method, remove the superclass overridden method - if ( callbackDefinition == null ) { - callbackDefinition = new ListenerCallback.Definition( listener, method, callbackType ); + if ( callback == null ) { + callback = new ListenerCallback( + managedBeanRegistry.getBean( listener ), + method, + callbackType + ); Class returnType = method.getReturnType(); Class[] args = method.getParameterTypes(); @@ -150,7 +203,7 @@ public static List resolveEntityCallbacks(ReflectionManager entityClass.getName() ); } - callbackDefinitions.add( 0, callbackDefinition ); // listeners first + callbacks.add( 0, callback ); // listeners first } else { throw new PersistenceException( @@ -165,20 +218,20 @@ public static List resolveEntityCallbacks(ReflectionManager } } } - return callbackDefinitions; + return callbacks.toArray( new Callback[callbacks.size()] ); } - public static List resolveEmbeddableCallbacks(ReflectionManager reflectionManager, - Class entityClass, Property embeddableProperty, - CallbackType callbackType) { + @SuppressWarnings({"unchecked", "WeakerAccess"}) + public Callback[] resolveEmbeddableCallbacks(Class entityClass, Property embeddableProperty, CallbackType callbackType, ReflectionManager reflectionManager) { + final Class embeddableClass = embeddableProperty.getType().getReturnedClass(); final XClass embeddableXClass = reflectionManager.toXClass( embeddableClass ); final Getter embeddableGetter = embeddableProperty.getGetter( entityClass ); - final List callbackDefinitions = new ArrayList<>(); + final List callbacks = new ArrayList<>(); final List callbacksMethodNames = new ArrayList<>(); XClass currentClazz = embeddableXClass; do { - CallbackDefinition callbackDefinition = null; + Callback callback = null; List methods = currentClazz.getDeclaredMethods(); for ( final XMethod xMethod : methods ) { if ( xMethod.isAnnotationPresent( callbackType.getCallbackAnnotation() ) ) { @@ -186,8 +239,8 @@ public static List resolveEmbeddableCallbacks(ReflectionMana final String methodName = method.getName(); if ( !callbacksMethodNames.contains( methodName ) ) { //overridden method, remove the superclass overridden method - if ( callbackDefinition == null ) { - callbackDefinition = new EmbeddableCallback.Definition( embeddableGetter, method, callbackType ); + if ( callback == null ) { + callback = new EmbeddableCallback( embeddableGetter, method, callbackType ); Class returnType = method.getReturnType(); Class[] args = method.getParameterTypes(); if ( returnType != Void.TYPE || args.length != 0 ) { @@ -205,7 +258,7 @@ public static List resolveEmbeddableCallbacks(ReflectionMana embeddableXClass.getName() ); } - callbackDefinitions.add( 0, callbackDefinition ); //superclass first + callbacks.add( 0, callback ); //superclass first callbacksMethodNames.add( 0, methodName ); } else { @@ -225,7 +278,7 @@ public static List resolveEmbeddableCallbacks(ReflectionMana } while ( currentClazz != null ); - return callbackDefinitions; + return callbacks.toArray( new Callback[callbacks.size()] ); } private static boolean useAnnotationAnnotatedByListener; diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackRegistryImplementor.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackRegistryImplementor.java index 9444bad0941d..6805b73b7e7b 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackRegistryImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackRegistryImplementor.java @@ -7,9 +7,9 @@ package org.hibernate.jpa.event.internal; import org.hibernate.jpa.event.spi.CallbackBuilder; -import org.hibernate.jpa.event.spi.CallbackRegistrar; +import org.hibernate.jpa.event.spi.CallbackRegistry; -public interface CallbackRegistryImplementor extends CallbackRegistrar, CallbackBuilder.CallbackRegistrar { +public interface CallbackRegistryImplementor extends CallbackRegistry, CallbackBuilder.CallbackRegistrar { void release(); diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbacksFactory.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbacksFactory.java index f62753638d61..0561b8edbc04 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbacksFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbacksFactory.java @@ -6,89 +6,42 @@ */ package org.hibernate.jpa.event.internal; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - import org.hibernate.annotations.common.reflection.ReflectionManager; import org.hibernate.boot.spi.SessionFactoryOptions; -import org.hibernate.jpa.event.spi.Callback; -import org.hibernate.jpa.event.spi.CallbackDefinition; -import org.hibernate.jpa.event.spi.CallbackType; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.jpa.event.spi.CallbackBuilder; import org.hibernate.resource.beans.spi.ManagedBeanRegistry; import org.hibernate.service.ServiceRegistry; -import org.jboss.logging.Logger; - /** * The intent of this class is to use a lighter implementation * when JPA callbacks are disabled via * {@link org.hibernate.boot.spi.SessionFactoryOptions#areJPACallbacksEnabled()} */ public final class CallbacksFactory { - private static final Logger log = Logger.getLogger( CallbacksFactory.class ); - - public static CallbackRegistryImplementor buildCallbackRegistry(SessionFactoryOptions options, - ServiceRegistry serviceRegistry, Collection entityBindings) { - if ( !jpaCallBacksEnabled( options ) ) { - return new EmptyCallbackRegistryImpl(); + public static CallbackRegistryImplementor buildCallbackRegistry(SessionFactoryOptions options) { + if ( jpaCallBacksEnabled( options ) ) { + return new CallbackRegistryImpl(); } - ManagedBeanRegistry beanRegistry = serviceRegistry.getService( ManagedBeanRegistry.class ); - CallbackRegistryImplementor registry = new CallbackRegistryImpl(); - Set> entityClasses = new HashSet<>(); - - for ( PersistentClass persistentClass : entityBindings ) { - if ( persistentClass.getClassName() == null ) { - // we can have dynamic (non-java class) mapping - continue; - } - - Class entityClass = persistentClass.getMappedClass(); - - if ( !entityClasses.add( entityClass ) ) { - // this most likely means we have a class mapped multiple times using the hbm.xml - // "entity name" feature - if ( log.isDebugEnabled() ) { - log.debugf( - "Class [%s] already has callbacks registered; " + - "assuming this means the class was mapped twice " + - "(using hbm.xml entity-name support) - skipping subsequent registrations" + - "to avoid duplicates", - entityClass.getName() - ); - } - continue; - } - - registry.registerCallbacks( persistentClass.getMappedClass(), - buildCallbacks( persistentClass.getCallbackDefinitions(), beanRegistry ) ); - - for ( @SuppressWarnings("unchecked") Iterator propertyIterator = persistentClass.getDeclaredPropertyIterator(); - propertyIterator.hasNext(); ) { - final Property property = propertyIterator.next(); - registry.registerCallbacks( persistentClass.getMappedClass(), - buildCallbacks( property.getCallbackDefinitions(), beanRegistry ) ); - } + else { + return new EmptyCallbackRegistryImpl(); } - - return registry; } - private static Callback[] buildCallbacks(List callbackDefinitions, - ManagedBeanRegistry beanRegistry) { - if ( callbackDefinitions == null || callbackDefinitions.isEmpty() ) { - return null; + public static CallbackBuilder buildCallbackBuilder( + SessionFactoryOptions options, + ServiceRegistry serviceRegistry, + ReflectionManager reflectionManager) { + if ( jpaCallBacksEnabled( options ) ) { + final ManagedBeanRegistry managedBeanRegistry = serviceRegistry.getService( ManagedBeanRegistry.class ); + return new CallbackBuilderLegacyImpl( + managedBeanRegistry, + reflectionManager + ); } - List callbacks = new ArrayList<>(); - for ( CallbackDefinition definition : callbackDefinitions ) { - callbacks.add( definition.createCallback( beanRegistry ) ); + else { + return new EmptyCallbackBuilder(); } - return callbacks.toArray( new Callback[0] ); } private static boolean jpaCallBacksEnabled(SessionFactoryOptions options) { diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EmbeddableCallback.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EmbeddableCallback.java index a66cc0d8aa18..e5fc177e0c93 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EmbeddableCallback.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EmbeddableCallback.java @@ -9,11 +9,8 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import org.hibernate.jpa.event.spi.Callback; -import org.hibernate.jpa.event.spi.CallbackDefinition; import org.hibernate.jpa.event.spi.CallbackType; import org.hibernate.property.access.spi.Getter; -import org.hibernate.resource.beans.spi.ManagedBeanRegistry; /** * Represents a JPA callback on the embeddable type @@ -22,27 +19,10 @@ */ final class EmbeddableCallback extends AbstractCallback { - public static class Definition implements CallbackDefinition { - private final Getter embeddableGetter; - private final Method callbackMethod; - private final CallbackType callbackType; - - public Definition(Getter embeddableGetter, Method callbackMethod, CallbackType callbackType) { - this.embeddableGetter = embeddableGetter; - this.callbackMethod = callbackMethod; - this.callbackType = callbackType; - } - - @Override - public Callback createCallback(ManagedBeanRegistry beanRegistry) { - return new EmbeddableCallback( embeddableGetter, callbackMethod, callbackType ); - } - } - private final Getter embeddableGetter; private final Method callbackMethod; - private EmbeddableCallback(Getter embeddableGetter, Method callbackMethod, CallbackType callbackType) { + EmbeddableCallback(Getter embeddableGetter, Method callbackMethod, CallbackType callbackType) { super( callbackType ); this.embeddableGetter = embeddableGetter; this.callbackMethod = callbackMethod; diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EmptyCallbackBuilder.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EmptyCallbackBuilder.java new file mode 100644 index 000000000000..894790f14c76 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EmptyCallbackBuilder.java @@ -0,0 +1,29 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.jpa.event.internal; + +import org.hibernate.jpa.event.spi.CallbackBuilder; +import org.hibernate.mapping.Property; + +final class EmptyCallbackBuilder implements CallbackBuilder { + + @Override + public void buildCallbacksForEntity(Class entityClass, CallbackRegistrar callbackRegistrar) { + //no-op + } + + @Override + public void buildCallbacksForEmbeddable(Property embeddableProperty, Class entityClass, CallbackRegistrar callbackRegistrar) { + //no-op + } + + @Override + public void release() { + //no-op + } + +} diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EntityCallback.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EntityCallback.java index fd23d5459d7e..8bae4ed6a777 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EntityCallback.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EntityCallback.java @@ -9,10 +9,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import org.hibernate.jpa.event.spi.Callback; -import org.hibernate.jpa.event.spi.CallbackDefinition; import org.hibernate.jpa.event.spi.CallbackType; -import org.hibernate.resource.beans.spi.ManagedBeanRegistry; /** * Represents a JPA callback on the entity itself @@ -22,24 +19,9 @@ */ final class EntityCallback extends AbstractCallback { - public static class Definition implements CallbackDefinition { - private final Method callbackMethod; - private final CallbackType callbackType; - - public Definition(Method callbackMethod, CallbackType callbackType) { - this.callbackMethod = callbackMethod; - this.callbackType = callbackType; - } - - @Override - public Callback createCallback(ManagedBeanRegistry beanRegistry) { - return new EntityCallback( callbackMethod, callbackType ); - } - } - private final Method callbackMethod; - private EntityCallback(Method callbackMethod, CallbackType callbackType) { + EntityCallback(Method callbackMethod, CallbackType callbackType) { super( callbackType ); this.callbackMethod = callbackMethod; } diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/ListenerCallback.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/ListenerCallback.java index a8bf663a8a88..e47c47a4d7c2 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/ListenerCallback.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/ListenerCallback.java @@ -9,11 +9,8 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import org.hibernate.jpa.event.spi.Callback; -import org.hibernate.jpa.event.spi.CallbackDefinition; import org.hibernate.jpa.event.spi.CallbackType; import org.hibernate.resource.beans.spi.ManagedBean; -import org.hibernate.resource.beans.spi.ManagedBeanRegistry; /** * Represents a JPA callback using a dedicated listener @@ -23,27 +20,10 @@ */ class ListenerCallback extends AbstractCallback { - public static class Definition implements CallbackDefinition { - private final Class listenerClass; - private final Method callbackMethod; - private final CallbackType callbackType; - - public Definition(Class listenerClass, Method callbackMethod, CallbackType callbackType) { - this.listenerClass = listenerClass; - this.callbackMethod = callbackMethod; - this.callbackType = callbackType; - } - - @Override - public Callback createCallback(ManagedBeanRegistry beanRegistry) { - return new ListenerCallback( beanRegistry.getBean( listenerClass ), callbackMethod, callbackType ); - } - } - private final Method callbackMethod; - private final ManagedBean listenerManagedBean; + private final ManagedBean listenerManagedBean; - ListenerCallback(ManagedBean listenerManagedBean, Method callbackMethod, CallbackType callbackType) { + ListenerCallback(ManagedBean listenerManagedBean, Method callbackMethod, CallbackType callbackType) { super( callbackType ); this.listenerManagedBean = listenerManagedBean; this.callbackMethod = callbackMethod; diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackBuilder.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackBuilder.java index 8db5b61884c4..41bfcda81afb 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackBuilder.java @@ -12,18 +12,20 @@ * Contract for walking an entity hierarchy and building a list of JPA callbacks * * @author Steve Ebersole - * - * @deprecated This SPI has never been functional and is no longer used. It will eventually be removed. */ -@Deprecated public interface CallbackBuilder { /** * Represents the target of JPA callback registrations as part the EntityCallbackBuilder - * - * @deprecated Use {@link org.hibernate.jpa.event.spi.CallbackRegistrar} instead. */ - @Deprecated - interface CallbackRegistrar extends org.hibernate.jpa.event.spi.CallbackRegistrar { + interface CallbackRegistrar extends CallbackRegistry { + + /** + * Register the callback against the given entity. + * + * @param entityClass The entity Class to register the Callbacks against + * @param callbacks The Callbacks to register against the given entity Class + */ + void registerCallbacks(Class entityClass, Callback[] callbacks); } void buildCallbacksForEntity(Class entityClass, CallbackRegistrar callbackRegistrar); diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackDefinition.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackDefinition.java deleted file mode 100644 index 3bed22602db2..000000000000 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackDefinition.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.jpa.event.spi; - -import java.io.Serializable; - -import org.hibernate.resource.beans.spi.ManagedBeanRegistry; - -public interface CallbackDefinition extends Serializable { - - Callback createCallback(ManagedBeanRegistry beanRegistry); - -} diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackRegistrar.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackRegistrar.java deleted file mode 100644 index 7b2bf2cbd423..000000000000 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackRegistrar.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.jpa.event.spi; - -public interface CallbackRegistrar extends CallbackRegistry { - - /** - * Register the callback against the given entity. - * - * @param entityClass The entity Class to register the Callbacks against - * @param callbacks The Callbacks to register against the given entity Class - */ - void registerCallbacks(Class entityClass, Callback[] callbacks); - -} diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java b/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java index 9b9478dd08d5..7703755e3003 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java @@ -27,7 +27,6 @@ import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.JoinedIterator; import org.hibernate.internal.util.collections.SingletonIterator; -import org.hibernate.jpa.event.spi.CallbackDefinition; import org.hibernate.service.ServiceRegistry; import org.hibernate.sql.Alias; @@ -74,7 +73,6 @@ public abstract class PersistentClass implements AttributeContainer, Serializabl private Boolean isAbstract; private boolean hasSubselectLoadableCollections; private Component identifierMapper; - private java.util.List callbackDefinitions; // Custom SQL private String customSQLInsert; @@ -980,23 +978,6 @@ public boolean hasIdentifierMapper() { return identifierMapper != null; } - public void addCallbackDefinitions(java.util.List callbackDefinitions) { - if ( callbackDefinitions == null || callbackDefinitions.isEmpty() ) { - return; - } - if ( this.callbackDefinitions == null ) { - this.callbackDefinitions = new ArrayList<>(); - } - this.callbackDefinitions.addAll( callbackDefinitions ); - } - - public java.util.List getCallbackDefinitions() { - if ( callbackDefinitions == null ) { - return Collections.emptyList(); - } - return Collections.unmodifiableList( callbackDefinitions ); - } - public void setIdentifierMapper(Component handle) { this.identifierMapper = handle; } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Property.java b/hibernate-core/src/main/java/org/hibernate/mapping/Property.java index 35b1525fd43d..697abe7a5be9 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Property.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Property.java @@ -7,8 +7,6 @@ package org.hibernate.mapping; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; import java.util.Iterator; import java.util.StringTokenizer; @@ -21,7 +19,6 @@ import org.hibernate.engine.spi.CascadeStyles; import org.hibernate.engine.spi.Mapping; import org.hibernate.internal.util.collections.ArrayHelper; -import org.hibernate.jpa.event.spi.CallbackDefinition; import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.PropertyAccessStrategy; import org.hibernate.property.access.spi.PropertyAccessStrategyResolver; @@ -53,7 +50,6 @@ public class Property implements Serializable, MetaAttributable { private PersistentClass persistentClass; private boolean naturalIdentifier; private boolean lob; - private java.util.List callbackDefinitions; public boolean isBackRef() { return false; @@ -369,21 +365,4 @@ public void setLob(boolean lob) { this.lob = lob; } - public void addCallbackDefinitions(java.util.List callbackDefinitions) { - if ( callbackDefinitions == null || callbackDefinitions.isEmpty() ) { - return; - } - if ( this.callbackDefinitions == null ) { - this.callbackDefinitions = new ArrayList<>(); - } - this.callbackDefinitions.addAll( callbackDefinitions ); - } - - public java.util.List getCallbackDefinitions() { - if ( callbackDefinitions == null ) { - return Collections.emptyList(); - } - return Collections.unmodifiableList( callbackDefinitions ); - } - }