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.mysql.sql.SqlCreateTempTableAs; 30 import org.xquark.extractor.runtime.IDProvider; 31 import org.xquark.extractor.sql.*; 32 33 public final class MySqlGenSqlVisitor extends AbstractGenSqlVisitor { 34 35 private static final String RCSRevision = "$Revision: 1.7 $"; 36 private static final String RCSName = "$Name: $"; 37 38 private IDProvider _tmpTableIDProvider; 39 40 public MySqlGenSqlVisitor(IDProvider relIDProvider, IDProvider tmpTableIDProvider) { 41 super((SqlFactory) MySqlFactory.getInstance(), relIDProvider); 42 _tmpTableIDProvider = tmpTableIDProvider; 43 } 44 45 public void reinit() { 46 super.reinit(); 47 } 48 49 public SqlExpression visit(UnOpAggregate arg) { 50 52 SqlExpression retVal = visit((UnOpProject) arg); 53 54 return retVal; 56 } 57 58 60 public SqlExpression visit(UnOpProject arg) { 61 SqlExpression retVal; 63 64 SqlSelect outerExpression = null; 65 if (!_nestStack.isEmpty()) 66 outerExpression = (SqlSelect) _nestStack.firstElement(); 67 68 SqlSelect select = _factory.createSelect(arg); 69 _nestStack.push(select); 70 71 retVal = selectAddSelectClause(select, arg); 73 75 if (outerExpression != null) { 76 String tempTableName = getTemporaryTableName(); 77 SqlCreateTempTableAs sCreateTempTable = new SqlCreateTempTableAs(tempTableName, select); 78 outerExpression.appendPrecedent(sCreateTempTable); 79 retVal = _factory.createTable(tempTableName); 80 } 81 _nestStack.pop(); 82 83 return retVal; 85 } 86 87 protected SqlSelect selectAddFromClause(SqlSelect select, BinOpOuterJoin arg) { 88 90 Expression[] relations = { arg.getLeftOperand(), arg.getRightOperand()}; 91 SqlExpression[] sOprnd = new SqlExpression[2]; 92 93 for (int i = 0; i < relations.length; i++) { 94 sOprnd[i] = relations[i].accept(this); 97 } 98 99 100 List aPredicateList = arg.getPredicateList(); 101 List sPredicateList = null; 102 if (null != aPredicateList) { 103 104 sPredicateList = new ArrayList (); 105 Expression aPredicate = null; 106 org.xquark.extractor.sql.SqlExpression sPredicate = null; 107 108 for (int i = 0; i < aPredicateList.size(); i++) { 109 aPredicate = (Expression) aPredicateList.get(i); 110 sPredicate = aPredicate.accept(this); 111 sPredicateList.add(sPredicate); 112 } 113 } 114 115 116 org.xquark.extractor.sql.SqlExpression retVal = new org.xquark.extractor.sql.SqlBinOpOuterJoin(sOprnd[0], sOprnd[1], arg.getJoinType(), sPredicateList); 117 118 select.addFromClause(retVal); 119 120 return select; 122 } 123 124 protected String getTemporaryTableName() { 125 return TMP_TABLE_PREFIX + _tmpTableIDProvider.getID(); 126 } 127 } 128 | Popular Tags |