KickJava   Java API By Example, From Geeks To Geeks.

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


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: FloatingPointLiteral.java,v 1.5 2004/01/18 03:01:06 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import com.triactive.jdo.util.SQLFormat;
14 import java.math.BigDecimal JavaDoc;
15
16
17 class FloatingPointLiteral extends NumericExpression
18 {
19     private final BigDecimal JavaDoc value;
20
21     public FloatingPointLiteral(QueryStatement qs, Float JavaDoc value)
22     {
23         super(qs);
24
25         this.value = new BigDecimal JavaDoc(value.toString());
26
27         DatabaseAdapter dba = qs.getStoreManager().getDatabaseAdapter();
28         st.appendParameter((ColumnMapping)dba.getMapping(Float JavaDoc.class), value);
29     }
30
31     public FloatingPointLiteral(QueryStatement qs, Double JavaDoc value)
32     {
33         super(qs);
34
35         this.value = new BigDecimal JavaDoc(value.toString());
36
37         DatabaseAdapter dba = qs.getStoreManager().getDatabaseAdapter();
38         st.appendParameter((ColumnMapping)dba.getMapping(Double JavaDoc.class), value);
39     }
40
41     public FloatingPointLiteral(QueryStatement qs, BigDecimal JavaDoc value)
42     {
43         super(qs);
44
45         this.value = value;
46         st.append(SQLFormat.format(value));
47     }
48
49     public BooleanExpression eq(SQLExpression expr)
50     {
51         if (expr instanceof FloatingPointLiteral)
52             return new BooleanLiteral(qs, value.compareTo(((FloatingPointLiteral)expr).value) == 0);
53         else
54             return super.eq(expr);
55     }
56
57     public BooleanExpression noteq(SQLExpression expr)
58     {
59         if (expr instanceof FloatingPointLiteral)
60             return new BooleanLiteral(qs, value.compareTo(((FloatingPointLiteral)expr).value) != 0);
61         else
62             return super.noteq(expr);
63     }
64
65     public BooleanExpression lt(SQLExpression expr)
66     {
67         if (expr instanceof FloatingPointLiteral)
68             return new BooleanLiteral(qs, value.compareTo(((FloatingPointLiteral)expr).value) < 0);
69         else
70             return super.lt(expr);
71     }
72
73     public BooleanExpression lteq(SQLExpression expr)
74     {
75         if (expr instanceof FloatingPointLiteral)
76             return new BooleanLiteral(qs, value.compareTo(((FloatingPointLiteral)expr).value) <= 0);
77         else
78             return super.lteq(expr);
79     }
80
81     public BooleanExpression gt(SQLExpression expr)
82     {
83         if (expr instanceof FloatingPointLiteral)
84             return new BooleanLiteral(qs, value.compareTo(((FloatingPointLiteral)expr).value) > 0);
85         else
86             return super.gt(expr);
87     }
88
89     public BooleanExpression gteq(SQLExpression expr)
90     {
91         if (expr instanceof FloatingPointLiteral)
92             return new BooleanLiteral(qs, value.compareTo(((FloatingPointLiteral)expr).value) >= 0);
93         else
94             return super.gteq(expr);
95     }
96
97     public SQLExpression add(SQLExpression expr)
98     {
99         if (expr instanceof FloatingPointLiteral)
100             return new FloatingPointLiteral(qs, value.add(((FloatingPointLiteral)expr).value));
101         else
102             return super.add(expr);
103     }
104
105     public SQLExpression sub(SQLExpression expr)
106     {
107         if (expr instanceof FloatingPointLiteral)
108             return new FloatingPointLiteral(qs, value.subtract(((FloatingPointLiteral)expr).value));
109         else
110             return super.sub(expr);
111     }
112
113     public SQLExpression mul(SQLExpression expr)
114     {
115         if (expr instanceof FloatingPointLiteral)
116             return new FloatingPointLiteral(qs, value.multiply(((FloatingPointLiteral)expr).value));
117         else
118             return super.mul(expr);
119     }
120
121     public SQLExpression div(SQLExpression expr)
122     {
123         if (expr instanceof FloatingPointLiteral)
124             return new FloatingPointLiteral(qs, value.divide(((FloatingPointLiteral)expr).value, BigDecimal.ROUND_DOWN));
125         else
126             return super.mul(expr);
127     }
128
129     public SQLExpression neg()
130     {
131         return new FloatingPointLiteral(qs, value.negate());
132     }
133 }
134
Popular Tags