001: /*
002: * Copyright 2002 (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: BooleanExpression.java,v 1.4 2003/08/11 16:01:51 pierreg0 Exp $
009: */
010:
011: package com.triactive.jdo.store;
012:
013: import java.util.List;
014:
015: class BooleanExpression extends SQLExpression {
016: public BooleanExpression(QueryStatement qs) {
017: super (qs);
018: }
019:
020: public BooleanExpression(QueryStatement qs,
021: QueryStatement.QueryColumn qsc) {
022: super (qs, qsc);
023: }
024:
025: public BooleanExpression(String functionName, List args) {
026: super (functionName, args);
027: }
028:
029: public BooleanExpression(MonadicOperator op, SQLExpression operand) {
030: super (op, operand);
031: }
032:
033: public BooleanExpression(SQLExpression operand1, DyadicOperator op,
034: SQLExpression operand2) {
035: super (operand1, op, operand2);
036: }
037:
038: public BooleanExpression and(SQLExpression expr) {
039: if (expr instanceof BooleanLiteral)
040: return expr.and(this );
041: else if (expr instanceof BooleanExpression)
042: return new BooleanExpression(this , OP_AND, expr);
043: else
044: return super .and(expr);
045: }
046:
047: public BooleanExpression eor(SQLExpression expr) {
048: if (expr instanceof BooleanLiteral)
049: return expr.eor(this );
050: else if (expr instanceof BooleanExpression) {
051: if (qs.getStoreManager().getDatabaseAdapter()
052: .supportsBooleanComparison())
053: return new BooleanExpression(this , OP_NOTEQ, expr);
054: else
055: return and(expr.not()).ior(not().and(expr));
056: } else
057: return super .eor(expr);
058: }
059:
060: public BooleanExpression ior(SQLExpression expr) {
061: if (expr instanceof BooleanLiteral)
062: return expr.ior(this );
063: else if (expr instanceof BooleanExpression)
064: return new BooleanExpression(this , OP_OR, expr);
065: else
066: return super .ior(expr);
067: }
068:
069: public BooleanExpression not() {
070: return new BooleanExpression(OP_NOT, this );
071: }
072:
073: public BooleanExpression eq(SQLExpression expr) {
074: if (expr instanceof BooleanLiteral
075: || expr instanceof NullLiteral)
076: return expr.eq(this );
077: else if (expr instanceof BooleanExpression) {
078: if (qs.getStoreManager().getDatabaseAdapter()
079: .supportsBooleanComparison())
080: return new BooleanExpression(this , OP_EQ, expr);
081: else
082: return and(expr).ior(not().and(expr.not()));
083: } else
084: return super .eq(expr);
085: }
086:
087: public BooleanExpression noteq(SQLExpression expr) {
088: if (expr instanceof BooleanLiteral
089: || expr instanceof NullLiteral)
090: return expr.noteq(this );
091: else if (expr instanceof BooleanExpression) {
092: if (qs.getStoreManager().getDatabaseAdapter()
093: .supportsBooleanComparison())
094: return new BooleanExpression(this , OP_NOTEQ, expr);
095: else
096: return and(expr.not()).ior(not().and(expr));
097: } else
098: return super .noteq(expr);
099: }
100:
101: public BooleanExpression in(SQLExpression expr) {
102: return new BooleanExpression(this, OP_IN, expr);
103: }
104: }
|