Author: steve.ebersole(a)jboss.com
Date: 2006-11-13 12:44:44 -0500 (Mon, 13 Nov 2006)
New Revision: 10791
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/proxy/pojo/javassist/JavassistLazyInitializer.java
Log:
HHH-2229 : performance of castability checks during proxy initialization (port to 3.2)
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java
===================================================================
---
branches/Branch_3_2/Hibernate3/src/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java 2006-11-13
14:14:45 UTC (rev 10790)
+++
branches/Branch_3_2/Hibernate3/src/org/hibernate/proxy/pojo/cglib/CGLIBLazyInitializer.java 2006-11-13
17:44:44 UTC (rev 10791)
@@ -4,11 +4,7 @@
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Iterator;
-
import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.CallbackFilter;
import net.sf.cglib.proxy.Enhancer;
@@ -137,63 +133,31 @@
this.interfaces = interfaces;
}
- private static boolean isCastable(Class caster, Class castee) {
- if ( castee.equals( caster ) ) {
- return true;
- }
- List list = addCheckingTypes( caster, new ArrayList() );
- for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
- Class cl = ( Class ) iter.next();
- if ( castee.equals( cl ) ) {
- return true;
- }
- }
- return false;
- }
-
- private static List addCheckingTypes(final Class type, final List list) {
- Class superclass = type.getSuperclass();
- if ( superclass != null ) {
- list.add( superclass );
- addCheckingTypes( superclass, list );
- }
- Class[] interfaces = type.getInterfaces();
- for ( int i = 0; i < interfaces.length; ++i ) {
- list.add( interfaces[i] );
- addCheckingTypes( interfaces[i], list );
- }
- return list;
- }
-
public Object invoke(final Object proxy, final Method method, final Object[] args)
throws Throwable {
if ( constructed ) {
Object result = invoke( method, args, proxy );
if ( result == INVOKE_IMPLEMENTATION ) {
Object target = getImplementation();
- final Object returnValue;
try {
- if ( ReflectHelper.isPublic( persistentClass, method ) ) {
- if ( !isCastable(
- target.getClass(), method
- .getDeclaringClass()
- ) ) {
- throw new ClassCastException(
- target.getClass()
- .getName()
- );
+ final Object returnValue;
+ if ( ReflectHelper.isPublic( persistentClass, method ) ) {
+ if ( ! method.getDeclaringClass().isInstance( target ) ) {
+ throw new ClassCastException( target.getClass().getName() );
}
returnValue = method.invoke( target, args );
- }
- else {
- if ( !method.isAccessible() ) method.setAccessible( true );
+ }
+ else {
+ if ( !method.isAccessible() ) {
+ method.setAccessible( true );
+ }
returnValue = method.invoke( target, args );
}
return returnValue == target ? proxy : returnValue;
}
- catch (InvocationTargetException ite) {
- throw ite.getTargetException();
- }
+ catch ( InvocationTargetException ite ) {
+ throw ite.getTargetException();
}
+ }
else {
return result;
}
@@ -204,7 +168,7 @@
return this;
}
else {
- throw new LazyInitializationException("unexpected case hit, method=" +
method.getName());
+ throw new LazyInitializationException( "unexpected case hit, method=" +
method.getName() );
}
}
}
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/proxy/pojo/javassist/JavassistLazyInitializer.java
===================================================================
---
branches/Branch_3_2/Hibernate3/src/org/hibernate/proxy/pojo/javassist/JavassistLazyInitializer.java 2006-11-13
14:14:45 UTC (rev 10790)
+++
branches/Branch_3_2/Hibernate3/src/org/hibernate/proxy/pojo/javassist/JavassistLazyInitializer.java 2006-11-13
17:44:44 UTC (rev 10791)
@@ -3,9 +3,6 @@
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
import javassist.util.proxy.MethodFilter;
import javassist.util.proxy.MethodHandler;
@@ -139,7 +136,6 @@
factory.setInterfaces( interfaces );
factory.setFilter( FINALIZE_FILTER );
return factory.createClass();
- // TODO
}
catch ( Throwable t ) {
LogFactory.getLog( BasicLazyInitializer.class ).error(
@@ -153,34 +149,6 @@
}
}
- private static boolean isCastable(Class caster, Class castee) {
- if ( castee.equals( caster ) ) {
- return true;
- }
- List list = addCheckingTypes( caster, new ArrayList() );
- for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
- Class cl = ( Class ) iter.next();
- if ( castee.equals( cl ) ) {
- return true;
- }
- }
- return false;
- }
-
- private static List addCheckingTypes(final Class type, final List list) {
- Class superclass = type.getSuperclass();
- if ( superclass != null ) {
- list.add( superclass );
- addCheckingTypes( superclass, list );
- }
- Class[] interfaces = type.getInterfaces();
- for ( int i = 0; i < interfaces.length; ++i ) {
- list.add( interfaces[i] );
- addCheckingTypes( interfaces[i], list );
- }
- return list;
- }
-
public Object invoke(
final Object proxy,
final Method thisMethod,
@@ -199,9 +167,9 @@
final Object returnValue;
try {
if ( ReflectHelper.isPublic( persistentClass, thisMethod ) ) {
- if ( !isCastable( target.getClass(), thisMethod.getDeclaringClass())
) {
+ if ( ! thisMethod.getDeclaringClass().isInstance( target ) ) {
throw new ClassCastException( target.getClass().getName() );
- }
+ }
returnValue = thisMethod.invoke( target, args );
}
else {
Show replies by date