01: package org.hibernate.proxy.pojo.javassist;
02:
03: import java.io.Serializable;
04: import java.lang.reflect.Method;
05: import java.util.Set;
06:
07: import org.hibernate.HibernateException;
08: import org.hibernate.engine.SessionImplementor;
09: import org.hibernate.proxy.HibernateProxy;
10: import org.hibernate.proxy.ProxyFactory;
11: import org.hibernate.type.AbstractComponentType;
12:
13: /**
14: * A {@link ProxyFactory} implementation for producing Javassist-based proxies.
15: *
16: * @author Muga Nishizawa
17: */
18: public class JavassistProxyFactory implements ProxyFactory,
19: Serializable {
20:
21: protected static final Class[] NO_CLASSES = new Class[0];
22: private Class persistentClass;
23: private String entityName;
24: private Class[] interfaces;
25: private Method getIdentifierMethod;
26: private Method setIdentifierMethod;
27: private AbstractComponentType componentIdType;
28: private Class factory;
29:
30: public void postInstantiate(final String entityName,
31: final Class persistentClass, final Set interfaces,
32: final Method getIdentifierMethod,
33: final Method setIdentifierMethod,
34: AbstractComponentType componentIdType)
35: throws HibernateException {
36: this .entityName = entityName;
37: this .persistentClass = persistentClass;
38: this .interfaces = (Class[]) interfaces.toArray(NO_CLASSES);
39: this .getIdentifierMethod = getIdentifierMethod;
40: this .setIdentifierMethod = setIdentifierMethod;
41: this .componentIdType = componentIdType;
42: factory = JavassistLazyInitializer.getProxyFactory(
43: persistentClass, this .interfaces);
44: }
45:
46: public HibernateProxy getProxy(Serializable id,
47: SessionImplementor session) throws HibernateException {
48: return JavassistLazyInitializer.getProxy(factory, entityName,
49: persistentClass, interfaces, getIdentifierMethod,
50: setIdentifierMethod, componentIdType, id, session);
51: }
52:
53: }
|