cleanup CallbackRegistry
This commit is contained in:
parent
73f4960e3d
commit
fad946838a
|
@ -19,30 +19,29 @@ import org.hibernate.jpa.event.spi.CallbackType;
|
|||
* @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "serial"})
|
||||
final class CallbackRegistryImpl implements CallbackRegistryImplementor {
|
||||
private HashMap<Class, Callback[]> preCreates = new HashMap<>();
|
||||
private HashMap<Class, Callback[]> postCreates = new HashMap<>();
|
||||
private HashMap<Class, Callback[]> preRemoves = new HashMap<>();
|
||||
private HashMap<Class, Callback[]> postRemoves = new HashMap<>();
|
||||
private HashMap<Class, Callback[]> preUpdates = new HashMap<>();
|
||||
private HashMap<Class, Callback[]> postUpdates = new HashMap<>();
|
||||
private HashMap<Class, Callback[]> postLoads = new HashMap<>();
|
||||
private final HashMap<Class<?>, Callback[]> preCreates = new HashMap<>();
|
||||
private final HashMap<Class<?>, Callback[]> postCreates = new HashMap<>();
|
||||
private final HashMap<Class<?>, Callback[]> preRemoves = new HashMap<>();
|
||||
private final HashMap<Class<?>, Callback[]> postRemoves = new HashMap<>();
|
||||
private final HashMap<Class<?>, Callback[]> preUpdates = new HashMap<>();
|
||||
private final HashMap<Class<?>, Callback[]> postUpdates = new HashMap<>();
|
||||
private final HashMap<Class<?>, Callback[]> postLoads = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean hasRegisteredCallbacks(Class entityClass, CallbackType callbackType) {
|
||||
final HashMap<Class, Callback[]> map = determineAppropriateCallbackMap( callbackType );
|
||||
public boolean hasRegisteredCallbacks(Class<?> entityClass, CallbackType callbackType) {
|
||||
final HashMap<Class<?>, 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<Class, Callback[]> map = determineAppropriateCallbackMap( callback.getCallbackType() );
|
||||
final HashMap<Class<?>, 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<Class, Callback[]> determineAppropriateCallbackMap(CallbackType callbackType) {
|
||||
private HashMap<Class<?>, 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<Class, Callback[]> 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 + "]" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public enum CallbackType {
|
|||
POST_LOAD( PostLoad.class )
|
||||
;
|
||||
|
||||
private Class<? extends Annotation> callbackAnnotation;
|
||||
private final Class<? extends Annotation> callbackAnnotation;
|
||||
|
||||
CallbackType(Class<? extends Annotation> callbackAnnotation) {
|
||||
this.callbackAnnotation = callbackAnnotation;
|
||||
|
|
Loading…
Reference in New Issue