KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2004 (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: CharacterLiteral.java,v 1.4 2004/01/18 03:01:06 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import java.math.BigInteger JavaDoc;
14
15
16 class CharacterLiteral extends CharacterExpression
17 {
18     private final String JavaDoc value;
19
20     public CharacterLiteral(QueryStatement qs, char value)
21     {
22         super(qs);
23
24         this.value = String.valueOf(value);
25         st.append('\'').append(value).append('\'');
26     }
27
28     public CharacterLiteral(QueryStatement qs, String JavaDoc value)
29     {
30         super(qs);
31
32         this.value = value;
33
34         DatabaseAdapter dba = qs.getStoreManager().getDatabaseAdapter();
35         st.appendParameter((ColumnMapping)dba.getMapping(String JavaDoc.class), value);
36     }
37
38     public BooleanExpression eq(SQLExpression expr)
39     {
40         if (expr instanceof CharacterLiteral)
41             return new BooleanLiteral(qs, value.equals(((CharacterLiteral)expr).value));
42         else
43             return super.eq(expr);
44     }
45
46     public BooleanExpression noteq(SQLExpression expr)
47     {
48         if (expr instanceof CharacterLiteral)
49             return new BooleanLiteral(qs, !value.equals(((CharacterLiteral)expr).value));
50         else
51             return super.noteq(expr);
52     }
53
54     public BooleanExpression lt(SQLExpression expr)
55     {
56         if (expr instanceof CharacterLiteral)
57             return new BooleanLiteral(qs, value.compareTo(((CharacterLiteral)expr).value) < 0);
58         else
59             return super.lt(expr);
60     }
61
62     public BooleanExpression lteq(SQLExpression expr)
63     {
64         if (expr instanceof CharacterLiteral)
65             return new BooleanLiteral(qs, value.compareTo(((CharacterLiteral)expr).value) <= 0);
66         else
67             return super.lteq(expr);
68     }
69
70     public BooleanExpression gt(SQLExpression expr)
71     {
72         if (expr instanceof CharacterLiteral)
73             return new BooleanLiteral(qs, value.compareTo(((CharacterLiteral)expr).value) > 0);
74         else
75             return super.gt(expr);
76     }
77
78     public BooleanExpression gteq(SQLExpression expr)
79     {
80         if (expr instanceof CharacterLiteral)
81             return new BooleanLiteral(qs, value.compareTo(((CharacterLiteral)expr).value) >= 0);
82         else
83             return super.gteq(expr);
84     }
85
86     public SQLExpression add(SQLExpression expr)
87     {
88         if (expr instanceof CharacterLiteral)
89             return new CharacterLiteral(qs, value.concat(((CharacterLiteral)expr).value));
90         else
91             return super.add(expr);
92     }
93
94     public BooleanExpression endsWithMethod(SQLExpression str)
95     {
96         if (str instanceof CharacterLiteral)
97             return new BooleanLiteral(qs, value.endsWith(((CharacterLiteral)str).value));
98         else
99             return super.endsWithMethod(str);
100     }
101
102     public NumericExpression indexOfMethod(SQLExpression str)
103     {
104         if (str instanceof CharacterLiteral)
105             return new IntegerLiteral(qs, BigInteger.valueOf((long)value.indexOf(((CharacterLiteral)str).value)));
106         else
107             return super.indexOfMethod(str);
108     }
109
110     public NumericExpression lengthMethod()
111     {
112         return new IntegerLiteral(qs, BigInteger.valueOf((long)value.length()));
113     }
114
115     public BooleanExpression startsWithMethod(SQLExpression str)
116     {
117         if (str instanceof CharacterLiteral)
118             return new BooleanLiteral(qs, value.startsWith(((CharacterLiteral)str).value));
119         else
120             return super.startsWithMethod(str);
121     }
122
123     public BooleanExpression startsWithMethod(SQLExpression str, SQLExpression toffset)
124     {
125         if (str instanceof CharacterLiteral && toffset instanceof IntegerLiteral)
126             return new BooleanLiteral(qs, value.startsWith(((CharacterLiteral)str).value,
127                                                            ((IntegerLiteral)toffset).getValue().intValue()));
128         else
129             return super.startsWithMethod(str, toffset);
130     }
131
132     public CharacterExpression substringMethod(NumericExpression begin)
133     {
134         if (begin instanceof IntegerLiteral)
135             return new CharacterLiteral(qs, value.substring(((IntegerLiteral)begin).getValue().intValue()));
136         else
137             return super.substringMethod(begin);
138     }
139
140     public CharacterExpression substringMethod(NumericExpression begin, NumericExpression end)
141     {
142         if (begin instanceof IntegerLiteral && end instanceof IntegerLiteral)
143             return new CharacterLiteral(qs, value.substring(((IntegerLiteral)begin).getValue().intValue(),
144                                                             ((IntegerLiteral)end ).getValue().intValue()));
145         else
146             return super.substringMethod(begin, end);
147     }
148
149     public CharacterExpression toLowerCase()
150     {
151         return new CharacterLiteral(qs, value.toLowerCase());
152     }
153
154     public CharacterExpression toUpperCase()
155     {
156         return new CharacterLiteral(qs, value.toUpperCase());
157     }
158
159     public CharacterExpression trim()
160     {
161         return new CharacterLiteral(qs, value.trim());
162     }
163 }
164
Popular Tags