Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/hibernate/proxy/pojo/javassist/JavassistProxyFactory.java


1   package org.hibernate.proxy.pojo.javassist;
2   
3   import java.io.Serializable;
4   import java.lang.reflect.Method;
5   import java.util.Set;
6   
7   import org.hibernate.HibernateException;
8   import org.hibernate.engine.SessionImplementor;
9   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, Serializable {
19  
20    protected static final Class[] NO_CLASSES = new Class[0];
21    private Class persistentClass;
22    private String entityName;
23    private Class[] interfaces;
24    private Method getIdentifierMethod;
25    private Method setIdentifierMethod;
26    private AbstractComponentType componentIdType;
27    private Class factory;
28  
29    public void postInstantiate(
30        final String entityName,
31        final Class persistentClass,
32            final Set interfaces,
33        final Method getIdentifierMethod,
34            final Method setIdentifierMethod,
35        AbstractComponentType componentIdType) 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( persistentClass, this.interfaces );
43    }
44  
45    public HibernateProxy getProxy(
46        Serializable id,
47            SessionImplementor session) throws HibernateException {
48      return JavassistLazyInitializer.getProxy(
49          factory,
50              entityName,
51          persistentClass,
52              interfaces,
53              getIdentifierMethod,
54          setIdentifierMethod,
55              componentIdType,
56              id,
57              session
58      );
59    }
60  
61  }