KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.sql.Connection JavaDoc;
23 import java.sql.SQLException JavaDoc;
24 import java.util.List JavaDoc;
25
26 import org.apache.cayenne.query.Query;
27 import org.apache.cayenne.query.SQLAction;
28
29 /**
30  * A helper that executes a sequence of queries, providing correct mapping of the results
31  * to the original query. Note that this class is not thread-safe as it stores current
32  * query execution state.
33  *
34  * @since 1.2
35  * @author Andrus Adamchik
36  */

37 class DataNodeQueryAction implements OperationObserver {
38
39     OperationObserver observer;
40     DataNode node;
41
42     private Query currentQuery;
43
44     public DataNodeQueryAction(DataNode node, OperationObserver observer) {
45         this.observer = observer;
46         this.node = node;
47     }
48
49     public void runQuery(Connection JavaDoc connection, Query query) throws SQLException JavaDoc,
50             Exception JavaDoc {
51
52         // remember root query ... it will be used to map the results, even if SQLAction
53
// uses query substitute...
54
this.currentQuery = query;
55
56         SQLAction action = node.getAdapter().getAction(query, node);
57         action.performAction(connection, this);
58     }
59
60     public void nextBatchCount(Query query, int[] resultCount) {
61         observer.nextBatchCount(currentQuery, resultCount);
62     }
63
64     public void nextCount(Query query, int resultCount) {
65         observer.nextCount(currentQuery, resultCount);
66     }
67
68     public void nextDataRows(Query query, List JavaDoc dataRows) {
69         observer.nextDataRows(currentQuery, dataRows);
70     }
71
72     public void nextDataRows(Query q, ResultIterator it) {
73         observer.nextDataRows(currentQuery, it);
74     }
75
76     public void nextGeneratedDataRows(Query query, ResultIterator keysIterator) {
77         observer.nextGeneratedDataRows(currentQuery, keysIterator);
78     }
79
80     public void nextGlobalException(Exception JavaDoc ex) {
81         observer.nextGlobalException(ex);
82     }
83
84     public void nextQueryException(Query query, Exception JavaDoc ex) {
85         observer.nextQueryException(currentQuery, ex);
86     }
87
88     public boolean isIteratedResult() {
89         return observer.isIteratedResult();
90     }
91 }
92
Popular Tags