01: /**********************************************************************
02: Copyright (c) 2002 Kelly Grizzle (TJDO) and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15: Contributors:
16: 2002 Mike Martin (TJDO)
17: 2003 Andy Jefferson - coding standards
18: ...
19: **********************************************************************/package org.jpox.store.expression;
20:
21: import org.jpox.store.mapping.JavaTypeMapping;
22: import org.jpox.store.query.StatementText;
23:
24: /**
25: * Representation of BooleanBit column expression in a Query.
26: *
27: * @version $Revision: 1.10 $
28: **/
29: public class BooleanBitColumnExpression extends BooleanExpression {
30: private boolean truthTest;
31: private StatementText booleanCondition = new StatementText();
32:
33: /**
34: * Constructor. Perform a positive truth test("<i>this</i> = 1").
35: * @param qs the QueryExpression
36: * @param mapping the mapping associated to this expression
37: * @param te the TableExpression where this expression refers to
38: */
39: public BooleanBitColumnExpression(QueryExpression qs,
40: JavaTypeMapping mapping, LogicSetExpression te) {
41: this (qs, mapping, te, true);
42: }
43:
44: /**
45: * Constructor. Perform a truth test
46: * @param qs the QueryExpression
47: * @param mapping the mapping associated to this expression
48: * @param te the TableExpression where this expression refers to
49: * @param truthTest true for positive ("<i>this</i> = 1"), 0 for negative ("<i>this</i> = 0")
50: */
51: public BooleanBitColumnExpression(QueryExpression qs,
52: JavaTypeMapping mapping, LogicSetExpression te,
53: boolean truthTest) {
54: super (qs, mapping, te);
55:
56: this .truthTest = truthTest;
57: booleanCondition.append(" = ").append(
58: new BooleanBitColumnLiteral(qs, mapping, truthTest));
59:
60: lowestOperator = OP_EQ;
61: }
62:
63: public BooleanExpression not() {
64: return new BooleanBitColumnExpression(qs, mapping, te,
65: !truthTest);
66: }
67:
68: public BooleanExpression eq(ScalarExpression expr) {
69: if (expr instanceof NullLiteral) {
70: return expr.eq(new NumericExpression(qs, mapping, te));
71: } else if (expr instanceof BooleanBitColumnExpression) {
72: return new BooleanExpression(new NumericExpression(qs,
73: mapping, te), OP_EQ, new NumericExpression(qs,
74: expr.mapping, expr.te));
75: } else {
76: return super .eq(expr);
77: }
78: }
79:
80: public BooleanExpression noteq(ScalarExpression expr) {
81: if (expr instanceof NullLiteral) {
82: return expr.noteq(new NumericExpression(qs, mapping, te));
83: } else if (expr instanceof BooleanBitColumnExpression) {
84: return new BooleanExpression(new NumericExpression(qs,
85: mapping, te), OP_NOTEQ, new NumericExpression(qs,
86: expr.mapping, expr.te));
87: } else {
88: return super .noteq(expr);
89: }
90: }
91:
92: public StatementText toStatementText(int mode) {
93: StatementText st = super.toStatementText(mode);
94: if (mode == ScalarExpression.FILTER) {
95: st.append(booleanCondition, mode);
96: }
97: return st;
98: }
99: }
|