1 19 package org.apache.cayenne; 20 21 import java.util.Collection ; 22 import java.util.List ; 23 24 import org.apache.cayenne.graph.GraphManager; 25 import org.apache.cayenne.map.EntityResolver; 26 import org.apache.cayenne.query.ObjectIdQuery; 27 import org.apache.cayenne.query.Query; 28 import org.apache.cayenne.reflect.Property; 29 30 36 public abstract class BaseContext implements ObjectContext { 37 38 protected transient DataChannel channel; 41 42 public abstract void commitChanges(); 43 44 public abstract void commitChangesToParent(); 45 46 public abstract void deleteObject(Object object) throws DeleteDenyException; 47 48 public abstract Collection deletedObjects(); 49 50 public DataChannel getChannel() { 51 return channel; 52 } 53 54 public abstract EntityResolver getEntityResolver(); 55 56 public abstract GraphManager getGraphManager(); 57 58 public abstract Persistent localObject(ObjectId id, Object prototype); 59 60 public abstract Collection modifiedObjects(); 61 62 public abstract Persistent newObject(Class persistentClass); 63 64 public abstract void registerNewObject(Object object); 65 66 public abstract Collection newObjects(); 67 68 public abstract QueryResponse performGenericQuery(Query query); 69 70 public abstract List performQuery(Query query); 71 72 76 public void prepareForAccess(Persistent object, String property) { 77 prepareForAccess(object, property, false); 78 } 79 80 public void prepareForAccess(Persistent object, String property, boolean lazyFaulting) { 81 if (object.getPersistenceState() == PersistenceState.HOLLOW) { 82 83 ObjectId oid = object.getObjectId(); 84 List objects = performQuery(new ObjectIdQuery(oid, false, ObjectIdQuery.CACHE)); 85 86 if (objects.size() == 0) { 87 throw new FaultFailureException( 88 "Error resolving fault, no matching row exists in the database for ObjectId: " 89 + oid); 90 } 91 else if (objects.size() > 1) { 92 throw new FaultFailureException( 93 "Error resolving fault, more than one row exists in the database for ObjectId: " 94 + oid); 95 } 96 97 if (object.getPersistenceState() != PersistenceState.COMMITTED) { 99 100 String state = PersistenceState.persistenceStateName(object 101 .getPersistenceState()); 102 103 106 throw new FaultFailureException( 107 "Error resolving fault for ObjectId: " 108 + oid 109 + " and state (" 110 + state 111 + "). Possible cause - matching row is missing from the database."); 112 } 113 } 114 115 if (lazyFaulting && property != null) { 117 Property propertyDescriptor = getEntityResolver().getClassDescriptor( 118 object.getObjectId().getEntityName()).getProperty(property); 119 120 propertyDescriptor.readProperty(object); 122 } 123 } 124 125 public abstract void propertyChanged( 126 Persistent object, 127 String property, 128 Object oldValue, 129 Object newValue); 130 131 public abstract void rollbackChanges(); 132 133 public abstract void rollbackChangesLocally(); 134 135 public abstract Collection uncommittedObjects(); 136 } 137 | Popular Tags |