1 package org.hibernate.property; 3 4 import java.lang.reflect.Method ; 5 import java.util.Map ; 6 import java.io.Serializable ; 7 8 import org.hibernate.HibernateException; 9 import org.hibernate.engine.SessionImplementor; 10 import org.hibernate.engine.SessionFactoryImplementor; 11 12 17 public class BackrefPropertyAccessor implements PropertyAccessor { 18 19 private final String propertyName; 20 private final String entityName; 21 22 26 public static final Serializable UNKNOWN = new Serializable () { 27 public String toString() { return "<unknown>"; } 28 public Object readResolve() { 29 return UNKNOWN; 30 } 31 }; 32 33 38 public BackrefPropertyAccessor(String collectionRole, String entityName) { 39 this.propertyName = collectionRole.substring( entityName.length() + 1 ); 40 this.entityName = entityName; 41 } 42 43 public Setter getSetter(Class theClass, String propertyName) { 44 return new BackrefSetter(); 45 } 46 47 public Getter getGetter(Class theClass, String propertyName) { 48 return new BackrefGetter(); 49 } 50 51 52 55 public static final class BackrefSetter implements Setter { 56 57 public Method getMethod() { 58 return null; 59 } 60 61 public String getMethodName() { 62 return null; 63 } 64 65 public void set(Object target, Object value, SessionFactoryImplementor factory) { 66 } 68 69 } 70 71 72 75 public class BackrefGetter implements Getter { 76 77 public Object getForInsert(Object target, Map mergeMap, SessionImplementor session) 78 throws HibernateException { 79 if (session==null) { 80 return UNKNOWN; 81 } 82 else { 83 return session.getPersistenceContext() 84 .getOwnerId( entityName, propertyName, target, mergeMap ); 85 } 86 } 87 88 public Object get(Object target) { 89 return UNKNOWN; 90 } 91 92 public Method getMethod() { 93 return null; 94 } 95 96 public String getMethodName() { 97 return null; 98 } 99 100 public Class getReturnType() { 101 return Object .class; 102 } 103 } 104 } 105 106 | Popular Tags |