From fad946838ad183834d320a5717799f7bb5b96785 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Mon, 24 Jan 2022 22:27:56 +0100 Subject: [PATCH] cleanup CallbackRegistry --- .../event/internal/CallbackRegistryImpl.java | 75 +++---------------- .../internal/CallbackRegistryImplementor.java | 3 +- .../internal/EmptyCallbackRegistryImpl.java | 24 +----- .../jpa/event/spi/CallbackBuilder.java | 37 --------- .../jpa/event/spi/CallbackRegistrar.java | 2 +- .../jpa/event/spi/CallbackRegistry.java | 29 +------ .../hibernate/jpa/event/spi/CallbackType.java | 2 +- 7 files changed, 18 insertions(+), 154 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackBuilder.java diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackRegistryImpl.java index bb6f27af91..aa1bb7daa2 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackRegistryImpl.java @@ -19,30 +19,29 @@ import org.hibernate.jpa.event.spi.CallbackType; * @author Kabir Khan * @author Steve Ebersole */ -@SuppressWarnings({"unchecked", "serial"}) final class CallbackRegistryImpl implements CallbackRegistryImplementor { - private HashMap preCreates = new HashMap<>(); - private HashMap postCreates = new HashMap<>(); - private HashMap preRemoves = new HashMap<>(); - private HashMap postRemoves = new HashMap<>(); - private HashMap preUpdates = new HashMap<>(); - private HashMap postUpdates = new HashMap<>(); - private HashMap postLoads = new HashMap<>(); + private final HashMap, Callback[]> preCreates = new HashMap<>(); + private final HashMap, Callback[]> postCreates = new HashMap<>(); + private final HashMap, Callback[]> preRemoves = new HashMap<>(); + private final HashMap, Callback[]> postRemoves = new HashMap<>(); + private final HashMap, Callback[]> preUpdates = new HashMap<>(); + private final HashMap, Callback[]> postUpdates = new HashMap<>(); + private final HashMap, Callback[]> postLoads = new HashMap<>(); @Override - public boolean hasRegisteredCallbacks(Class entityClass, CallbackType callbackType) { - final HashMap map = determineAppropriateCallbackMap( callbackType ); + public boolean hasRegisteredCallbacks(Class entityClass, CallbackType callbackType) { + final HashMap, Callback[]> map = determineAppropriateCallbackMap( callbackType ); return notEmpty( map.get( entityClass ) ); } @Override - public void registerCallbacks(Class entityClass, Callback[] callbacks) { + public void registerCallbacks(Class entityClass, Callback[] callbacks) { if ( callbacks == null || callbacks.length == 0 ) { return; } for ( Callback callback : callbacks ) { - final HashMap map = determineAppropriateCallbackMap( callback.getCallbackType() ); + final HashMap, Callback[]> map = determineAppropriateCallbackMap( callback.getCallbackType() ); Callback[] entityCallbacks = map.get( entityClass ); if ( entityCallbacks == null ) { entityCallbacks = new Callback[0]; @@ -103,7 +102,7 @@ final class CallbackRegistryImpl implements CallbackRegistryImplementor { } } - private HashMap determineAppropriateCallbackMap(CallbackType callbackType) { + private HashMap, Callback[]> determineAppropriateCallbackMap(CallbackType callbackType) { if ( callbackType == CallbackType.PRE_PERSIST ) { return preCreates; } @@ -147,54 +146,4 @@ final class CallbackRegistryImpl implements CallbackRegistryImplementor { postLoads.clear(); } - - - // deprecations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - @Override - public boolean hasPostCreateCallbacks(Class entityClass) { - return notEmpty( preCreates.get( entityClass ) ); - } - - @Override - public boolean hasPostUpdateCallbacks(Class entityClass) { - return notEmpty( postUpdates.get( entityClass ) ); - } - - @Override - public boolean hasPostRemoveCallbacks(Class entityClass) { - return notEmpty( postRemoves.get( entityClass ) ); - } - - @Override - public boolean hasRegisteredCallbacks(Class entityClass, Class annotationClass) { - final HashMap map = determineAppropriateCallbackMap( toCallbackType( annotationClass ) ); - return map != null && map.containsKey( entityClass ); - } - - private CallbackType toCallbackType(Class annotationClass) { - if ( annotationClass == CallbackType.POST_LOAD.getCallbackAnnotation() ) { - return CallbackType.POST_LOAD; - } - else if ( annotationClass == CallbackType.PRE_PERSIST.getCallbackAnnotation() ) { - return CallbackType.PRE_PERSIST; - } - else if ( annotationClass == CallbackType.POST_PERSIST.getCallbackAnnotation() ) { - return CallbackType.POST_PERSIST; - } - else if ( annotationClass == CallbackType.PRE_UPDATE.getCallbackAnnotation() ) { - return CallbackType.PRE_UPDATE; - } - else if ( annotationClass == CallbackType.POST_UPDATE.getCallbackAnnotation() ) { - return CallbackType.POST_UPDATE; - } - else if ( annotationClass == CallbackType.PRE_REMOVE.getCallbackAnnotation() ) { - return CallbackType.PRE_REMOVE; - } - else if ( annotationClass == CallbackType.POST_REMOVE.getCallbackAnnotation() ) { - return CallbackType.POST_REMOVE; - } - - throw new PersistenceException( "Unrecognized JPA callback annotation [" + annotationClass + "]" ); - } } 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 9444bad094..a3b5758e62 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 @@ -6,10 +6,9 @@ */ package org.hibernate.jpa.event.internal; -import org.hibernate.jpa.event.spi.CallbackBuilder; import org.hibernate.jpa.event.spi.CallbackRegistrar; -public interface CallbackRegistryImplementor extends CallbackRegistrar, CallbackBuilder.CallbackRegistrar { +public interface CallbackRegistryImplementor extends CallbackRegistrar { void release(); diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EmptyCallbackRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EmptyCallbackRegistryImpl.java index fc23e51666..a2f5845964 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EmptyCallbackRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EmptyCallbackRegistryImpl.java @@ -12,7 +12,7 @@ import org.hibernate.jpa.event.spi.CallbackType; final class EmptyCallbackRegistryImpl implements CallbackRegistryImplementor { @Override - public boolean hasRegisteredCallbacks(final Class entityClass, final CallbackType callbackType) { + public boolean hasRegisteredCallbacks(final Class entityClass, final CallbackType callbackType) { return false; } @@ -51,33 +51,13 @@ final class EmptyCallbackRegistryImpl implements CallbackRegistryImplementor { return false; } - @Override - public boolean hasPostCreateCallbacks(final Class entityClass) { - return false; - } - - @Override - public boolean hasPostUpdateCallbacks(final Class entityClass) { - return false; - } - - @Override - public boolean hasPostRemoveCallbacks(final Class entityClass) { - return false; - } - - @Override - public boolean hasRegisteredCallbacks(final Class entityClass, final Class annotationClass) { - return false; - } - @Override public void release() { //no-op } @Override - public void registerCallbacks(Class entityClass, Callback[] callbacks) { + public void registerCallbacks(Class entityClass, Callback[] callbacks) { //no-op } 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 deleted file mode 100644 index 8db5b61884..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackBuilder.java +++ /dev/null @@ -1,37 +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 org.hibernate.mapping.Property; - -/** - * 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 { - } - - void buildCallbacksForEntity(Class entityClass, CallbackRegistrar callbackRegistrar); - - void buildCallbacksForEmbeddable( - Property embeddableProperty, - Class entityClass, - CallbackRegistrar callbackRegistrar); - - void release(); -} 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 index 7b2bf2cbd4..7a2e4b9c42 100644 --- 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 @@ -14,6 +14,6 @@ public interface CallbackRegistrar extends CallbackRegistry { * @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 registerCallbacks(Class entityClass, Callback[] callbacks); } diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackRegistry.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackRegistry.java index 052f8e854a..30792dadf6 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackRegistry.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackRegistry.java @@ -23,7 +23,7 @@ public interface CallbackRegistry extends Serializable { * @return {@code true} indicates there are already registered callbacks of * that type for that class; {@code false} indicates there are not. */ - boolean hasRegisteredCallbacks(Class entityClass, CallbackType callbackType); + boolean hasRegisteredCallbacks(Class entityClass, CallbackType callbackType); void preCreate(Object entity); void postCreate(Object entity); @@ -35,31 +35,4 @@ public interface CallbackRegistry extends Serializable { void postRemove(Object entity); boolean postLoad(Object entity); - - /** - * @deprecated Use {@link #hasRegisteredCallbacks(Class, CallbackType)} instead passing - * {@link CallbackType#POST_PERSIST} - */ - @Deprecated - boolean hasPostCreateCallbacks(Class entityClass); - - /** - * @deprecated Use {@link #hasRegisteredCallbacks(Class, CallbackType)} instead passing - * {@link CallbackType#POST_UPDATE} - */ - @Deprecated - boolean hasPostUpdateCallbacks(Class entityClass); - - /** - * @deprecated Use {@link #hasRegisteredCallbacks(Class, CallbackType)} instead passing - * {@link CallbackType#POST_REMOVE} - */ - @Deprecated - boolean hasPostRemoveCallbacks(Class entityClass); - - /** - * @deprecated Use {@link #hasRegisteredCallbacks(Class, CallbackType)} instead. - */ - @Deprecated - boolean hasRegisteredCallbacks(Class entityClass, Class annotationClass); } diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackType.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackType.java index 40b78a9b04..ee3c4e5cab 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackType.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackType.java @@ -28,7 +28,7 @@ public enum CallbackType { POST_LOAD( PostLoad.class ) ; - private Class callbackAnnotation; + private final Class callbackAnnotation; CallbackType(Class callbackAnnotation) { this.callbackAnnotation = callbackAnnotation;