KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: IndexPropertyAccessor.java,v 1.7 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
7 import org.hibernate.HibernateException;
8 import org.hibernate.engine.SessionImplementor;
9 import org.hibernate.engine.SessionFactoryImplementor;
10
11 /**
12  * Represents a "back-reference" to the index of a collection.
13  *
14  * @author Gavin King
15  */

16 public class IndexPropertyAccessor implements PropertyAccessor {
17     
18     private final String JavaDoc propertyName;
19     private final String JavaDoc entityName;
20
21     /**
22      * Constructs a new instance of IndexPropertyAccessor.
23      *
24      * @param collectionRole The collection role which this back ref references.
25      */

26     public IndexPropertyAccessor(String JavaDoc collectionRole, String JavaDoc entityName) {
27         this.propertyName = collectionRole.substring( entityName.length()+1 );
28         this.entityName = entityName;
29     }
30
31     public Setter getSetter(Class JavaDoc theClass, String JavaDoc propertyName) {
32         return new IndexSetter();
33     }
34
35     public Getter getGetter(Class JavaDoc theClass, String JavaDoc propertyName) {
36         return new IndexGetter();
37     }
38
39
40     /**
41      * The Setter implementation for index backrefs.
42      */

43     public static final class IndexSetter implements Setter {
44
45         public Method JavaDoc getMethod() {
46             return null;
47         }
48
49         public String JavaDoc getMethodName() {
50             return null;
51         }
52
53         public void set(Object JavaDoc target, Object JavaDoc value) {
54             // do nothing...
55
}
56
57         public void set(Object JavaDoc target, Object JavaDoc value, SessionFactoryImplementor factory) throws HibernateException {
58             // do nothing...
59
}
60
61     }
62
63
64     /**
65      * The Getter implementation for index backrefs.
66      */

67     public class IndexGetter implements Getter {
68         
69         public Object JavaDoc getForInsert(Object JavaDoc target, Map JavaDoc mergeMap, SessionImplementor session) throws HibernateException {
70             if (session==null) {
71                 return BackrefPropertyAccessor.UNKNOWN;
72             }
73             else {
74                 return session.getPersistenceContext()
75                         .getIndexInOwner(entityName, propertyName, target, mergeMap);
76             }
77         }
78
79         public Object JavaDoc get(Object JavaDoc target) {
80             return BackrefPropertyAccessor.UNKNOWN;
81         }
82
83         public Method JavaDoc getMethod() {
84             return null;
85         }
86
87         public String JavaDoc getMethodName() {
88             return null;
89         }
90
91         public Class JavaDoc getReturnType() {
92             return Object JavaDoc.class;
93         }
94     }
95 }
96
Popular Tags