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