KickJava   Java API By Example, From Geeks To Geeks.

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


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: BooleanLiteral.java,v 1.4 2003/08/11 16:01:51 pierreg0 Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13
14 class BooleanLiteral extends BooleanExpression
15 {
16     private final boolean value;
17
18
19     public BooleanLiteral(QueryStatement qs, boolean value)
20     {
21         super(qs);
22         
23         this.value = value;
24         st.append(value ? getBooleanTrueValue() : getBooleanFalseValue());
25     }
26
27
28     /**
29      * Return the String value for TRUE in the database. This should be
30      * overriden by subclasses for special cases of booleans.
31      *
32      * @return The String value for TRUE in the database.
33      */

34     protected String JavaDoc getBooleanTrueValue()
35     {
36         return "TRUE";
37     }
38
39
40     /**
41      * Return the String value for FALSE in the database. This should be
42      * overriden by subclasses for special cases of booleans.
43      *
44      * @return The String value for FALSE in the database.
45      */

46     protected String JavaDoc getBooleanFalseValue()
47     {
48         return "FALSE";
49     }
50
51
52     public BooleanExpression and(SQLExpression expr)
53     {
54         if (expr instanceof BooleanExpression)
55             return value ? (BooleanExpression)expr : this;
56         else
57             return super.and(expr);
58     }
59
60     public BooleanExpression eor(SQLExpression expr)
61     {
62         if (expr instanceof BooleanExpression)
63             return value ? expr.not() : (BooleanExpression)expr;
64         else
65             return super.eor(expr);
66     }
67
68     public BooleanExpression ior(SQLExpression expr)
69     {
70         if (expr instanceof BooleanExpression)
71             return value ? this : (BooleanExpression)expr;
72         else
73             return super.ior(expr);
74     }
75
76     public BooleanExpression not()
77     {
78         return new BooleanLiteral(qs, !value);
79     }
80
81     public BooleanExpression eq(SQLExpression expr)
82     {
83         if (expr instanceof BooleanExpression)
84             return value ? (BooleanExpression)expr : expr.not();
85         else
86             return super.eq(expr);
87     }
88
89     public BooleanExpression noteq(SQLExpression expr)
90     {
91         if (expr instanceof BooleanExpression)
92             return value ? expr.not() : (BooleanExpression)expr;
93         else
94             return super.noteq(expr);
95     }
96 }
97
Popular Tags