KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > remote > SyncMessage


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.remote;
21
22 import org.apache.cayenne.DataChannel;
23 import org.apache.cayenne.ObjectContext;
24 import org.apache.cayenne.graph.GraphDiff;
25
26 /**
27  * A message used for synchronization of the child with parent. It defines a few types of
28  * synchronization: "flush" (when the child sends its changes without a commit), "commit"
29  * (cascading flush with ultimate commit to the database), and "rollback" - cascading
30  * reverting of all uncommitted changes.
31  *
32  * @since 1.2
33  * @author Andrus Adamchik
34  */

35 public class SyncMessage implements ClientMessage {
36
37     protected transient ObjectContext source;
38     protected int type;
39     protected GraphDiff senderChanges;
40
41     // private constructor for Hessian deserialization
42
private SyncMessage() {
43
44     }
45
46     public SyncMessage(ObjectContext source, int syncType, GraphDiff senderChanges) {
47         // validate type
48
if (syncType != DataChannel.FLUSH_NOCASCADE_SYNC
49                 && syncType != DataChannel.FLUSH_CASCADE_SYNC
50                 && syncType != DataChannel.ROLLBACK_CASCADE_SYNC) {
51             throw new IllegalArgumentException JavaDoc("'type' is invalid: " + syncType);
52         }
53
54         this.source = source;
55         this.type = syncType;
56         this.senderChanges = senderChanges;
57     }
58
59     /**
60      * Returns a source of SyncMessage.
61      */

62     public ObjectContext getSource() {
63         return source;
64     }
65
66     public int getType() {
67         return type;
68     }
69
70     public GraphDiff getSenderChanges() {
71         return senderChanges;
72     }
73
74     public String JavaDoc toString() {
75         switch (type) {
76             case DataChannel.FLUSH_NOCASCADE_SYNC:
77                 return "flush-sync";
78             case DataChannel.FLUSH_CASCADE_SYNC:
79                 return "flush-cascade-sync";
80             case DataChannel.ROLLBACK_CASCADE_SYNC:
81                 return "rollback-cascade-sync";
82             default:
83                 return "unknown-sync";
84         }
85     }
86 }
87
Popular Tags