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: BooleanLiteral.java,v 1.4 2003/08/11 16:01:51 pierreg0 Exp $
09: */
10:
11: package com.triactive.jdo.store;
12:
13: class BooleanLiteral extends BooleanExpression {
14: private final boolean value;
15:
16: public BooleanLiteral(QueryStatement qs, boolean value) {
17: super (qs);
18:
19: this .value = value;
20: st.append(value ? getBooleanTrueValue()
21: : getBooleanFalseValue());
22: }
23:
24: /**
25: * Return the String value for TRUE in the database. This should be
26: * overriden by subclasses for special cases of booleans.
27: *
28: * @return The String value for TRUE in the database.
29: */
30: protected String getBooleanTrueValue() {
31: return "TRUE";
32: }
33:
34: /**
35: * Return the String value for FALSE in the database. This should be
36: * overriden by subclasses for special cases of booleans.
37: *
38: * @return The String value for FALSE in the database.
39: */
40: protected String getBooleanFalseValue() {
41: return "FALSE";
42: }
43:
44: public BooleanExpression and(SQLExpression expr) {
45: if (expr instanceof BooleanExpression)
46: return value ? (BooleanExpression) expr : this ;
47: else
48: return super .and(expr);
49: }
50:
51: public BooleanExpression eor(SQLExpression expr) {
52: if (expr instanceof BooleanExpression)
53: return value ? expr.not() : (BooleanExpression) expr;
54: else
55: return super .eor(expr);
56: }
57:
58: public BooleanExpression ior(SQLExpression expr) {
59: if (expr instanceof BooleanExpression)
60: return value ? this : (BooleanExpression) expr;
61: else
62: return super .ior(expr);
63: }
64:
65: public BooleanExpression not() {
66: return new BooleanLiteral(qs, !value);
67: }
68:
69: public BooleanExpression eq(SQLExpression expr) {
70: if (expr instanceof BooleanExpression)
71: return value ? (BooleanExpression) expr : expr.not();
72: else
73: return super .eq(expr);
74: }
75:
76: public BooleanExpression noteq(SQLExpression expr) {
77: if (expr instanceof BooleanExpression)
78: return value ? expr.not() : (BooleanExpression) expr;
79: else
80: return super.noteq(expr);
81: }
82: }
|