1 package org.hibernate.proxy; 3 4 import java.io.Serializable ; 5 import java.lang.reflect.Method ; 6 7 import org.hibernate.HibernateException; 8 import org.hibernate.type.AbstractComponentType; 9 10 13 public final class SerializableProxy implements Serializable { 14 15 private String entityName; 16 private Class persistentClass; 17 private Class [] interfaces; 18 private Serializable id; 19 private Class getIdentifierMethodClass; 20 private Class setIdentifierMethodClass; 21 private String getIdentifierMethodName; 22 private String setIdentifierMethodName; 23 private Class [] setIdentifierMethodParams; 24 private AbstractComponentType componentIdType; 25 26 public SerializableProxy() {} 27 28 public SerializableProxy( 29 final String entityName, 30 final Class persistentClass, 31 final Class [] interfaces, 32 final Serializable id, 33 final Method getIdentifierMethod, 34 final Method setIdentifierMethod, 35 AbstractComponentType componentIdType 36 ) { 37 this.entityName = entityName; 38 this.persistentClass = persistentClass; 39 this.interfaces = interfaces; 40 this.id = id; 41 if (getIdentifierMethod!=null) { 42 getIdentifierMethodClass = getIdentifierMethod.getDeclaringClass(); 43 getIdentifierMethodName = getIdentifierMethod.getName(); 44 } 45 if (setIdentifierMethod!=null) { 46 setIdentifierMethodClass = setIdentifierMethod.getDeclaringClass(); 47 setIdentifierMethodName = setIdentifierMethod.getName(); 48 setIdentifierMethodParams = setIdentifierMethod.getParameterTypes(); 49 } 50 this.componentIdType = componentIdType; 51 } 52 53 private Object readResolve() { 54 try { 55 return CGLIBLazyInitializer.getProxy( 56 entityName, 57 persistentClass, 58 interfaces, 59 getIdentifierMethodName==null ? 60 null : 61 getIdentifierMethodClass.getDeclaredMethod(getIdentifierMethodName, null), 62 setIdentifierMethodName==null ? 63 null : 64 setIdentifierMethodClass.getDeclaredMethod(setIdentifierMethodName, setIdentifierMethodParams), 65 componentIdType, 66 id, 67 null 68 ); 69 } 70 catch (NoSuchMethodException nsme) { 71 throw new HibernateException("could not create proxy for entity: " + entityName, nsme); 72 } 73 } 74 75 } 76 | Popular Tags |