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: 2004 Andy Jefferson - removed dependency on JDK 1.4 (Boolean.valueOf(boolean))
018: 2004 Andy Jefferson - updated type handling to use datastoreMappings
019: 2007 Andy Jefferson - removed RDBMS-specifics
020: ...
021: **********************************************************************/package org.jpox.store.mapping;
022:
023: import org.jpox.ClassLoaderResolver;
024: import org.jpox.store.expression.BooleanBitColumnExpression;
025: import org.jpox.store.expression.BooleanBitColumnLiteral;
026: import org.jpox.store.expression.BooleanCharColumnExpression;
027: import org.jpox.store.expression.BooleanCharColumnLiteral;
028: import org.jpox.store.expression.BooleanExpression;
029: import org.jpox.store.expression.BooleanLiteral;
030: import org.jpox.store.expression.LogicSetExpression;
031: import org.jpox.store.expression.QueryExpression;
032: import org.jpox.store.expression.ScalarExpression;
033:
034: /**
035: * Mapping of Java Boolean object.
036: *
037: * @version $Revision: 1.21 $
038: */
039: public class BooleanMapping extends SingleFieldMapping implements
040: SimpleDatastoreRepresentation {
041: private static Boolean mappingSampleValue = Boolean.TRUE;
042:
043: public Object getSampleValue(ClassLoaderResolver clr) {
044: return mappingSampleValue;
045: }
046:
047: public ScalarExpression newLiteral(QueryExpression qs, Object value) {
048: ScalarExpression expr;
049: if (getNumberOfDatastoreFields() > 0) {
050: DatastoreMapping data_mapping = getDataStoreMapping(0);
051: if (data_mapping.isBitBased()
052: || data_mapping.isIntegerBased()) {
053: if (dba.isBitReallyBoolean()) {
054: expr = new BooleanLiteral(qs, this ,
055: ((Boolean) value).booleanValue());
056: } else {
057: expr = new BooleanBitColumnLiteral(qs, this ,
058: ((Boolean) value).booleanValue());
059: }
060: } else if (data_mapping.isBooleanBased()) {
061: expr = new BooleanLiteral(qs, this , ((Boolean) value)
062: .booleanValue());
063: } else if (data_mapping.isStringBased()) {
064: expr = new BooleanCharColumnLiteral(qs, this ,
065: ((Boolean) value).booleanValue());
066: } else {
067: expr = new BooleanLiteral(qs, this , ((Boolean) value)
068: .booleanValue());
069: }
070: } else {
071: expr = new BooleanLiteral(qs, this , ((Boolean) value)
072: .booleanValue());
073: }
074: return expr;
075: }
076:
077: public ScalarExpression newScalarExpression(QueryExpression qs,
078: LogicSetExpression te) {
079: ScalarExpression expr;
080: DatastoreMapping data_mapping = getDataStoreMapping(0);
081: if (data_mapping.isBitBased() || data_mapping.isIntegerBased()) {
082: if (dba.isBitReallyBoolean()) {
083: expr = new BooleanExpression(qs, this , te);
084: } else {
085: expr = new BooleanBitColumnExpression(qs, this , te);
086: }
087: } else if (data_mapping.isBooleanBased()) {
088: expr = new BooleanExpression(qs, this , te);
089: } else if (data_mapping.isStringBased()) {
090: expr = new BooleanCharColumnExpression(qs, this , te);
091: } else {
092: expr = new BooleanExpression(qs, this , te);
093: }
094:
095: return expr;
096: }
097:
098: /**
099: * Accessor for the Java type being represented here.
100: * @return The Java type
101: */
102: public Class getJavaType() {
103: return Boolean.class;
104: }
105: }
|