1 package org.bsf.smartValueObject; 2 3 7 public class Version implements Versionable { 8 private long timestamp; 9 private boolean dirty; 10 private boolean created; 11 private boolean deleted; 12 private final boolean debug = false; 13 14 17 public Version() { 18 markClean(); 19 create(); } 21 22 26 public Version(Object o) { 27 this(); 28 } 29 30 public void touch() { 31 touch("unknown"); 32 } 33 34 public void touch(String field) { 35 if (debug) 36 System.out.println("touched (" + field + ") @ " + 37 this.timestamp); 38 dirty = true; 39 } 40 41 public void delete() { 42 deleted = true; 43 created = false; 44 dirty = true; 45 } 46 47 public void create() { 48 deleted = false; 49 created = true; 50 dirty = true; 51 } 52 53 public boolean isCreated() { 54 return created; 55 } 56 57 public boolean isDeleted() { 58 return deleted; 59 } 60 61 public boolean isDirty() { 62 return dirty; 63 } 64 65 public void markClean() { 66 deleted = dirty = created = false; 67 this.timestamp = System.currentTimeMillis(); 68 } 69 70 73 public long getVersionId() { 74 return timestamp; 75 } 76 77 80 public void setVersionId(long id) { 81 this.timestamp = id; 82 } 83 84 public String toString() { 85 return "Version [timestamp: " + this.timestamp + 86 " dirty:" + (dirty ? "yes" : "no") + 87 " created:" + (created ? "yes" : "no") + 88 " deleted:" + (deleted ? "yes" : "no") + 89 "]"; 90 } 91 } 92 93 | Popular Tags |