JavassistLazyInitializerpublic class JavassistLazyInitializer extends org.hibernate.proxy.pojo.BasicLazyInitializer implements MethodHandlerA Javassist-based lazy initializer proxy. |
Fields Summary |
---|
private static final MethodFilter | FINALIZE_FILTER | private Class[] | interfaces | private boolean | constructed |
Constructors Summary |
---|
private JavassistLazyInitializer(String entityName, Class persistentClass, Class[] interfaces, Serializable id, Method getIdentifierMethod, Method setIdentifierMethod, org.hibernate.type.AbstractComponentType componentIdType, org.hibernate.engine.SessionImplementor session)
super( entityName, persistentClass, id, getIdentifierMethod, setIdentifierMethod, componentIdType, session );
this.interfaces = interfaces;
|
Methods Summary |
---|
public static org.hibernate.proxy.HibernateProxy | getProxy(java.lang.String entityName, java.lang.Class persistentClass, java.lang.Class[] interfaces, java.lang.reflect.Method getIdentifierMethod, java.lang.reflect.Method setIdentifierMethod, org.hibernate.type.AbstractComponentType componentIdType, java.io.Serializable id, org.hibernate.engine.SessionImplementor session)
// note: interface is assumed to already contain HibernateProxy.class
try {
final JavassistLazyInitializer instance = new JavassistLazyInitializer(
entityName,
persistentClass,
interfaces,
id,
getIdentifierMethod,
setIdentifierMethod,
componentIdType,
session
);
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
factory.setInterfaces( interfaces );
factory.setFilter( FINALIZE_FILTER );
Class cl = factory.createClass();
final HibernateProxy proxy = ( HibernateProxy ) cl.newInstance();
( ( ProxyObject ) proxy ).setHandler( instance );
instance.constructed = true;
return proxy;
}
catch ( Throwable t ) {
LogFactory.getLog( BasicLazyInitializer.class ).error(
"Javassist Enhancement failed: " + entityName, t
);
throw new HibernateException(
"Javassist Enhancement failed: "
+ entityName, t
);
}
| public static org.hibernate.proxy.HibernateProxy | getProxy(java.lang.Class factory, java.lang.String entityName, java.lang.Class persistentClass, java.lang.Class[] interfaces, java.lang.reflect.Method getIdentifierMethod, java.lang.reflect.Method setIdentifierMethod, org.hibernate.type.AbstractComponentType componentIdType, java.io.Serializable id, org.hibernate.engine.SessionImplementor session)
final JavassistLazyInitializer instance = new JavassistLazyInitializer(
entityName,
persistentClass,
interfaces, id,
getIdentifierMethod,
setIdentifierMethod,
componentIdType,
session
);
final HibernateProxy proxy;
try {
proxy = ( HibernateProxy ) factory.newInstance();
}
catch ( Exception e ) {
throw new HibernateException(
"Javassist Enhancement failed: "
+ persistentClass.getName(), e
);
}
( ( ProxyObject ) proxy ).setHandler( instance );
instance.constructed = true;
return proxy;
| public static java.lang.Class | getProxyFactory(java.lang.Class persistentClass, java.lang.Class[] interfaces)
// note: interfaces is assumed to already contain HibernateProxy.class
try {
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
factory.setInterfaces( interfaces );
factory.setFilter( FINALIZE_FILTER );
return factory.createClass();
}
catch ( Throwable t ) {
LogFactory.getLog( BasicLazyInitializer.class ).error(
"Javassist Enhancement failed: "
+ persistentClass.getName(), t
);
throw new HibernateException(
"Javassist Enhancement failed: "
+ persistentClass.getName(), t
);
}
| public java.lang.Object | invoke(java.lang.Object proxy, java.lang.reflect.Method thisMethod, java.lang.reflect.Method proceed, java.lang.Object[] args)
if ( this.constructed ) {
Object result;
try {
result = this.invoke( thisMethod, args, proxy );
}
catch ( Throwable t ) {
throw new Exception( t.getCause() );
}
if ( result == INVOKE_IMPLEMENTATION ) {
Object target = getImplementation();
final Object returnValue;
try {
if ( ReflectHelper.isPublic( persistentClass, thisMethod ) ) {
if ( ! thisMethod.getDeclaringClass().isInstance( target ) ) {
throw new ClassCastException( target.getClass().getName() );
}
returnValue = thisMethod.invoke( target, args );
}
else {
if ( !thisMethod.isAccessible() ) {
thisMethod.setAccessible( true );
}
returnValue = thisMethod.invoke( target, args );
}
return returnValue == target ? proxy : returnValue;
}
catch ( InvocationTargetException ite ) {
throw ite.getTargetException();
}
}
else {
return result;
}
}
else {
// while constructor is running
if ( thisMethod.getName().equals( "getHibernateLazyInitializer" ) ) {
return this;
}
else {
return proceed.invoke( proxy, args );
}
}
| protected java.lang.Object | serializableProxy()
return new SerializableProxy(
getEntityName(),
persistentClass,
interfaces,
getIdentifier(),
getIdentifierMethod,
setIdentifierMethod,
componentIdType
);
|
|