~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to src/org/hibernate/property/BackrefPropertyAccessor.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//$Id: BackrefPropertyAccessor.java 7516 2005-07-16 22:20:48Z oneovthafew $
 
2
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
/**
 
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 propertyName;
 
20
        private final String 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 UNKNOWN = new Serializable() {
 
27
                public String toString() { return "<unknown>"; }
 
28
                public Object 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 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
        /**
 
53
         * The Setter implementation for id backrefs.
 
54
         */
 
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
                        // 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 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