KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > property > BackrefPropertyAccessor


1 //$Id: BackrefPropertyAccessor.java,v 1.9 2005/07/16 22:20:47 oneovthafew Exp $
2
package org.hibernate.property;
3
4 import java.lang.reflect.Method JavaDoc;
5 import java.util.Map JavaDoc;
6 import java.io.Serializable JavaDoc;
7
8 import org.hibernate.HibernateException;
9 import org.hibernate.engine.SessionImplementor;
10 import org.hibernate.engine.SessionFactoryImplementor;
11
12 /**
13  * Represents a "back-reference" to the id of a collection owner.
14  *
15  * @author Gavin King
16  */

17 public class BackrefPropertyAccessor implements PropertyAccessor {
18
19     private final String JavaDoc propertyName;
20     private final String JavaDoc entityName;
21
22     /**
23      * A placeholder for a property value, indicating that
24      * we don't know the value of the back reference
25      */

26     public static final Serializable JavaDoc UNKNOWN = new Serializable JavaDoc() {
27         public String JavaDoc toString() { return "<unknown>"; }
28         public Object JavaDoc readResolve() {
29             return UNKNOWN;
30         }
31     };
32     
33     /**
34      * Constructs a new instance of BackrefPropertyAccessor.
35      *
36      * @param collectionRole The collection role which this back ref references.
37      */

38     public BackrefPropertyAccessor(String JavaDoc collectionRole, String JavaDoc entityName) {
39         this.propertyName = collectionRole.substring( entityName.length() + 1 );
40         this.entityName = entityName;
41     }
42
43     public Setter getSetter(Class JavaDoc theClass, String JavaDoc propertyName) {
44         return new BackrefSetter();
45     }
46
47     public Getter getGetter(Class JavaDoc theClass, String JavaDoc propertyName) {
48         return new BackrefGetter();
49     }
50
51
52     /**
53      * The Setter implementation for id backrefs.
54      */

55     public static final class BackrefSetter implements Setter {
56
57         public Method JavaDoc getMethod() {
58             return null;
59         }
60
61         public String JavaDoc getMethodName() {
62             return null;
63         }
64
65         public void set(Object JavaDoc target, Object JavaDoc value, SessionFactoryImplementor factory) {
66             // this page intentionally left blank :)
67
}
68
69     }
70
71
72     /**
73      * The Getter implementation for id backrefs.
74      */

75     public class BackrefGetter implements Getter {
76         
77         public Object JavaDoc getForInsert(Object JavaDoc target, Map JavaDoc 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 JavaDoc get(Object JavaDoc target) {
89             return UNKNOWN;
90         }
91
92         public Method JavaDoc getMethod() {
93             return null;
94         }
95
96         public String JavaDoc getMethodName() {
97             return null;
98         }
99
100         public Class JavaDoc getReturnType() {
101             return Object JavaDoc.class;
102         }
103     }
104 }
105
106
Popular Tags