1 56 package org.objectstyle.cayenne.access.event; 57 58 import java.util.Collection ; 59 import java.util.Collections ; 60 import java.util.Map ; 61 62 import org.objectstyle.cayenne.event.CayenneEvent; 63 64 70 public class SnapshotEvent extends CayenneEvent { 71 72 protected long timestamp; 73 protected Collection deletedIds; 74 protected Collection invalidatedIds; 75 protected Map modifiedDiffs; 76 protected Collection indirectlyModifiedIds; 77 78 81 public SnapshotEvent( 82 Object source, 83 Object postedBy, 84 Map modifiedDiffs, 85 Collection deletedIds, 86 Collection indirectlyModifiedIds) { 87 88 this(source, postedBy, modifiedDiffs, deletedIds, Collections.EMPTY_LIST, indirectlyModifiedIds); 89 } 90 91 public SnapshotEvent( 92 Object source, 93 Object postedBy, 94 Map modifiedDiffs, 95 Collection deletedIds, 96 Collection invalidatedIds, 97 Collection indirectlyModifiedIds) { 98 99 super(source, postedBy, null); 100 101 this.timestamp = System.currentTimeMillis(); 102 this.modifiedDiffs = modifiedDiffs; 103 this.deletedIds = deletedIds; 104 this.invalidatedIds = invalidatedIds; 105 this.indirectlyModifiedIds = indirectlyModifiedIds; 106 } 107 108 public long getTimestamp() { 109 return timestamp; 110 } 111 112 public Map getModifiedDiffs() { 113 return (modifiedDiffs != null) ? modifiedDiffs : Collections.EMPTY_MAP; 114 } 115 116 public Collection getDeletedIds() { 117 return (deletedIds != null) ? deletedIds : Collections.EMPTY_LIST; 118 } 119 120 public Collection getInvalidatedIds() { 121 return (invalidatedIds != null) ? invalidatedIds : Collections.EMPTY_LIST; 122 } 123 124 public Collection getIndirectlyModifiedIds() { 125 return (indirectlyModifiedIds != null) ? indirectlyModifiedIds : Collections.EMPTY_LIST; 126 } 127 128 public String toString() { 129 StringBuffer buffer = new StringBuffer (); 130 buffer.append("[SnapshotEvent] source: ").append(getSource()); 131 132 Map modified = getModifiedDiffs(); 133 if (!modified.isEmpty()) { 134 buffer.append(", modified ").append(modified.size()).append(" id(s)"); 135 } 136 137 Collection deleted = getDeletedIds(); 138 if (!deleted.isEmpty()) { 139 buffer.append(", deleted ").append(deleted.size()).append(" id(s)"); 140 } 141 142 Collection invalidated = getInvalidatedIds(); 143 if (!invalidated.isEmpty()) { 144 buffer.append(", invalidated ").append(invalidated.size()).append(" id(s)"); 145 } 146 147 Collection related = getIndirectlyModifiedIds(); 148 if (!related.isEmpty()) { 149 buffer.append(", indirectly modified ").append(related.size()).append(" id(s)"); 150 } 151 152 return buffer.toString(); 153 } 154 } 155 | Popular Tags |