1 19 20 package org.apache.cayenne.access.event; 21 22 import java.util.Collection ; 23 import java.util.Collections ; 24 import java.util.Map ; 25 26 import org.apache.cayenne.event.CayenneEvent; 27 28 34 public class SnapshotEvent extends CayenneEvent { 35 36 protected long timestamp; 37 protected Collection deletedIds; 38 protected Collection invalidatedIds; 39 protected Map modifiedDiffs; 40 protected Collection indirectlyModifiedIds; 41 42 public SnapshotEvent(Object source, Object postedBy, Map modifiedDiffs, 43 Collection deletedIds, Collection invalidatedIds, 44 Collection indirectlyModifiedIds) { 45 46 super(source, postedBy, null); 47 48 this.timestamp = System.currentTimeMillis(); 49 this.modifiedDiffs = modifiedDiffs; 50 this.deletedIds = deletedIds; 51 this.invalidatedIds = invalidatedIds; 52 this.indirectlyModifiedIds = indirectlyModifiedIds; 53 } 54 55 public long getTimestamp() { 56 return timestamp; 57 } 58 59 public Map getModifiedDiffs() { 60 return (modifiedDiffs != null) ? modifiedDiffs : Collections.EMPTY_MAP; 61 } 62 63 public Collection getDeletedIds() { 64 return (deletedIds != null) ? deletedIds : Collections.EMPTY_LIST; 65 } 66 67 public Collection getInvalidatedIds() { 68 return (invalidatedIds != null) ? invalidatedIds : Collections.EMPTY_LIST; 69 } 70 71 public Collection getIndirectlyModifiedIds() { 72 return (indirectlyModifiedIds != null) 73 ? indirectlyModifiedIds 74 : Collections.EMPTY_LIST; 75 } 76 77 public String toString() { 78 StringBuffer buffer = new StringBuffer (); 79 buffer.append("[SnapshotEvent] source: ").append(getSource()); 80 81 Map modified = getModifiedDiffs(); 82 if (!modified.isEmpty()) { 83 buffer.append(", modified ").append(modified.size()).append(" id(s)"); 84 } 85 86 Collection deleted = getDeletedIds(); 87 if (!deleted.isEmpty()) { 88 buffer.append(", deleted ").append(deleted.size()).append(" id(s)"); 89 } 90 91 Collection invalidated = getInvalidatedIds(); 92 if (!invalidated.isEmpty()) { 93 buffer.append(", invalidated ").append(invalidated.size()).append(" id(s)"); 94 } 95 96 Collection related = getIndirectlyModifiedIds(); 97 if (!related.isEmpty()) { 98 buffer.append(", indirectly modified ").append(related.size()).append( 99 " id(s)"); 100 } 101 102 return buffer.toString(); 103 } 104 } 105 | Popular Tags |