Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/hibernate/intercept/cglib/FieldInterceptorImpl.java


1   //$Id: FieldInterceptorImpl.java 9210 2006-02-03 22:15:19Z steveebersole $
2   package org.hibernate.intercept.cglib;
3   
4   import java.io.Serializable;
5   import java.util.Set;
6   
7   import net.sf.cglib.transform.impl.InterceptFieldCallback;
8   
9   import org.hibernate.intercept.AbstractFieldInterceptor;
10  import org.hibernate.engine.SessionImplementor;
11  import org.hibernate.proxy.HibernateProxy;
12  import org.hibernate.proxy.LazyInitializer;
13  
14  /**
15   * A field-level interceptor that initializes lazily fetched properties.
16   * This interceptor can be attached to classes instrumented by CGLIB.
17   * Note that this implementation assumes that the instance variable
18   * name is the same as the name of the persistent property that must
19   * be loaded.
20   *
21   * @author Gavin King
22   */
23  public final class FieldInterceptorImpl extends AbstractFieldInterceptor implements InterceptFieldCallback, Serializable {
24  
25    /**
26     * Package-protected constructor
27     *
28     * @param session
29     * @param uninitializedFields
30     * @param entityName
31     */
32    FieldInterceptorImpl(SessionImplementor session, Set uninitializedFields, String entityName) {
33      super( session, uninitializedFields, entityName );
34    }
35  
36    public boolean readBoolean(Object target, String name, boolean oldValue) {
37      return ( ( Boolean ) intercept( target, name, oldValue  ? Boolean.TRUE : Boolean.FALSE ) )
38          .booleanValue();
39    }
40  
41    public byte readByte(Object target, String name, byte oldValue) {
42      return ( ( Byte ) intercept( target, name, new Byte( oldValue ) ) ).byteValue();
43    }
44  
45    public char readChar(Object target, String name, char oldValue) {
46      return ( ( Character ) intercept( target, name, new Character( oldValue ) ) )
47          .charValue();
48    }
49  
50    public double readDouble(Object target, String name, double oldValue) {
51      return ( ( Double ) intercept( target, name, new Double( oldValue ) ) )
52          .doubleValue();
53    }
54  
55    public float readFloat(Object target, String name, float oldValue) {
56      return ( ( Float ) intercept( target, name, new Float( oldValue ) ) )
57          .floatValue();
58    }
59  
60    public int readInt(Object target, String name, int oldValue) {
61      return ( ( Integer ) intercept( target, name, new Integer( oldValue ) ) )
62          .intValue();
63    }
64  
65    public long readLong(Object target, String name, long oldValue) {
66      return ( ( Long ) intercept( target, name, new Long( oldValue ) ) ).longValue();
67    }
68  
69    public short readShort(Object target, String name, short oldValue) {
70      return ( ( Short ) intercept( target, name, new Short( oldValue ) ) )
71          .shortValue();
72    }
73  
74    public Object readObject(Object target, String name, Object oldValue) {
75      Object value = intercept( target, name, oldValue );
76      if (value instanceof HibernateProxy) {
77        LazyInitializer li = ( (HibernateProxy) value ).getHibernateLazyInitializer();
78        if ( li.isUnwrap() ) {
79          value = li.getImplementation();
80        }
81      }
82      return value;
83    }
84  
85    public boolean writeBoolean(Object target, String name, boolean oldValue, boolean newValue) {
86      dirty();
87      intercept( target, name, oldValue ? Boolean.TRUE : Boolean.FALSE );
88      return newValue;
89    }
90  
91    public byte writeByte(Object target, String name, byte oldValue, byte newValue) {
92      dirty();
93      intercept( target, name, new Byte( oldValue ) );
94      return newValue;
95    }
96  
97    public char writeChar(Object target, String name, char oldValue, char newValue) {
98      dirty();
99      intercept( target, name, new Character( oldValue ) );
100     return newValue;
101   }
102 
103   public double writeDouble(Object target, String name, double oldValue, double newValue) {
104     dirty();
105     intercept( target, name, new Double( oldValue ) );
106     return newValue;
107   }
108 
109   public float writeFloat(Object target, String name, float oldValue, float newValue) {
110     dirty();
111     intercept( target, name, new Float( oldValue ) );
112     return newValue;
113   }
114 
115   public int writeInt(Object target, String name, int oldValue, int newValue) {
116     dirty();
117     intercept( target, name, new Integer( oldValue ) );
118     return newValue;
119   }
120 
121   public long writeLong(Object target, String name, long oldValue, long newValue) {
122     dirty();
123     intercept( target, name, new Long( oldValue ) );
124     return newValue;
125   }
126 
127   public short writeShort(Object target, String name, short oldValue, short newValue) {
128     dirty();
129     intercept( target, name, new Short( oldValue ) );
130     return newValue;
131   }
132 
133   public Object writeObject(Object target, String name, Object oldValue, Object newValue) {
134     dirty();
135     intercept( target, name, oldValue );
136     return newValue;
137   }
138 
139   public String toString() {
140     return "FieldInterceptorImpl(" +
141       "entityName=" + getEntityName() +
142       ",dirty=" + isDirty() +
143       ",uninitializedFields=" + getUninitializedFields() +
144       ')';
145   }
146 
147 }