KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > DataChannel


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;
21
22 import org.apache.cayenne.event.EventManager;
23 import org.apache.cayenne.event.EventSubject;
24 import org.apache.cayenne.graph.GraphDiff;
25 import org.apache.cayenne.map.EntityResolver;
26 import org.apache.cayenne.query.Query;
27
28 /**
29  * DataChannel is an abstraction used by ObjectContexts to obtain mapping metadata and
30  * access a persistent store. There is rarely a need to use it directly.
31  *
32  * @since 1.2
33  * @author Andrus Adamchik
34  */

35 public interface DataChannel {
36
37     /**
38      * A synchronization type that results in changes from an ObjectContext to be recorded
39      * in the parent DataChannel. If the parent is itself an ObjectContext, changes are
40      * NOT propagated any further.
41      */

42     public static final int FLUSH_NOCASCADE_SYNC = 1;
43
44     /**
45      * A synchronization type that results in changes from an ObjectContext to be recorded
46      * in the parent DataChannel. If the parent is itself an ObjectContext, it is expected
47      * to send its own sync message to its parent DataChannel to cascade sycnhronization
48      * all the way down the stack.
49      */

50     public static final int FLUSH_CASCADE_SYNC = 2;
51
52     /**
53      * A synchronization type that results in cascading rollback of changes through the
54      * DataChannel stack.
55      */

56     public static final int ROLLBACK_CASCADE_SYNC = 3;
57
58     public static final EventSubject GRAPH_CHANGED_SUBJECT = EventSubject.getSubject(
59             DataChannel.class,
60             "graphChanged");
61
62     public static final EventSubject GRAPH_FLUSHED_SUBJECT = EventSubject.getSubject(
63             DataChannel.class,
64             "graphFlushed");
65
66     public static final EventSubject GRAPH_ROLLEDBACK_SUBJECT = EventSubject.getSubject(
67             DataChannel.class,
68             "graphRolledback");
69
70     /**
71      * Returns an EventManager associated with this channel. Channel may return null if
72      * EventManager is not available for any reason.
73      */

74     EventManager getEventManager();
75
76     /**
77      * Returns an EntityResolver instance that contains runtime mapping information.
78      */

79     EntityResolver getEntityResolver();
80
81     /**
82      * Executes a query, using provided <em>context</em> to register persistent objects
83      * if query returns any objects.
84      *
85      * @param originatingContext an ObjectContext that originated the query, used to
86      * register result objects.
87      * @return a generic response object that encapsulates result of the execution.
88      */

89     QueryResponse onQuery(ObjectContext originatingContext, Query query);
90
91     /**
92      * Processes synchronization request from a child ObjectContext, returning a GraphDiff
93      * that describes changes to objects made on the receiving end as a result of
94      * syncronization.
95      * @param originatingContext an ObjectContext that initiated the sync. Can be null.
96      * @param changes diff from the context that initiated the sync.
97      * @param syncType One of {@link #FLUSH_NOCASCADE_SYNC}, {@link #FLUSH_CASCADE_SYNC},
98      * {@link #ROLLBACK_CASCADE_SYNC}.
99      */

100     GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType);
101 }
102
Popular Tags