1 19 20 package org.apache.cayenne; 21 22 35 public abstract class PersistentObject implements Persistent { 36 37 protected ObjectId objectId; 38 protected int persistenceState; 39 protected transient ObjectContext objectContext; 40 41 44 public PersistentObject() { 45 this.persistenceState = PersistenceState.TRANSIENT; 46 } 47 48 public int getPersistenceState() { 49 return persistenceState; 50 } 51 52 public void setPersistenceState(int persistenceState) { 53 this.persistenceState = persistenceState; 54 55 if (persistenceState == PersistenceState.TRANSIENT) { 56 setObjectContext(null); 57 } 58 } 59 60 public ObjectContext getObjectContext() { 61 return objectContext; 62 } 63 64 public void setObjectContext(ObjectContext objectContext) { 65 this.objectContext = objectContext; 66 } 67 68 public ObjectId getObjectId() { 69 return objectId; 70 } 71 72 public void setObjectId(ObjectId objectId) { 73 this.objectId = objectId; 74 } 75 76 public String toString() { 77 String state = PersistenceState.persistenceStateName(getPersistenceState()); 78 79 StringBuffer buffer = new StringBuffer (); 80 buffer 81 .append("<") 82 .append(getClass().getName()) 83 .append("@") 84 .append(System.identityHashCode(this)) 85 .append(", id=") 86 .append(objectId) 87 .append(", state=") 88 .append(state) 89 .append(", context=") 90 .append(objectContext) 91 .append(">"); 92 93 return buffer.toString(); 94 } 95 } 96 | Popular Tags |