KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > oracle > Oracle7QueryFactory


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 package org.xquark.extractor.oracle;
24
25 import java.sql.SQLException JavaDoc;
26 import java.sql.Statement JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.xquark.extractor.algebra.*;
31 import org.xquark.extractor.sql.SqlExpression;
32 import org.xquark.extractor.metadata.MetaDataManager;
33 import org.xquark.extractor.runtime.Query;
34 import org.xquark.extractor.runtime.SynchronizedResultSet;
35 import org.xquark.xml.xdbc.XMLDBCException;
36 import org.xquark.xquery.metadata.resolver.MetadataAccess;
37 import org.xquark.xquery.parser.XQueryException;
38 import org.xquark.xquery.parser.XQueryExpression;
39
40 public class Oracle7QueryFactory extends OracleQueryFactory {
41     private static final String JavaDoc RCSRevision = "$Revision: 1.5 $";
42     private static final String JavaDoc RCSName = "$Name: $";
43
44     private PreEvaluationVisitor _pev;
45
46     public Oracle7QueryFactory(MetaDataManager metadataManager, MetadataAccess metadata) throws XMLDBCException {
47         super(metadataManager, metadata);
48     }
49
50     protected void createVisitors() {
51         TypeInterpreter ti = new TypeInterpreter();
52         _genAlgebraVisitor = new GenAlgebraVisitor(ti, _metadataManager, _attIDProvider, _relIDProvider);
53
54         _algebraTypeVisitor = new AlgebraTypeVisitor();
55         _removeProjectVisitor = new RemoveIntermediateProjectVisitor();
56         _brav = new BuildReferredAttributes();
57         _apv = new AnalyzePredicateVisitor();
58
59         _genSqlVisitor = new org.xquark.extractor.oracle.OracleGenSqlVisitor(_relIDProvider);
60         _genSqlVisitor.setMetadataManager(_metadataManager);
61
62         _pev = new PreEvaluationVisitor();
63     }
64
65     protected Query.SQLExecutionInfo compileSingleQDB(XQueryExpression xQuery, boolean keyNeeded)
66     throws XQueryException, XMLDBCException {
67         //Trace.enter(this, "executeSingleQDB(XQueryExpression xQuery, boolean keyNeeded)");
68

69         SynchronizedResultSet retVal = null;
70         Expression algebraTree = null;
71         Mapper mapper = null;
72
73         /* Algebra tree building */
74         _genAlgebraVisitor.reinit();
75
76         if (keyNeeded) { // Used when Sorted Outer Union is needed to identify rows
77
List JavaDoc souArgList = new ArrayList JavaDoc();
78             souArgList.add(xQuery);
79             _genAlgebraVisitor.noticSortedOuterUnion(souArgList);
80         }
81         xQuery.accept(_genAlgebraVisitor);
82         algebraTree = _genAlgebraVisitor.getAlgebraTree();
83
84         // INFO : YS types of visitors : GenAlgebraVisitor (a ParserVisitor impl),
85
// AlgebraVisitor, GenSQLVisitor
86
_removeProjectVisitor.reinit();
87         algebraTree.accept(_removeProjectVisitor);
88
89         algebraTree.accept(_brav);
90
91         /* resolve invalid predicates */
92         _apv.reinit();
93         algebraTree.accept(_apv);
94
95         algebraTree.accept(new RemoveNestedAggregation(_attIDProvider, _relIDProvider));
96
97         _algebraTypeVisitor.reinit();
98         algebraTree.accept(_algebraTypeVisitor);
99
100         _pev.setGenSqlVisitor(_genSqlVisitor);
101         try { // TODO: why temp tables should be created here ?
102
Statement JavaDoc jdbcStatement = _stmt.createJdbcStatement();
103             _pev.setJdbcStatement(jdbcStatement);
104             jdbcStatement.close();
105         }
106         catch (SQLException JavaDoc ex) {
107             throw new XMLDBCException(ex.getMessage(), ex);
108         }
109         algebraTree.accept(_pev);
110
111         mapper = algebraTree.getMapper();
112
113         _genSqlVisitor.reinit();
114         SqlExpression sql = algebraTree.accept(_genSqlVisitor);
115
116         /* Generate string to be ready for prepared statements execution */
117         sql.generateRequestList();
118         return new Query.SQLExecutionInfo(sql, algebraTree.getMapper());
119     }
120 }
121
Popular Tags