KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > access > DataContextGraphAction


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 package org.apache.cayenne.access;
20
21 import org.apache.cayenne.Persistent;
22 import org.apache.cayenne.reflect.ArcProperty;
23 import org.apache.cayenne.util.ObjectContextGraphAction;
24
25 /**
26  * An action object that processes graph change calls from Persistent objects. It handles
27  * GraphManager notifications and bi-directional graph consistency. The main difference
28  * with CayenneContextGraph action is that reverse relationships are handled by the
29  * objects themselves.
30  *
31  * @since 3.0
32  * @author Andrus Adamchik
33  */

34 class DataContextGraphAction extends ObjectContextGraphAction {
35
36     DataContextGraphAction(DataContext context) {
37         super(context);
38     }
39
40     protected void handleSimplePropertyChange(
41             Persistent object,
42             String JavaDoc propertyName,
43             Object JavaDoc oldValue,
44             Object JavaDoc newValue) {
45
46         // for simple properties ObjectStore requires a callback only the first time the
47
// object changes
48
if (markAsDirty(object)) {
49             context.getGraphManager().nodePropertyChanged(
50                     object.getObjectId(),
51                     propertyName,
52                     oldValue,
53                     newValue);
54         }
55     }
56
57     protected void handleArcPropertyChange(
58             Persistent object,
59             ArcProperty property,
60             Object JavaDoc oldValue,
61             Object JavaDoc newValue) {
62
63         if (oldValue != newValue) {
64             markAsDirty(object);
65
66             if (oldValue instanceof Persistent) {
67                 context.getGraphManager().arcDeleted(
68                         object.getObjectId(),
69                         ((Persistent) oldValue).getObjectId(),
70                         property.getName());
71             }
72
73             if (newValue instanceof Persistent) {
74                 context.getGraphManager().arcCreated(
75                         object.getObjectId(),
76                         ((Persistent) newValue).getObjectId(),
77                         property.getName());
78             }
79         }
80     }
81 }
82
Popular Tags