1 10 11 package com.triactive.jdo.store; 12 13 import java.math.BigInteger ; 14 import javax.jdo.JDOUserException; 15 16 17 class IndexOfExpression extends NumericExpression 18 { 19 private CharacterExpression str; 20 private CharacterExpression substr; 21 22 public IndexOfExpression(CharacterExpression str, CharacterExpression substr) 23 { 24 super(str.qs); 25 26 this.str = str; 27 this.substr = substr; 28 } 29 30 public BooleanExpression gteq(SQLExpression expr) 31 { 32 if (expr instanceof IntegerLiteral) 33 { 34 BigInteger idx = ((IntegerLiteral)expr).getValue(); 35 36 if (idx.compareTo(BigInteger.ZERO) != 0) 37 throw new JDOUserException("String.indexOf() can only be compared >= 0"); 38 39 CharacterLiteral pct = new CharacterLiteral(qs, '%'); 40 41 return new BooleanExpression(str, OP_LIKE, pct.add(substr).add(pct)); 42 43 } 44 else 45 return super.gteq(expr); 46 } 47 48 public StatementText toStatementText() 49 { 50 throw new JDOUserException("String.indexOf() can only be compared >= 0"); 51 } 52 } 53 | Popular Tags |