1
//$Id: BackrefPropertyAccessor.java 7516 2005-07-16 22:20:48Z oneovthafew $
2
package org.hibernate.property;
4
import java.lang.reflect.Method;
6
import java.io.Serializable;
8
import org.hibernate.HibernateException;
9
import org.hibernate.engine.SessionImplementor;
10
import org.hibernate.engine.SessionFactoryImplementor;
13
* Represents a "back-reference" to the id of a collection owner.
17
public class BackrefPropertyAccessor implements PropertyAccessor {
19
private final String propertyName;
20
private final String entityName;
23
* A placeholder for a property value, indicating that
24
* we don't know the value of the back reference
26
public static final Serializable UNKNOWN = new Serializable() {
27
public String toString() { return "<unknown>"; }
28
public Object readResolve() {
34
* Constructs a new instance of BackrefPropertyAccessor.
36
* @param collectionRole The collection role which this back ref references.
38
public BackrefPropertyAccessor(String collectionRole, String entityName) {
39
this.propertyName = collectionRole.substring( entityName.length() + 1 );
40
this.entityName = entityName;
43
public Setter getSetter(Class theClass, String propertyName) {
44
return new BackrefSetter();
47
public Getter getGetter(Class theClass, String propertyName) {
48
return new BackrefGetter();
53
* The Setter implementation for id backrefs.
55
public static final class BackrefSetter implements Setter {
57
public Method getMethod() {
61
public String getMethodName() {
65
public void set(Object target, Object value, SessionFactoryImplementor factory) {
66
// this page intentionally left blank :)
73
* The Getter implementation for id backrefs.
75
public class BackrefGetter implements Getter {
77
public Object getForInsert(Object target, Map mergeMap, SessionImplementor session)
78
throws HibernateException {
83
return session.getPersistenceContext()
84
.getOwnerId( entityName, propertyName, target, mergeMap );
88
public Object get(Object target) {
92
public Method getMethod() {
96
public String getMethodName() {
100
public Class getReturnType() {