1 10 11 package com.triactive.jdo.store; 12 13 import java.math.BigInteger ; 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 18 class CharacterExpression extends SQLExpression 19 { 20 public CharacterExpression(QueryStatement qs) 21 { 22 super(qs); 23 } 24 25 public CharacterExpression(QueryStatement qs, QueryStatement.QueryColumn qsc) 26 { 27 super(qs, qsc); 28 } 29 30 public CharacterExpression(String functionName, List args) 31 { 32 super(functionName, args); 33 } 34 35 public CharacterExpression(SQLExpression operand1, DyadicOperator op, SQLExpression operand2) 36 { 37 super(operand1, op, operand2); 38 } 39 40 public BooleanExpression eq(SQLExpression expr) 41 { 42 if (expr instanceof NullLiteral) 43 return expr.eq(this); 44 else if (expr instanceof CharacterExpression) 45 return new BooleanExpression(this, OP_EQ, expr); 46 else 47 return super.eq(expr); 48 } 49 50 public BooleanExpression noteq(SQLExpression expr) 51 { 52 if (expr instanceof NullLiteral) 53 return expr.noteq(this); 54 else if (expr instanceof CharacterExpression) 55 return new BooleanExpression(this, OP_NOTEQ, expr); 56 else 57 return super.noteq(expr); 58 } 59 60 public BooleanExpression lt(SQLExpression expr) 61 { 62 if (expr instanceof CharacterExpression) 63 return new BooleanExpression(this, OP_LT, expr); 64 else 65 return super.lt(expr); 66 } 67 68 public BooleanExpression lteq(SQLExpression expr) 69 { 70 if (expr instanceof CharacterExpression) 71 return new BooleanExpression(this, OP_LTEQ, expr); 72 else 73 return super.lteq(expr); 74 } 75 76 public BooleanExpression gt(SQLExpression expr) 77 { 78 if (expr instanceof CharacterExpression) 79 return new BooleanExpression(this, OP_GT, expr); 80 else 81 return super.gt(expr); 82 } 83 84 public BooleanExpression gteq(SQLExpression expr) 85 { 86 if (expr instanceof CharacterExpression) 87 return new BooleanExpression(this, OP_GTEQ, expr); 88 else 89 return super.gteq(expr); 90 } 91 92 public SQLExpression add(SQLExpression expr) 93 { 94 if (expr instanceof CharacterExpression) 95 return new CharacterExpression(this, OP_CONCAT, expr); 96 else 97 return super.add(expr); 98 } 99 100 public BooleanExpression in(SQLExpression expr) 101 { 102 return new BooleanExpression(this, OP_IN, expr); 103 } 104 105 public CharacterExpression charAtMethod(SQLExpression index) 106 { 107 if (!(index instanceof NumericExpression)) 108 throw new IllegalArgumentTypeException(index); 109 110 NumericExpression begin = (NumericExpression)index; 111 NumericExpression end = (NumericExpression)begin.add(new IntegerLiteral(qs, BigInteger.ONE)); 112 113 return substringMethod(begin, end); 114 } 115 116 public BooleanExpression endsWithMethod(SQLExpression str) 117 { 118 if (!(str instanceof CharacterExpression)) 119 throw new IllegalArgumentTypeException(str); 120 121 CharacterLiteral pct = new CharacterLiteral(qs, '%'); 122 123 return new BooleanExpression(this, OP_LIKE, pct.add(str)); 124 } 125 126 public NumericExpression indexOfMethod(SQLExpression str) 127 { 128 if (!(str instanceof CharacterExpression)) 129 throw new IllegalArgumentTypeException(str); 130 131 return new IndexOfExpression(this, (CharacterExpression)str); 132 } 133 134 public NumericExpression lengthMethod() 135 { 136 return qs.getStoreManager().getDatabaseAdapter().lengthMethod(this); 137 } 138 139 public BooleanExpression startsWithMethod(SQLExpression str) 140 { 141 if (!(str instanceof CharacterExpression)) 142 throw new IllegalArgumentTypeException(str); 143 144 CharacterLiteral pct = new CharacterLiteral(qs, '%'); 145 146 return new BooleanExpression(this, OP_LIKE, str.add(pct)); 147 } 148 149 public BooleanExpression startsWithMethod(SQLExpression str, SQLExpression toffset) 150 { 151 return substringMethod(toffset).startsWithMethod(str); 152 } 153 154 public CharacterExpression substringMethod(SQLExpression begin) 155 { 156 if (!(begin instanceof NumericExpression)) 157 throw new IllegalArgumentTypeException(begin); 158 159 return qs.getStoreManager().getDatabaseAdapter().substringMethod(this, 160 (NumericExpression)begin); 161 } 162 163 public CharacterExpression substringMethod(SQLExpression begin, SQLExpression end) 164 { 165 if (!(begin instanceof NumericExpression)) 166 throw new IllegalArgumentTypeException(begin); 167 if (!(end instanceof NumericExpression)) 168 throw new IllegalArgumentTypeException(end); 169 170 return qs.getStoreManager().getDatabaseAdapter().substringMethod(this, 171 (NumericExpression)begin, 172 (NumericExpression)end); 173 } 174 175 public CharacterExpression toLowerCaseMethod() 176 { 177 ArrayList args = new ArrayList (); 178 args.add(this); 179 180 return new CharacterExpression("LOWER", args); 181 } 182 183 public CharacterExpression toUpperCaseMethod() 184 { 185 ArrayList args = new ArrayList (); 186 args.add(this); 187 188 return new CharacterExpression("UPPER", args); 189 } 190 191 public CharacterExpression trim() 192 { 193 ArrayList args = new ArrayList (); 194 args.add(this); 195 196 return new CharacterExpression("TRIM", args); 197 } 198 } 199 | Popular Tags |