1 22 23 package org.xquark.extractor.progress; 24 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import java.util.Set ; 28 29 import org.xquark.extractor.algebra.*; 30 import org.xquark.extractor.common.Debug; 31 import org.xquark.extractor.common.SqlWrapperException; 32 import org.xquark.extractor.runtime.IDProvider; 33 import org.xquark.extractor.sql.*; 34 import org.xquark.extractor.xfunctions.XfContains; 35 36 public final class ProgressGenSqlVisitor extends AbstractGenSqlVisitor { 37 private static final String RCSRevision = "$Revision: 1.8 $"; 38 private static final String RCSName = "$Name: $"; 39 40 public ProgressGenSqlVisitor(IDProvider relIDProvider) { 41 super((SqlFactory) ProgressFactory.getInstance(), relIDProvider); 42 } 43 44 public SqlExpression visit(AttributeExpression arg) { 45 47 SqlExpression retVal = null; 48 String attrName = arg.getName(); 49 50 String tableInstanceName; 51 RenameRelation rr = arg.getTableInstance(); 52 if (null != rr) { 53 tableInstanceName = rr.getUniqueName(); 54 } else { 55 tableInstanceName = null; 56 } 57 58 if (attrName.equals("*")) { 59 retVal = _factory.createAttributeExpression(null, attrName); 60 } else { 61 retVal = _factory.createAttributeExpression(tableInstanceName, attrName); 62 } 63 return retVal; 65 } 66 67 public SqlExpression visit(BinOpArithmetic arg) { 68 70 SqlExpression retVal = null; 71 72 Expression aLOprnd = arg.getLeftOperand(); 73 SqlExpression sLOprnd = aLOprnd.accept(this); 74 75 Expression aROprnd = arg.getRightOperand(); 76 SqlExpression sROprnd = aROprnd.accept(this); 77 78 int oprtr = arg.getOperator(); 79 80 retVal = _factory.createBinOpArithmetic(oprtr, sLOprnd, sROprnd); 81 82 if (false 85 ) { 86 87 retVal = _factory.createSfRound(retVal); 88 } 89 90 return retVal; 92 } 93 94 public SqlExpression visit(SortSpecification arg) { 95 SqlSortSpecification retVal = null; 97 Expression sortOperand = ((UnOpSort) arg.getFather()).getOperand(); 98 if (sortOperand instanceof BinaryAlgebra) { 99 Expression sortExpr = arg.getSortExpression(); 100 101 SqlExpression sqlSortExpr = sortExpr.accept(this); 102 103 retVal = _factory.createSortSpecification(sqlSortExpr, arg.getSortDirection()); 104 } else { 105 Expression sortExpr = arg.getSortExpression(); 106 Expression underlyingExpr = null; 107 if (sortExpr instanceof AttributeExpression) { 108 underlyingExpr = ((AttributeExpression) sortExpr).getUnderlyinExpr(); 109 if (underlyingExpr instanceof AttributeExpression) { 110 sortExpr = underlyingExpr; 111 } else if (underlyingExpr instanceof RenameItem) { 112 Expression operandOfUnderlyingExpr = ((RenameItem) underlyingExpr).getOperand(); 113 if (operandOfUnderlyingExpr instanceof AttributeExpression) { 114 sortExpr = operandOfUnderlyingExpr; 115 } 116 } 117 } 118 SqlExpression sqlSortExpr = sortExpr.accept(this); 119 120 retVal = _factory.createSortSpecification(sqlSortExpr, arg.getSortDirection()); 121 } 122 return retVal; 124 } 125 126 public SqlExpression visit(XfContains arg) throws SqlWrapperException { 127 129 Debug.assertTrue(2 == arg.getArgumentNumber(), "2 == arg.getArgumentNumber()"); 130 org.xquark.extractor.progress.sql.SfInStr inStr = new org.xquark.extractor.progress.sql.SfInStr(); 131 132 Expression aArg0 = (Expression) arg.getArgument(0); 133 SqlExpression sArg0 = aArg0.accept(this); 134 135 Expression aArg1 = (Expression) arg.getArgument(1); 136 SqlExpression sArg1 = aArg1.accept(this); 137 138 inStr.setArgument(0, sArg0); 139 inStr.setArgument(1, sArg1); 140 141 SqlBinOpCompare retVal = _factory.createBinOpCompare(GT_COMPOP, inStr, _factory.createLitInteger(new Integer (0))); 142 143 return retVal; 145 } 146 147 protected org.xquark.extractor.sql.SqlSelect selectAddFromClause(org.xquark.extractor.sql.SqlSelect select, BinOpOuterJoin arg) { 148 150 org.xquark.extractor.sql.SqlExpression newFrom = arg.accept(this); 151 select.addFromClause(newFrom); 152 153 return select; 155 } 156 157 public org.xquark.extractor.sql.SqlExpression visit(BinOpOuterJoin arg) { 158 160 Expression[] aOprnds = { arg.getLeftOperand(), arg.getRightOperand()}; 161 org.xquark.extractor.sql.SqlExpression[] sOprnd = new SqlExpression[2]; 162 Set providedTableInstances; 163 164 165 for (int i = 0; i < aOprnds.length; i++) { 166 providedTableInstances = ((Relation) aOprnds[i]).providedTableInstances(); 167 if (1 == providedTableInstances.size()) { 168 RenameRelation ti = (RenameRelation) providedTableInstances.toArray()[0]; 170 171 if (!(aOprnds[i] instanceof RenameRelation)) { 172 aOprnds[i] = new RenameRelation(aOprnds[i], ti.getName()); 173 } 174 175 sOprnd[i] = aOprnds[i].accept(this); 176 } else if (aOprnds[i] instanceof BinOpOuterJoin) { 177 sOprnd[i] = aOprnds[i].accept(this); 178 } else { 179 Debug.nyi("complex outerjoin"); 180 } 181 } 182 183 int outerJoinType = arg.getJoinType(); 184 185 186 List aPredicateList = arg.getPredicateList(); 187 List sPredicateList = null; 188 if (null != aPredicateList) { 189 190 sPredicateList = new ArrayList (); 191 Expression aPredicate = null; 192 org.xquark.extractor.sql.SqlExpression sPredicate = null; 193 194 for (int i = 0; i < aPredicateList.size(); i++) { 195 aPredicate = (Expression) aPredicateList.get(i); 196 sPredicate = aPredicate.accept(this); 197 sPredicateList.add(sPredicate); 198 } 199 } 200 201 202 org.xquark.extractor.sql.SqlExpression retVal = new org.xquark.extractor.sql.SqlBinOpOuterJoin(sOprnd[0], sOprnd[1], outerJoinType, sPredicateList); 203 204 return retVal; 206 } 207 208 protected org.xquark.extractor.sql.SqlSelect selectAddFromClause(org.xquark.extractor.sql.SqlSelect select, DummyTable operand) { 209 211 org.xquark.extractor.sql.SqlTable newFrom = _factory.createTable("dual"); 212 select.addFromClause(newFrom); 213 214 return select; 216 } 217 } 218 | Popular Tags |