KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > store > IndexOfExpression


1 /*
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: IndexOfExpression.java,v 1.3 2003/08/04 16:40:35 pierreg0 Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import java.math.BigInteger JavaDoc;
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 JavaDoc 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