001: /**********************************************************************
002: Copyright (c) 2002 Kelly Grizzle (TJDO) and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015: Contributors:
016: 2002 Mike Martin (TJDO)
017: 2003 Andy Jefferson - coding standards
018: ...
019: **********************************************************************/package org.jpox.store.expression;
020:
021: import org.jpox.store.mapping.JavaTypeMapping;
022: import org.jpox.store.query.StatementText;
023:
024: /**
025: * Representation of a BooleanChar column expression.
026: *
027: * @version $Revision: 1.10 $
028: **/
029: public class BooleanCharColumnExpression extends BooleanExpression {
030: private boolean truthTest;
031: private StatementText booleanCondition = new StatementText();
032:
033: /**
034: * Constructor. Perform a positive truth test("<i>this</i> = 1").
035: * @param qs the QueryExpression
036: * @param mapping the mapping associated to this expression
037: * @param te the TableExpression where this expression refers to
038: */
039: public BooleanCharColumnExpression(QueryExpression qs,
040: JavaTypeMapping mapping, LogicSetExpression te) {
041: this (qs, mapping, te, true);
042: }
043:
044: /**
045: * Constructor. Perform a truth test
046: * @param qs the QueryExpression
047: * @param mapping the mapping associated to this expression
048: * @param te the TableExpression where this expression refers to
049: * @param truthTest true for positive ("<i>this</i> = 1"), 0 for negative ("<i>this</i> = 0")
050: */
051: public BooleanCharColumnExpression(QueryExpression qs,
052: JavaTypeMapping mapping, LogicSetExpression te,
053: boolean truthTest) {
054: super (qs, mapping, te);
055:
056: this .truthTest = truthTest;
057: booleanCondition.append(" = ").append(
058: new BooleanCharColumnLiteral(qs, mapping, truthTest));
059:
060: lowestOperator = OP_EQ;
061: }
062:
063: public BooleanExpression not() {
064: return new BooleanCharColumnExpression(qs, mapping, te,
065: !truthTest);
066: }
067:
068: public BooleanExpression eq(ScalarExpression expr) {
069: if (expr instanceof NullLiteral) {
070: return expr.eq(new CharacterExpression(qs, mapping, te));
071: } else if (expr instanceof BooleanCharColumnExpression) {
072: return new BooleanExpression(new CharacterExpression(qs,
073: mapping, te), OP_EQ, new CharacterExpression(qs,
074: expr.mapping, expr.te));
075: } else {
076: return super .eq(expr);
077: }
078: }
079:
080: public BooleanExpression noteq(ScalarExpression expr) {
081: if (expr instanceof NullLiteral) {
082: return expr.noteq(new CharacterExpression(qs, mapping, te));
083: } else if (expr instanceof BooleanCharColumnExpression) {
084: return new BooleanExpression(new CharacterExpression(qs,
085: mapping, te), OP_NOTEQ, new CharacterExpression(qs,
086: expr.mapping, expr.te));
087: } else {
088: return super .noteq(expr);
089: }
090: }
091:
092: public BooleanExpression in(ScalarExpression expr) {
093: return new BooleanExpression(new CharacterExpression(qs,
094: mapping, te), OP_IN, expr);
095: }
096:
097: public StatementText toStatementText(int mode) {
098: StatementText st = super.toStatementText(mode);
099: if (mode == ScalarExpression.FILTER) {
100: st.append(booleanCondition, mode);
101: }
102: return st;
103: }
104: }
|