KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > access > event > SnapshotEvent


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.access.event;
21
22 import java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.apache.cayenne.event.CayenneEvent;
27
28 /**
29  * Event sent on modification of the DataRowStore.
30  *
31  * @since 1.1
32  * @author Andrus Adamchik
33  */

34 public class SnapshotEvent extends CayenneEvent {
35
36     protected long timestamp;
37     protected Collection JavaDoc deletedIds;
38     protected Collection JavaDoc invalidatedIds;
39     protected Map JavaDoc modifiedDiffs;
40     protected Collection JavaDoc indirectlyModifiedIds;
41
42     public SnapshotEvent(Object JavaDoc source, Object JavaDoc postedBy, Map JavaDoc modifiedDiffs,
43             Collection JavaDoc deletedIds, Collection JavaDoc invalidatedIds,
44             Collection JavaDoc 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 JavaDoc getModifiedDiffs() {
60         return (modifiedDiffs != null) ? modifiedDiffs : Collections.EMPTY_MAP;
61     }
62
63     public Collection JavaDoc getDeletedIds() {
64         return (deletedIds != null) ? deletedIds : Collections.EMPTY_LIST;
65     }
66
67     public Collection JavaDoc getInvalidatedIds() {
68         return (invalidatedIds != null) ? invalidatedIds : Collections.EMPTY_LIST;
69     }
70
71     public Collection JavaDoc getIndirectlyModifiedIds() {
72         return (indirectlyModifiedIds != null)
73                 ? indirectlyModifiedIds
74                 : Collections.EMPTY_LIST;
75     }
76
77     public String JavaDoc toString() {
78         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
79         buffer.append("[SnapshotEvent] source: ").append(getSource());
80
81         Map JavaDoc modified = getModifiedDiffs();
82         if (!modified.isEmpty()) {
83             buffer.append(", modified ").append(modified.size()).append(" id(s)");
84         }
85
86         Collection JavaDoc deleted = getDeletedIds();
87         if (!deleted.isEmpty()) {
88             buffer.append(", deleted ").append(deleted.size()).append(" id(s)");
89         }
90
91         Collection JavaDoc invalidated = getInvalidatedIds();
92         if (!invalidated.isEmpty()) {
93             buffer.append(", invalidated ").append(invalidated.size()).append(" id(s)");
94         }
95
96         Collection JavaDoc 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