KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > storage > InteractiveQueryExplorer


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
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 /*
24  * QueryExplorer.java
25  *
26  * Created on 18 avril 2002, 17:15
27  */

28
29 package org.xquark.mapper.storage;
30
31 import java.sql.SQLException JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Map JavaDoc;
35
36 import org.apache.commons.logging.Log;
37 import org.apache.commons.logging.LogFactory;
38 import org.xquark.mapper.RepositoryException;
39 import org.xquark.mapper.dbms.AbstractConnection;
40 import org.xquark.mapper.dbms.TableSpec;
41 import org.xquark.mapper.mapping.TableMapping;
42 import org.xquark.mapper.metadata.CollectionMappingInfo;
43 import org.xquark.mapper.metadata.CollectionMetadata;
44 import org.xquark.xml.xdbc.XMLDBCException;
45
46 /**
47  *
48  */

49 class InteractiveQueryExplorer extends QueryExplorer
50 {
51     private static final String JavaDoc RCSRevision = "$Revision: 1.2 $";
52     private static final String JavaDoc RCSName = "$Name: $";
53     
54     private static Log log = LogFactory.getLog(InteractiveQueryExplorer.class);
55     
56     /** Creates a new instance of QueryExplorer */
57     InteractiveQueryExplorer(_RepositoryCollection collection) throws SQLException JavaDoc, XMLDBCException
58     {
59         super(collection);
60         AbstractConnection connection = collection.getRepositoryConnection().getConnection();
61         CollectionMetadata meta = collection.getMetadata();
62         wNode = qNode = new InteractiveQueryStructExplorer(meta.getTableInfo(TableSpec.TYPE_STRUCT), meta.getUOIDManager());
63         extraNode = qExtraNode = new InteractiveQueryExtraDataExplorer(meta.getTableInfo(TableSpec.TYPE_EXTRA));
64     }
65     
66     /** Perform Tuple allocation and therefore query execution
67      * @param subPaths a {PathNode subPath, PathNode variablePath} map giving
68      * for an absolute subpath the variable root path
69      * @param varPaths 0 index PathNode contains the variable root path other are
70      * this path subpaths
71      */

72     void initExploration(VarInfoSet varInfoSet, AbstractConnection connection)
73     throws SQLException JavaDoc, XMLDBCException
74     {
75         if (log.isDebugEnabled())
76             log.debug("QueryExplorer::initExploration [varInfoSet]=" + varInfoSet);
77         
78         // Table partitioning
79
Object JavaDoc[] ret = dispatchSubPaths(varInfoSet);
80         Map JavaDoc tableMappingSubset = (Map JavaDoc)ret[0];
81         List JavaDoc subPathNodes = (List JavaDoc)ret[1];
82         
83         // Table subset browsing for statement execution
84
Iterator JavaDoc it = tableMappingSubset.entrySet().iterator();
85         Map.Entry JavaDoc entry;
86         CollectionMappingInfo tableStmts;
87         int tableIndex;
88         
89         CollectionMetadata meta = collection.getMetadata();
90         while (it.hasNext())
91         {
92             entry = (Map.Entry JavaDoc)it.next();
93             tableIndex = ((TableMapping)entry.getKey()).getTableIndex();
94             tableStmts = (CollectionMappingInfo)meta.getMappingStatements(tableIndex);
95             if (queryTuples[tableIndex] == null)
96                 queryTuples[tableIndex] = new InteractiveQueryTuple(tableStmts, meta.getMappingPID(tableIndex));
97             ((InteractiveQueryTuple)queryTuples[tableIndex]).prepareStatement((List JavaDoc)entry.getValue(),
98             meta, connection);
99         }
100         
101         // initialize structure retrieval
102
((InteractiveQueryStructExplorer)qNode).prepareStatement(subPathNodes, connection);
103         ((InteractiveQueryExtraDataExplorer)qExtraNode).prepareStatement(subPathNodes, connection);
104     }
105     
106     void execQuery(long first, long last, short path) throws SQLException JavaDoc, RepositoryException
107     {
108         for (int i=0; i < queryTuples.length; i++)
109         {
110             if (queryTuples[i] != null)
111                 ((InteractiveQueryTuple)queryTuples[i]).execQuery(first, last, path);
112         }
113         ((InteractiveQueryStructExplorer)qNode).execQuery(first, last, path);
114         ((InteractiveQueryExtraDataExplorer)qExtraNode).execQuery(first, last, path);
115     }
116 }
117
Popular Tags