1 package org.apache.ojb.jdori.sql; 2 16 17 import javax.jdo.spi.PersistenceCapable; 18 19 import org.apache.ojb.broker.PersistenceBroker; 20 import org.apache.ojb.broker.metadata.AttributeDescriptorBase; 21 import org.apache.ojb.broker.metadata.ClassDescriptor; 22 23 import com.sun.jdori.FieldManager; 24 import com.sun.jdori.model.jdo.JDOClass; 25 import com.sun.jdori.model.jdo.JDOField; 26 27 30 public class OjbFieldManager implements FieldManager 31 { 32 33 private PersistenceCapable pc; 34 35 private PersistenceBroker broker; 36 37 40 public OjbFieldManager() 41 { 42 super(); 43 } 44 45 48 public OjbFieldManager(PersistenceCapable pPc) 49 { 50 pc = pPc; 51 } 52 53 56 public OjbFieldManager(PersistenceCapable pPc, PersistenceBroker pBroker) 57 { 58 pc = pPc; 59 broker = pBroker; 60 } 61 62 65 public void storeBooleanField(int fieldNum, boolean value) 66 { 67 } 68 69 72 public boolean fetchBooleanField(int fieldNum) 73 { 74 Boolean value = (Boolean ) getValue(fieldNum); 75 return value.booleanValue(); 76 } 77 78 81 public void storeCharField(int fieldNum, char value) 82 { 83 } 84 85 88 public char fetchCharField(int fieldNum) 89 { 90 Character value = (Character ) getValue(fieldNum); 91 return value.charValue(); 92 } 93 94 97 public void storeByteField(int fieldNum, byte value) 98 { 99 } 100 101 104 public byte fetchByteField(int fieldNum) 105 { 106 Byte value = (Byte ) getValue(fieldNum); 107 return value.byteValue(); 108 } 109 110 113 public void storeShortField(int fieldNum, short value) 114 { 115 } 116 117 120 public short fetchShortField(int fieldNum) 121 { 122 Short value = (Short ) getValue(fieldNum); 123 return value.shortValue(); 124 } 125 126 129 public void storeIntField(int fieldNum, int value) 130 { 131 } 132 133 136 public int fetchIntField(int fieldNum) 137 { 138 Integer value = (Integer ) getValue(fieldNum); 139 return value.intValue(); 140 } 141 142 145 public void storeLongField(int fieldNum, long value) 146 { 147 } 148 149 152 public long fetchLongField(int fieldNum) 153 { 154 Long value = (Long ) getValue(fieldNum); 155 return value.longValue(); 156 } 157 158 161 public void storeFloatField(int fieldNum, float value) 162 { 163 } 164 165 168 public float fetchFloatField(int fieldNum) 169 { 170 Float value = (Float ) getValue(fieldNum); 171 return value.floatValue(); 172 } 173 174 177 public void storeDoubleField(int fieldNum, double value) 178 { 179 } 180 181 184 public double fetchDoubleField(int fieldNum) 185 { 186 Double value = (Double ) getValue(fieldNum); 187 return value.doubleValue(); 188 } 189 190 193 public void storeStringField(int fieldNum, String value) 194 { 195 } 196 197 200 public String fetchStringField(int fieldNum) 201 { 202 String value = (String ) getValue(fieldNum); 203 return value; 204 } 205 206 209 public void storeObjectField(int fieldNum, Object value) 210 { 211 } 212 213 216 public Object fetchObjectField(int fieldNum) 217 { 218 Object value = getValue(fieldNum); 219 return value; 220 } 221 222 226 public PersistenceCapable getPc() 227 { 228 return pc; 229 } 230 231 235 public void setPc(PersistenceCapable pc) 236 { 237 this.pc = pc; 238 } 239 240 String getAttributeName(int fieldNum) 241 { 242 JDOClass jdoClass = Helper.getJDOClass(pc.getClass()); 243 JDOField jdoField = jdoClass.getField(fieldNum); 244 String attributeName = jdoField.getName(); 245 return attributeName; 246 } 247 248 252 Object getValue(int fieldNum) 253 { 254 String attributeName = getAttributeName(fieldNum); 255 ClassDescriptor cld = broker.getClassDescriptor(pc.getClass()); 256 257 AttributeDescriptorBase fld = cld.getFieldDescriptorByName(attributeName); 259 if (fld == null) 261 { 262 fld = cld.getObjectReferenceDescriptorByName(attributeName); 263 } 264 if (fld == null) 266 { 267 fld = cld.getCollectionDescriptorByName(attributeName); 268 } 269 Object value = fld.getPersistentField().get(pc); 270 return value; 271 } 272 } 273 | Popular Tags |