1 22 23 package org.xquark.extractor.progress; 24 25 import java.sql.SQLException ; 26 import java.sql.Statement ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 import org.xquark.extractor.algebra.*; 31 import org.xquark.extractor.metadata.MetaDataManager; 32 import org.xquark.extractor.runtime.QueryFactory; 33 import org.xquark.extractor.runtime.Query; 34 import org.xquark.extractor.runtime.SynchronizedResultSet; 35 import org.xquark.extractor.sql.SqlExpression; 36 import org.xquark.xml.xdbc.XMLDBCException; 37 import org.xquark.xquery.metadata.resolver.MetadataAccess; 38 import org.xquark.xquery.parser.XQueryException; 39 import org.xquark.xquery.parser.XQueryExpression; 40 41 public class ProgressQueryFactory extends QueryFactory { 42 private static final String RCSRevision = "$Revision: 1.5 $"; 43 private static final String RCSName = "$Name: $"; 44 45 private PreEvaluationVisitor _pev; 46 47 public ProgressQueryFactory(MetaDataManager metadataManager, MetadataAccess metadata) throws XMLDBCException { 48 super(metadataManager, metadata); 49 } 50 51 protected void createVisitors() { 52 TypeInterpreter ti = new TypeInterpreter(); 53 _genAlgebraVisitor = new GenAlgebraVisitor(ti, _metadataManager, _attIDProvider, _relIDProvider); 54 55 _algebraTypeVisitor = new AlgebraTypeVisitor(); 56 _removeProjectVisitor = new RemoveIntermediateProjectVisitor(); 57 _brav = new BuildReferredAttributes(); 58 _apv = new AnalyzePredicateVisitor(); 59 60 _genSqlVisitor = new org.xquark.extractor.progress.ProgressGenSqlVisitor(_relIDProvider); 61 _genSqlVisitor.setMetadataManager(_metadataManager); 62 63 _pev = new PreEvaluationVisitor(); 64 } 65 66 protected Query.SQLExecutionInfo compileSingleQDB(XQueryExpression xQuery, boolean keyNeeded) 67 throws XQueryException, XMLDBCException { 68 70 SynchronizedResultSet retVal = null; 71 Expression algebraTree = null; 72 Mapper mapper = null; 73 74 75 _attIDProvider.reset(); 76 _relIDProvider.reset(); 77 78 79 _genAlgebraVisitor.reinit(); 80 81 if (keyNeeded) { List souArgList = new ArrayList (); 83 souArgList.add(xQuery); 84 _genAlgebraVisitor.noticSortedOuterUnion(souArgList); 85 } 86 xQuery.accept(_genAlgebraVisitor); 87 algebraTree = _genAlgebraVisitor.getAlgebraTree(); 88 89 _removeProjectVisitor.reinit(); 92 algebraTree.accept(_removeProjectVisitor); 93 94 algebraTree.accept(_brav); 95 96 97 _apv.reinit(); 98 algebraTree.accept(_apv); 99 100 104 algebraTree.accept(new RemoveNestedAggregation(_attIDProvider, _relIDProvider)); 105 106 _algebraTypeVisitor.reinit(); 107 algebraTree.accept(_algebraTypeVisitor); 108 109 _pev.setGenSqlVisitor(_genSqlVisitor); 110 try { Statement jdbcStatement = _stmt.createJdbcStatement(); 112 _pev.setJdbcStatement(jdbcStatement); 113 jdbcStatement.close(); 114 } 115 catch (SQLException ex) { 116 throw new XMLDBCException(ex.getMessage(), ex); 117 } 118 algebraTree.accept(_pev); 119 120 mapper = algebraTree.getMapper(); 121 122 _genSqlVisitor.reinit(); 123 SqlExpression sql = algebraTree.accept(_genSqlVisitor); 124 125 126 sql.generateRequestList(); 127 return new Query.SQLExecutionInfo(sql, algebraTree.getMapper()); 128 } 129 } 130 | Popular Tags |