01: /*
02: * Copyright 2002 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: IndexOfExpression.java,v 1.3 2003/08/04 16:40:35 pierreg0 Exp $
09: */
10:
11: package com.triactive.jdo.store;
12:
13: import java.math.BigInteger;
14: import javax.jdo.JDOUserException;
15:
16: class IndexOfExpression extends NumericExpression {
17: private CharacterExpression str;
18: private CharacterExpression substr;
19:
20: public IndexOfExpression(CharacterExpression str,
21: CharacterExpression substr) {
22: super (str.qs);
23:
24: this .str = str;
25: this .substr = substr;
26: }
27:
28: public BooleanExpression gteq(SQLExpression expr) {
29: if (expr instanceof IntegerLiteral) {
30: BigInteger idx = ((IntegerLiteral) expr).getValue();
31:
32: if (idx.compareTo(BigInteger.ZERO) != 0)
33: throw new JDOUserException(
34: "String.indexOf() can only be compared >= 0");
35:
36: CharacterLiteral pct = new CharacterLiteral(qs, '%');
37:
38: return new BooleanExpression(str, OP_LIKE, pct.add(substr)
39: .add(pct));
40:
41: } else
42: return super .gteq(expr);
43: }
44:
45: public StatementText toStatementText() {
46: throw new JDOUserException(
47: "String.indexOf() can only be compared >= 0");
48: }
49: }
|