KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
33
34 import org.xquark.mapper.dbms.AbstractConnection;
35 import org.xquark.mapper.mapping.TableMapping;
36 import org.xquark.xml.xdbc.XMLDBCException;
37
38 /**
39  *
40  */

41 abstract class QueryExplorer extends TableExplorer
42 {
43     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
44     private static final String JavaDoc RCSName = "$Name: $";
45     protected QueryTuple[] queryTuples;
46     protected QueryStructExplorer qNode;
47     protected QueryExtraDataExplorer qExtraNode;
48     private int subPathCount;
49     
50     /** Creates a new instance of QueryExplorer */
51     QueryExplorer(_RepositoryCollection collection) throws SQLException JavaDoc, XMLDBCException
52     {
53         super(collection);
54         
55         // tuples creation performed at execution (only if needed)
56
tuples = queryTuples =
57             new QueryTuple[collection.getMetadata().getMappingStatementsCount()];
58     }
59     
60     int getSubPathCount()
61     {
62         return subPathCount;
63     }
64     
65     /**
66      * Method dispatchSubPaths.
67      * @param varInfoSet
68      * @return Object[]
69      */

70     protected Object JavaDoc[] dispatchSubPaths(VarInfoSet varInfoSet)
71     {
72         HashMap tableMappingSubset = new HashMap();
73         SubPathInfo subPathInfo;
74         ArrayList subPathNodes = new ArrayList();
75         TableMapping table;
76         List tablePaths;
77
78         // Table partitioning
79
List rangeList = varInfoSet.getExpandedPathList();
80         List subPathList;
81         ExpandedPathInfoSet expandedPathInfo;
82         int expandedPathCount = rangeList.size();
83         
84         for (int i = 0; i < expandedPathCount; i++)
85         {
86             expandedPathInfo = (ExpandedPathInfoSet)rangeList.get(i);
87             subPathList = expandedPathInfo.getSubPaths();
88             subPathCount = subPathList.size();
89             
90             for (int j = 0; j < subPathCount; j++)
91             {
92                 SubPathInfoSet subPathInfoSet = (SubPathInfoSet)subPathList.get(j);
93                 subPathInfo = new SubPathInfo(
94                 subPathInfoSet.getSubPath(),
95                 j+1,
96                 subPathInfoSet.getText(),
97                 expandedPathInfo.getPhysicalPath());
98                 subPathNodes.add(subPathInfo);
99                 
100                 if ((subPathInfo.subPath.getBuildMappings() == null) || subPathInfo.isText) // pure column mapping (not generic)
101
{
102                     table = subPathInfo.subPath.getReadColumnMapping().getTableMapping();
103                     tablePaths = (List)tableMappingSubset.get(table);
104                     if (tablePaths == null)
105                     {
106                         tablePaths = new ArrayList(2);
107                         tableMappingSubset.put(table, tablePaths);
108                     }
109                     tablePaths.add(subPathInfo);
110                 }
111                 else // complex mapping
112
{
113                     Iterator it = subPathInfo.subPath.getBuilderAncestor().getBuildMappings().iterator();
114                     
115                     while (it.hasNext())
116                     {
117                         table = (TableMapping)it.next();
118                         tablePaths = (List)tableMappingSubset.get(table);
119                         if (tablePaths == null)
120                         {
121                             tablePaths = new ArrayList(2);
122                             tableMappingSubset.put(table, tablePaths);
123                         }
124                         tablePaths.add(subPathInfo);
125                     }
126                 }
127             }
128         }
129         return new Object JavaDoc[] {tableMappingSubset, subPathNodes};
130     }
131     
132     abstract void initExploration(VarInfoSet varInfoSet, AbstractConnection connection)
133     throws SQLException JavaDoc, XMLDBCException;
134     
135     void freezeCurrentSubPath()
136     {
137         for (int i=0; i < queryTuples.length; i++)
138         {
139             if (queryTuples[i] != null)
140                 ((QueryTuple)queryTuples[i]).freezeCurrentSubPath();
141         }
142         qNode.freezeCurrentSubPath();
143         qExtraNode.freezeCurrentSubPath();
144     }
145     
146 }
147
Popular Tags