HHH-12482 Avoid logging overhead within CallbackBuilderLegacyImpl loops

This commit is contained in:
Sanne Grinovero 2018-04-12 11:55:36 +01:00
parent cf75861c0e
commit e316649fd6
1 changed files with 38 additions and 28 deletions

View File

@ -53,6 +53,7 @@ public class CallbackBuilderLegacyImpl implements CallbackBuilder {
@Override @Override
public void buildCallbacksForEntity(String entityClassName, CallbackRegistrar callbackRegistrar) { public void buildCallbacksForEntity(String entityClassName, CallbackRegistrar callbackRegistrar) {
final boolean debugEnabled = log.isDebugEnabled();
try { try {
final XClass entityXClass = reflectionManager.classForName( entityClassName ); final XClass entityXClass = reflectionManager.classForName( entityClassName );
final Class entityClass = reflectionManager.toClass( entityXClass ); final Class entityClass = reflectionManager.toClass( entityXClass );
@ -60,13 +61,15 @@ public class CallbackBuilderLegacyImpl implements CallbackBuilder {
if ( callbackRegistrar.hasRegisteredCallbacks( entityClass, callbackType ) ) { if ( callbackRegistrar.hasRegisteredCallbacks( entityClass, callbackType ) ) {
// this most likely means we have a class mapped multiple times using the hbm.xml // this most likely means we have a class mapped multiple times using the hbm.xml
// "entity name" feature // "entity name" feature
log.debugf( if ( debugEnabled ) {
"CallbackRegistry reported that Class [%s] already had %s callbacks registered; " + log.debugf(
"assuming this means the class was mapped twice " + "CallbackRegistry reported that Class [%s] already had %s callbacks registered; " +
"(using hbm.xml entity-name support) - skipping subsequent registrations", "assuming this means the class was mapped twice " +
entityClassName, "(using hbm.xml entity-name support) - skipping subsequent registrations",
callbackType.getCallbackAnnotation().getSimpleName() entityClassName,
); callbackType.getCallbackAnnotation().getSimpleName()
);
}
continue; continue;
} }
final Callback[] callbacks = resolveEntityCallbacks( entityXClass, callbackType, reflectionManager ); final Callback[] callbacks = resolveEntityCallbacks( entityXClass, callbackType, reflectionManager );
@ -113,6 +116,7 @@ public class CallbackBuilderLegacyImpl implements CallbackBuilder {
XClass currentClazz = beanClass; XClass currentClazz = beanClass;
boolean stopListeners = false; boolean stopListeners = false;
boolean stopDefaultListeners = false; boolean stopDefaultListeners = false;
final boolean debugEnabled = log.isDebugEnabled();
do { do {
Callback callback = null; Callback callback = null;
List<XMethod> methods = currentClazz.getDeclaredMethods(); List<XMethod> methods = currentClazz.getDeclaredMethods();
@ -133,12 +137,14 @@ public class CallbackBuilderLegacyImpl implements CallbackBuilder {
); );
} }
ReflectHelper.ensureAccessibility( method ); ReflectHelper.ensureAccessibility( method );
log.debugf( if ( debugEnabled ) {
"Adding %s as %s callback for entity %s", log.debugf(
methodName, "Adding %s as %s callback for entity %s",
callbackType.getCallbackAnnotation().getSimpleName(), methodName,
beanClass.getName() callbackType.getCallbackAnnotation().getSimpleName(),
); beanClass.getName()
);
}
callbacks.add( 0, callback ); //superclass first callbacks.add( 0, callback ); //superclass first
callbacksMethodNames.add( 0, methodName ); callbacksMethodNames.add( 0, methodName );
} }
@ -207,12 +213,14 @@ public class CallbackBuilderLegacyImpl implements CallbackBuilder {
); );
} }
ReflectHelper.ensureAccessibility( method ); ReflectHelper.ensureAccessibility( method );
log.debugf( if ( debugEnabled ) {
"Adding %s as %s callback for entity %s", log.debugf(
methodName, "Adding %s as %s callback for entity %s",
callbackType.getCallbackAnnotation().getSimpleName(), methodName,
beanClass.getName() callbackType.getCallbackAnnotation().getSimpleName(),
); beanClass.getName()
);
}
callbacks.add( 0, callback ); // listeners first callbacks.add( 0, callback ); // listeners first
} }
else { else {
@ -237,9 +245,9 @@ public class CallbackBuilderLegacyImpl implements CallbackBuilder {
final String embeddableClassName = embeddableProperty.getType().getReturnedClass().getName(); final String embeddableClassName = embeddableProperty.getType().getReturnedClass().getName();
final XClass embeddableXClass = reflectionManager.classForName( embeddableClassName ); final XClass embeddableXClass = reflectionManager.classForName( embeddableClassName );
final Getter embeddableGetter = embeddableProperty.getGetter( entityClass ); final Getter embeddableGetter = embeddableProperty.getGetter( entityClass );
final boolean debugEnabled = log.isDebugEnabled();
List<Callback> callbacks = new ArrayList<>(); final List<Callback> callbacks = new ArrayList<>();
List<String> callbacksMethodNames = new ArrayList<>(); final List<String> callbacksMethodNames = new ArrayList<>();
XClass currentClazz = embeddableXClass; XClass currentClazz = embeddableXClass;
do { do {
Callback callback = null; Callback callback = null;
@ -261,12 +269,14 @@ public class CallbackBuilderLegacyImpl implements CallbackBuilder {
); );
} }
ReflectHelper.ensureAccessibility( method ); ReflectHelper.ensureAccessibility( method );
log.debugf( if ( debugEnabled ) {
"Adding %s as %s callback for entity %s", log.debugf(
methodName, "Adding %s as %s callback for entity %s",
callbackType.getCallbackAnnotation().getSimpleName(), methodName,
embeddableXClass.getName() callbackType.getCallbackAnnotation().getSimpleName(),
); embeddableXClass.getName()
);
}
callbacks.add( 0, callback ); //superclass first callbacks.add( 0, callback ); //superclass first
callbacksMethodNames.add( 0, methodName ); callbacksMethodNames.add( 0, methodName );
} }