KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > runtime > Query


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 XQuark Group.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.extractor.runtime;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.xquark.extractor.algebra.Mapper;
29 import org.xquark.extractor.sql.SqlExpression;
30 import org.xquark.extractor.sql.StatementInfo;
31 import org.xquark.xquery.normalize.TransformXQueryExpression;
32 import org.xquark.xquery.parser.XQueryModule;
33
34 /**
35  * An extractor query as an XQuery string and in the compiled form (compilation
36  * is performed by this class).
37  */

38 public class Query {
39
40     private String JavaDoc _query = null;
41     private List JavaDoc _cQuery = null;
42     private QueryFactory _compiler = null;
43     private XQueryModule _module = null;
44
45     // public Query(String query, QueryFactory compiler, XQueryModule module) {
46
// this._query = query;
47
// _compiler = compiler;
48
// }
49

50     public Query(String JavaDoc query, QueryFactory compiler, List JavaDoc compiledQuery, XQueryModule module) {
51         //this(query, compiler, module);
52
_query = query;
53         _compiler = compiler;
54         _cQuery = compiledQuery;
55         _module = module;
56     }
57
58     // public void compile() throws XMLDBCException {
59
// _compiler.compileQuery(_query);
60
// }
61

62     /**
63      * @return Returns the compiled query.
64      */

65     public List JavaDoc getCompiledQuery() {
66         return _cQuery;
67     }
68
69     /**
70      * @return Returns the query as String.
71      */

72     public String JavaDoc getQuery() {
73         return _query;
74     }
75
76     /**
77      * @return Returns the parent module of the query.
78      */

79     public XQueryModule getModule() {
80         return _module;
81     }
82
83     public static class CompiledExpression {
84         public SQLExecutionInfo sqlInfoTree = null;
85         public TransformXQueryExpression expr = null;
86         public CompiledExpression(SQLExecutionInfo sqlInfoTree, TransformXQueryExpression expr) {
87             this.sqlInfoTree = sqlInfoTree;
88             this.expr = expr;
89         }
90     }
91
92     /**
93      * A tree of queries and mapper that let us to postpone the JDBC execution
94      * for subclass prepared statement mainly.
95      */

96     public static class SQLExecutionInfo {
97         public SqlExpression sql = null;
98         public StatementInfo sInfo = null;
99         public Mapper mapper = null;
100         public List JavaDoc childrenQueries = null;
101         public int[] idPosition = null;
102         public int idCount = -1;
103
104         public SQLExecutionInfo() {
105         }
106         public SQLExecutionInfo(SqlExpression sql, Mapper mapper) {
107             this.sql = sql;
108             this.mapper = mapper;
109         }
110         public void addChild(SQLExecutionInfo child) {
111             if (childrenQueries == null)
112                 childrenQueries = new ArrayList JavaDoc();
113             childrenQueries.add(child);
114         }
115         public boolean isUnion() {
116             return (sql == null);
117         }
118     }
119 }
120
Popular Tags