1 19 package org.apache.cayenne.util; 20 21 import java.io.Serializable ; 22 23 import org.apache.cayenne.ObjectContext; 24 import org.apache.cayenne.PersistenceState; 25 import org.apache.cayenne.Persistent; 26 import org.apache.cayenne.reflect.ArcProperty; 27 import org.apache.cayenne.reflect.ClassDescriptor; 28 import org.apache.cayenne.reflect.Property; 29 30 38 public abstract class ObjectContextGraphAction implements Serializable { 39 40 protected ObjectContext context; 41 42 public ObjectContextGraphAction(ObjectContext context) { 43 this.context = context; 44 } 45 46 51 public void handlePropertyChange( 52 Persistent object, 53 String propertyName, 54 Object oldValue, 55 Object newValue) { 56 57 60 ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor( 61 object.getObjectId().getEntityName()); 62 Property property = descriptor.getProperty(propertyName); 63 64 if (property instanceof ArcProperty) { 65 handleArcPropertyChange(object, (ArcProperty) property, oldValue, newValue); 66 } 67 else { 68 handleSimplePropertyChange(object, propertyName, oldValue, newValue); 69 } 70 } 71 72 protected abstract void handleArcPropertyChange( 73 Persistent object, 74 ArcProperty property, 75 Object oldValue, 76 Object newValue); 77 78 protected abstract void handleSimplePropertyChange( 79 Persistent object, 80 String propertyName, 81 Object oldValue, 82 Object newValue); 83 84 88 protected boolean markAsDirty(Persistent object) { 89 if (object.getPersistenceState() == PersistenceState.COMMITTED) { 90 object.setPersistenceState(PersistenceState.MODIFIED); 91 return true; 92 } 93 94 return false; 95 } 96 } 97 | Popular Tags |