KickJava   Java API By Example, From Geeks To Geeks.

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


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;
21
22 import org.apache.cayenne.DataObject;
23 import org.apache.cayenne.DataRow;
24 import org.apache.cayenne.query.Query;
25
26 /**
27  * Defines API for a DataContext "delegate" - an object that is temporarily passed control
28  * by DataContext at some critical points in the normal flow of execution. A delegate thus
29  * can modify the flow, abort an operation, modify the objects participating in an
30  * operation, or perform any other tasks it deems necessary. DataContextDelegate is shared
31  * by DataContext and its ObjectStore.
32  *
33  * @see org.apache.cayenne.access.DataContext
34  * @author Mike Kienenberger
35  * @author Andrus Adamchik
36  * @since 1.1
37  */

38 public interface DataContextDelegate {
39
40     /**
41      * Invoked before a Query is executed via <em>DataContext.performQuery</em>. The
42      * delegate may subsitute the Query with a different one or may return null to discard
43      * the query.
44      *
45      * @since 1.2
46      */

47     Query willPerformQuery(DataContext context, Query query);
48
49     /**
50      * Invoked before a Query is executed via <em>DataContext.performGenericQuery</em>.
51      * The delegate may subsitute the Query with a different one or may return null to
52      * discard the query.
53      *
54      * @since 1.2
55      */

56     Query willPerformGenericQuery(DataContext context, Query query);
57
58     /**
59      * Invoked by parent DataContext whenever an object change is detected. This can be a
60      * change to the object snapshot, or a modification of an "independent" relationship
61      * not resulting in a snapshot change. In the later case snapshot argument may be
62      * null. If a delegate returns <code>true</code>, ObjectStore will attempt to merge
63      * the changes into an object.
64      */

65     boolean shouldMergeChanges(DataObject object, DataRow snapshotInStore);
66
67     /**
68      * Called after a successful merging of external changes to an object. If previosly a
69      * delegate returned <code>false</code> from
70      * {@link #shouldMergeChanges(DataObject, DataRow)}, this method is not invoked,
71      * since changes were not merged.
72      */

73     void finishedMergeChanges(DataObject object);
74
75     /**
76      * Invoked by ObjectStore whenever it is detected that a database row was deleted for
77      * object. If a delegate returns <code>true</code>, ObjectStore will change
78      * MODIFIED objects to NEW (resulting in recreating the deleted record on next commit)
79      * and all other objects - to TRANSIENT. To block this behavior, delegate should
80      * return <code>false</code>, and possibly do its own processing.
81      *
82      * @param object DataObject that was deleted externally and is still present in the
83      * ObjectStore associated with the delegate.
84      */

85     boolean shouldProcessDelete(DataObject object);
86
87     /**
88      * Called after a successful processing of externally deleted object. If previosly a
89      * delegate returned <code>false</code> from
90      * {@link #shouldProcessDelete(DataObject)}, this method is not invoked, since no
91      * processing was done.
92      */

93     void finishedProcessDelete(DataObject object);
94 }
95
Popular Tags