001: /*
002: * Copyright 2004 (C) TJDO.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the TJDO License version 1.0.
006: * See the terms of the TJDO License in the documentation provided with this software.
007: *
008: * $Id: FloatingPointLiteral.java,v 1.5 2004/01/18 03:01:06 jackknifebarber Exp $
009: */
010:
011: package com.triactive.jdo.store;
012:
013: import com.triactive.jdo.util.SQLFormat;
014: import java.math.BigDecimal;
015:
016: class FloatingPointLiteral extends NumericExpression {
017: private final BigDecimal value;
018:
019: public FloatingPointLiteral(QueryStatement qs, Float value) {
020: super (qs);
021:
022: this .value = new BigDecimal(value.toString());
023:
024: DatabaseAdapter dba = qs.getStoreManager().getDatabaseAdapter();
025: st.appendParameter((ColumnMapping) dba.getMapping(Float.class),
026: value);
027: }
028:
029: public FloatingPointLiteral(QueryStatement qs, Double value) {
030: super (qs);
031:
032: this .value = new BigDecimal(value.toString());
033:
034: DatabaseAdapter dba = qs.getStoreManager().getDatabaseAdapter();
035: st.appendParameter(
036: (ColumnMapping) dba.getMapping(Double.class), value);
037: }
038:
039: public FloatingPointLiteral(QueryStatement qs, BigDecimal value) {
040: super (qs);
041:
042: this .value = value;
043: st.append(SQLFormat.format(value));
044: }
045:
046: public BooleanExpression eq(SQLExpression expr) {
047: if (expr instanceof FloatingPointLiteral)
048: return new BooleanLiteral(
049: qs,
050: value
051: .compareTo(((FloatingPointLiteral) expr).value) == 0);
052: else
053: return super .eq(expr);
054: }
055:
056: public BooleanExpression noteq(SQLExpression expr) {
057: if (expr instanceof FloatingPointLiteral)
058: return new BooleanLiteral(
059: qs,
060: value
061: .compareTo(((FloatingPointLiteral) expr).value) != 0);
062: else
063: return super .noteq(expr);
064: }
065:
066: public BooleanExpression lt(SQLExpression expr) {
067: if (expr instanceof FloatingPointLiteral)
068: return new BooleanLiteral(qs, value
069: .compareTo(((FloatingPointLiteral) expr).value) < 0);
070: else
071: return super .lt(expr);
072: }
073:
074: public BooleanExpression lteq(SQLExpression expr) {
075: if (expr instanceof FloatingPointLiteral)
076: return new BooleanLiteral(
077: qs,
078: value
079: .compareTo(((FloatingPointLiteral) expr).value) <= 0);
080: else
081: return super .lteq(expr);
082: }
083:
084: public BooleanExpression gt(SQLExpression expr) {
085: if (expr instanceof FloatingPointLiteral)
086: return new BooleanLiteral(qs, value
087: .compareTo(((FloatingPointLiteral) expr).value) > 0);
088: else
089: return super .gt(expr);
090: }
091:
092: public BooleanExpression gteq(SQLExpression expr) {
093: if (expr instanceof FloatingPointLiteral)
094: return new BooleanLiteral(
095: qs,
096: value
097: .compareTo(((FloatingPointLiteral) expr).value) >= 0);
098: else
099: return super .gteq(expr);
100: }
101:
102: public SQLExpression add(SQLExpression expr) {
103: if (expr instanceof FloatingPointLiteral)
104: return new FloatingPointLiteral(qs, value
105: .add(((FloatingPointLiteral) expr).value));
106: else
107: return super .add(expr);
108: }
109:
110: public SQLExpression sub(SQLExpression expr) {
111: if (expr instanceof FloatingPointLiteral)
112: return new FloatingPointLiteral(qs, value
113: .subtract(((FloatingPointLiteral) expr).value));
114: else
115: return super .sub(expr);
116: }
117:
118: public SQLExpression mul(SQLExpression expr) {
119: if (expr instanceof FloatingPointLiteral)
120: return new FloatingPointLiteral(qs, value
121: .multiply(((FloatingPointLiteral) expr).value));
122: else
123: return super .mul(expr);
124: }
125:
126: public SQLExpression div(SQLExpression expr) {
127: if (expr instanceof FloatingPointLiteral)
128: return new FloatingPointLiteral(qs, value.divide(
129: ((FloatingPointLiteral) expr).value,
130: BigDecimal.ROUND_DOWN));
131: else
132: return super .mul(expr);
133: }
134:
135: public SQLExpression neg() {
136: return new FloatingPointLiteral(qs, value.negate());
137: }
138: }
|