1 22 23 package org.xquark.extractor.microsoft; 24 25 import org.xquark.extractor.algebra.*; 26 import org.xquark.extractor.runtime.IDProvider; 27 import org.xquark.extractor.sql.*; 28 import org.xquark.jdbc.typing.DbType; 29 30 public class MicrosoftGenSqlVisitor extends AbstractGenSqlVisitor { 31 32 private static final String RCSRevision = "$Revision: 1.8 $"; 33 private static final String RCSName = "$Name: $"; 34 35 36 public MicrosoftGenSqlVisitor(IDProvider relIDProvider) { 37 super((SqlFactory)MicrosoftFactory.getInstance(), relIDProvider); 38 } 39 40 protected SqlSelect selectAddFromClause (SqlSelect select, DummyTable operand) 41 { 42 44 return select; 46 } 47 public SqlExpression visit(BinOpArithmetic arg) 48 { 49 51 SqlExpression retVal = null; 52 53 Expression aLOprnd = arg.getLeftOperand(); 54 SqlExpression sLOprnd = aLOprnd.accept(this); 55 56 Expression aROprnd = arg.getRightOperand(); 57 SqlExpression sROprnd = aROprnd.accept(this); 58 59 int oprtr = arg.getOperator(); 60 61 if (MODULO_ARITHMETICS == oprtr ) { 62 retVal = visitModulo(sLOprnd, (SqlTypeAtom)aLOprnd.getType(), sROprnd, (SqlTypeAtom)aROprnd.getType()); 63 } 64 else { 65 if ( DIVIDE_ARITHMETICS == oprtr && 66 aLOprnd.getType().isInteger() && 67 aROprnd.getType().isInteger() ) { 68 70 sLOprnd = _factory.createConvert(sLOprnd, 71 new DbType(java.sql.Types.INTEGER), 72 new DbType(java.sql.Types.DECIMAL)); 73 } 74 retVal = _factory.createBinOpArithmetic(oprtr,sLOprnd, sROprnd); 75 retVal = _factory.createBinOpArithmetic(oprtr,sLOprnd, sROprnd); 76 } 77 78 return retVal; 80 } 81 82 protected SqlExpression visitModulo(SqlExpression lOprnd, SqlTypeAtom lOprndType, 83 SqlExpression rOprnd, SqlTypeAtom rOprndType) { 84 SqlBinOpArithmetic retVal = null; 85 if (lOprndType.isInteger() && rOprndType.isInteger()) { 86 retVal = _factory.createBinOpArithmetic(MODULO_ARITHMETICS,lOprnd,rOprnd); 87 } 88 else { 89 90 91 SfSign signL = _factory.createSfSign(lOprnd); 92 93 SfAbs absL = _factory.createSfAbs(lOprnd); 94 95 SqlBinOpArithmetic LdivR = _factory.createBinOpArithmetic(DIVIDE_ARITHMETICS,lOprnd, rOprnd); 96 SfAbs absLdivR = _factory.createSfAbs(LdivR); 97 SfFloor floorAbs = _factory.createSfFloor(absLdivR); 98 SfAbs absR = _factory.createSfAbs(rOprnd); 99 100 SqlBinOpArithmetic floorMultiR = _factory.createBinOpArithmetic(MULTIPLY_ARITHMETICS,floorAbs, absR); 101 102 SqlBinOpArithmetic AbsMinusFloor = _factory.createBinOpArithmetic(MINUS_ARITHMETICS,absL, floorMultiR); 103 104 retVal = _factory.createBinOpArithmetic(MULTIPLY_ARITHMETICS,signL, AbsMinusFloor); 105 } 106 return retVal; 107 } 108 109 110 public SqlExpression visit(SortSpecification arg) 111 { 112 SqlSortSpecification retVal = null; 114 Expression sortOperand = ((UnOpSort)arg.getFather()).getOperand(); 115 if (sortOperand instanceof BinaryAlgebra && !(sortOperand instanceof BinOpOuterJoin)) { 116 Expression sortExpr = arg.getSortExpression(); 117 SqlExpression sqlSortExpr = sortExpr.accept(this); 121 122 retVal = _factory.createSortSpecification(sqlSortExpr,arg.getSortDirection()); 123 } 124 else { 125 Expression sortExpr = arg.getSortExpression(); 126 Expression underlyingExpr = null; 127 if (sortExpr instanceof AttributeExpression) { 128 underlyingExpr = ((AttributeExpression)sortExpr).getUnderlyinExpr(); 129 if (underlyingExpr instanceof AttributeExpression) { 130 sortExpr = underlyingExpr; 131 } 132 } 133 SqlExpression sqlSortExpr = sortExpr.accept(this); 134 135 retVal = _factory.createSortSpecification(sqlSortExpr,arg.getSortDirection()); 136 } 137 return retVal; 139 } 140 141 142 protected SqlSelect selectAddFromClause (SqlSelect select, BinaryAlgebra operand) 143 { 144 146 SqlExpression sRelation = operand.accept(this); 147 SqlRenameRelation sRR = _factory.createRenameRelation( sRelation,"BinaryAlgebra"); 148 149 select.addFromClause(sRR); 150 151 return select; 153 } 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 } 169 | Popular Tags |