1 2 12 package com.versant.core.jdo; 13 14 import com.versant.core.common.BindingSupportImpl; 15 import com.versant.core.metadata.FieldMetaData; 16 import com.versant.core.metadata.ClassMetaData; 17 import com.versant.core.metadata.ModelMetaData; 18 19 import javax.jdo.spi.StateManager; 20 import javax.jdo.spi.PersistenceCapable; 21 import javax.jdo.spi.JDOImplHelper; 22 import javax.jdo.PersistenceManager; 23 24 25 26 28 public class EmbeddedStateManager implements StateManager 29 { 30 public PCStateMan owner; 31 public PersistenceCapable pc; 32 public ClassMetaData cmd; 33 public ModelMetaData jmd; 34 public FieldMetaData owningFmd; 35 38 private byte jdoFlags = PersistenceCapable.LOAD_REQUIRED; 39 40 public EmbeddedStateManager(PCStateMan owner, ModelMetaData jmd, 41 JDOImplHelper jdoImplHelper, FieldMetaData fmd) { 42 Class cls = fmd.typeMetaData.cls; 43 owningFmd = fmd; 44 this.jmd = jmd; 45 this.owner = owner; 46 pc = jdoImplHelper.newInstance(cls, this); 47 cmd = jmd.getClassMetaData(cls); 48 } 49 50 public EmbeddedStateManager(PCStateMan owner, PersistenceCapable pc, 51 ModelMetaData jmd, FieldMetaData fmd) { 52 this.owningFmd = fmd; 53 this.jmd = jmd; 54 this.owner = owner; 55 this.pc = pc; 56 cmd = jmd.getClassMetaData(pc.getClass()); 57 } 58 59 public void setLoadRequired() { 60 jdoFlags = PersistenceCapable.LOAD_REQUIRED; 61 pc.jdoReplaceFlags(); 62 } 63 64 public byte replacingFlags(PersistenceCapable pc) { 65 return jdoFlags; 66 } 67 68 public StateManager replacingStateManager(PersistenceCapable pc, StateManager sm) { 69 return sm; 70 } 71 72 public boolean isDirty(PersistenceCapable pc) { 73 return owner.isDirty(); 74 } 75 76 public boolean isTransactional(PersistenceCapable pc) { 77 return owner.isTransactional(pc); 78 } 79 80 public boolean isPersistent(PersistenceCapable pc) { 81 return owner.isPersistent(pc); 82 } 83 84 public boolean isNew(PersistenceCapable pc) { 85 return owner.isNew(pc); 86 } 87 88 public boolean isDeleted(PersistenceCapable pc) { 89 return owner.isDeleted(pc); 90 } 91 92 public PersistenceManager getPersistenceManager(PersistenceCapable pc) { 93 return owner.getPersistenceManager(pc); 94 } 95 96 public void makeDirty(PersistenceCapable pc, String fieldName) { 97 owner.makeDirty(pc, fieldName); 98 } 99 100 public Object getObjectId(PersistenceCapable pc) { 101 throwNotImplemented(); 102 return null; } 104 105 public Object getTransactionalObjectId(PersistenceCapable pc) { 106 throwNotImplemented(); 107 return null; } 109 110 public boolean isLoaded(PersistenceCapable pc, int field) { 111 return owner.isLoaded(pc, getFmd(field)); 112 } 113 114 public void preSerialize(PersistenceCapable pc) { 115 throwNotImplemented(); 116 } 117 118 public boolean getBooleanField(PersistenceCapable pc, int field, boolean currentValue) { 119 return owner.getBooleanFieldImp(pc, getFmd(field), currentValue); 120 } 121 122 public char getCharField(PersistenceCapable pc, int field, char currentValue) { 123 return owner.getCharFieldImp(pc, getFmd(field), currentValue); 124 } 125 126 public byte getByteField(PersistenceCapable pc, int field, byte currentValue) { 127 return owner.getByteFieldImp(pc, getFmd(field), currentValue); 128 } 129 130 public short getShortField(PersistenceCapable pc, int field, short currentValue) { 131 return owner.getShortFieldImp(pc, getFmd(field), currentValue); 132 } 133 134 public int getIntField(PersistenceCapable pc, int field, int currentValue) { 135 return owner.getIntFieldImp(pc, getFmd(field), currentValue); 136 } 137 138 public long getLongField(PersistenceCapable pc, int field, long currentValue) { 139 return owner.getLongFieldImp(pc, getFmd(field), currentValue); 140 } 141 142 public float getFloatField(PersistenceCapable pc, int field, float currentValue) { 143 return owner.getFloatFieldImp(pc, getFmd(field), currentValue); 144 } 145 146 public double getDoubleField(PersistenceCapable pc, int field, double currentValue) { 147 return owner.getDoubleFieldImp(pc, getFmd(field), currentValue); 148 } 149 150 public String getStringField(PersistenceCapable pc, int field, String currentValue) { 151 return owner.getStringFieldImp(pc, getFmd(field), currentValue); 152 } 153 154 public Object getObjectField(PersistenceCapable pc, int field, Object currentValue) { 155 return owner.getObjectFieldImp(pc, getFmd(field), currentValue); 156 } 157 158 public void setBooleanField(PersistenceCapable pc, int field, boolean currentValue, boolean newValue) { 159 owner.setBooleanFieldImp(this.pc, getFmd(field), currentValue, newValue); 160 pc.jdoReplaceField(field); 161 } 162 163 public void setCharField(PersistenceCapable pc, int field, char currentValue, char newValue) { 164 owner.setCharFieldImp(this.pc, getFmd(field), currentValue, newValue); 165 pc.jdoReplaceField(field); 166 } 167 168 public void setByteField(PersistenceCapable pc, int field, byte currentValue, byte newValue) { 169 owner.setByteFieldImp(this.pc, getFmd(field), currentValue, newValue); 170 pc.jdoReplaceField(field); 171 } 172 173 public void setShortField(PersistenceCapable pc, int field, short currentValue, short newValue) { 174 owner.setShortFieldImp(this.pc, getFmd(field), currentValue, newValue); 175 pc.jdoReplaceField(field); 176 } 177 178 public void setIntField(PersistenceCapable pc, int field, int currentValue, int newValue) { 179 owner.setIntFieldImp(this.pc, getFmd(field), currentValue, newValue); 180 pc.jdoReplaceField(field); 181 } 182 183 public void setLongField(PersistenceCapable pc, int field, long currentValue, long newValue) { 184 owner.setLongFieldImp(this.pc, getFmd(field), currentValue, newValue); 185 pc.jdoReplaceField(field); 186 } 187 188 public void setFloatField(PersistenceCapable pc, int field, float currentValue, float newValue) { 189 owner.setFloatFieldImp(this.pc, getFmd(field), currentValue, newValue); 190 pc.jdoReplaceField(field); 191 } 192 193 public void setDoubleField(PersistenceCapable pc, int field, double currentValue, double newValue) { 194 owner.setDoubleFieldImp(this.pc, getFmd(field), currentValue, newValue); 195 pc.jdoReplaceField(field); 196 } 197 198 public void setStringField(PersistenceCapable pc, int field, 199 String currentValue, String newValue) { 200 owner.setStringFieldImp(this.pc, getFmd(field), currentValue, newValue); 201 pc.jdoReplaceField(field); 202 } 203 204 public void setObjectField(PersistenceCapable pc, int field, Object currentValue, Object newValue) { 205 owner.setObjectFieldImp(this.pc, getFmd(field), currentValue, newValue); 206 pc.jdoReplaceField(field); 207 } 208 209 210 211 private FieldMetaData getFmd(int fieldNo) { 212 return owningFmd.managedEmbeddedFields[fieldNo]; 213 } 223 224 public void providedBooleanField(PersistenceCapable pc, int field, boolean currentValue) { 225 owner.providedBooleanFieldImp(pc, getFmd(field), currentValue); 226 } 227 228 public void providedCharField(PersistenceCapable pc, int field, char currentValue) { 229 owner.providedCharFieldImp(pc, getFmd(field), currentValue); 230 } 231 232 public void providedByteField(PersistenceCapable pc, int field, byte currentValue) { 233 owner.providedByteFieldImp(pc, getFmd(field), currentValue); 234 } 235 236 public void providedShortField(PersistenceCapable pc, int field, short currentValue) { 237 owner.providedShortFieldImp(pc, getFmd(field), currentValue); 238 } 239 240 public void providedIntField(PersistenceCapable pc, int field, int currentValue) { 241 owner.providedIntFieldImp(pc, getFmd(field), currentValue); 242 } 243 244 public void providedLongField(PersistenceCapable pc, int field, long currentValue) { 245 owner.providedLongFieldImp(pc, getFmd(field), currentValue); 246 } 247 248 public void providedFloatField(PersistenceCapable pc, int field, float currentValue) { 249 owner.providedFloatFieldImp(pc, getFmd(field), currentValue); 250 } 251 252 public void providedDoubleField(PersistenceCapable pc, int field, double currentValue) { 253 owner.providedDoubleFieldImp(pc, getFmd(field), currentValue); 254 } 255 256 public void providedStringField(PersistenceCapable pc, int field, String currentValue) { 257 owner.providedStringFieldImp(pc, getFmd(field), currentValue); 258 } 259 260 public void providedObjectField(PersistenceCapable pc, int field, Object currentValue) { 261 owner.providedObjectFieldImp(pc, getFmd(field), currentValue); 262 } 263 264 265 public boolean replacingBooleanField(PersistenceCapable pc, int field) { 266 return owner.replacingBooleanFieldImp(pc, getFmd(field)); 267 } 268 269 public char replacingCharField(PersistenceCapable pc, int field) { 270 return owner.replacingCharFieldImp(pc, getFmd(field)); 271 } 272 273 public byte replacingByteField(PersistenceCapable pc, int field) { 274 return owner.replacingByteFieldImp(pc, getFmd(field)); 275 } 276 277 public short replacingShortField(PersistenceCapable pc, int field) { 278 return owner.replacingShortFieldImp(pc, getFmd(field)); 279 } 280 281 public int replacingIntField(PersistenceCapable pc, int field) { 282 return owner.replacingIntFieldImp(pc, getFmd(field)); 283 } 284 285 public long replacingLongField(PersistenceCapable pc, int field) { 286 return owner.replacingLongFieldImp(pc, getFmd(field)); 287 } 288 289 public float replacingFloatField(PersistenceCapable pc, int field) { 290 return owner.replacingFloatFieldImp(pc, getFmd(field)); 291 } 292 293 public double replacingDoubleField(PersistenceCapable pc, int field) { 294 return owner.replacingDoubleFieldImp(pc, getFmd(field)); 295 } 296 297 public String replacingStringField(PersistenceCapable pc, int field) { 298 return owner.replacingStringFieldImp(pc, getFmd(field)); 299 } 300 301 public Object replacingObjectField(PersistenceCapable pc, int field) { 302 return owner.replacingObjectFieldImp(pc, getFmd(field)); 303 } 304 305 private void throwNotImplemented() { 306 throw BindingSupportImpl.getInstance().invalidOperation("Not implememted"); 307 } 308 309 310 311 312 313 314 315 316 317 } 318 | Popular Tags |