1 56 package org.objectstyle.cayenne; 57 58 import org.apache.commons.lang.builder.ToStringBuilder; 59 60 66 public abstract class PersistentObject implements Persistent { 67 68 protected Object oid; 69 protected int persistenceState; 70 protected transient ObjectContext objectContext; 71 72 public PersistentObject() { 73 this.persistenceState = PersistenceState.TRANSIENT; 74 } 75 76 79 protected void willRead(String property) { 80 if (objectContext != null) { 81 objectContext.objectWillRead(this, property); 82 } 83 } 84 85 88 protected void willWrite(String property, Object oldValue, Object newValue) { 89 if (objectContext != null) { 90 objectContext.objectWillWrite(this, property, oldValue, newValue); 91 } 92 } 93 94 public int getPersistenceState() { 95 return persistenceState; 96 } 97 98 public void setPersistenceState(int persistenceState) { 99 this.persistenceState = persistenceState; 100 101 if (persistenceState == PersistenceState.TRANSIENT) { 102 this.objectContext = null; 103 } 104 } 105 106 public ObjectContext getObjectContext() { 107 return objectContext; 108 } 109 110 public void setObjectContext(ObjectContext objectContext) { 111 this.objectContext = objectContext; 112 } 113 114 public Object getOid() { 115 return oid; 116 } 117 118 public void setOid(Object oid) { 119 this.oid = oid; 120 } 121 122 public String toString() { 123 return ToStringBuilder.reflectionToString(this); 124 } 125 } | Popular Tags |