001/*
002 * Copyright (c) 2003-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: welker $'
006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 
007 * '$Revision: 24234 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.ecoinformatics.seek.querybuilder;
031
032import org.kepler.objectmanager.data.DataType;
033
034/**
035 * THis class is a model class for a condition of a where clause
036 */
037public class DBWhereCondition extends DBWhereListCellBase {
038        /**
039         * Constructor
040         * 
041         * @param aParent
042         *            parent to be added to
043         * @param aTableName
044         *            name of item
045         * @param aFieldName
046         *            field name of item
047         * @param aDataType
048         *            the datatype
049         */
050        public DBWhereCondition(DBWhereOperator aParent, String aTableName,
051                        String aFieldName, String aDataType) {
052                super(aParent);
053                mParent = aParent;
054                mName = aFieldName;
055                mTableName = aTableName;
056                mDataType = aDataType;
057                mOper = DBSelectTableUIStd.OPERS_TXT[DBSelectTableUIStd.EQUALS_INX];
058        }
059
060        /**
061         * Copy Constructor (does not copy parent), sets it to the new parent
062         * 
063         * @param aParent
064         *            parent to be added to
065         * @param aCond
066         *            object to be copied
067         */
068        public DBWhereCondition(DBWhereOperator aParent, DBWhereCondition aCond) {
069                super(aParent);
070                mParent = aParent;
071                mName = aCond.mName;
072                mTableName = aCond.mTableName;
073                mDataType = aCond.mDataType;
074                mOper = aCond.mOper;
075                mDepth = aCond.mDepth;
076                mCriteria = aCond.mCriteria;
077                mIsDisplayed = aCond.mIsDisplayed;
078                mTableId = aCond.mTableId;
079        }
080
081        /**
082         * Indicates whether it is an operator
083         * 
084         * @return whether it is an operator or not
085         */
086        public boolean isOperator() {
087                return false;
088        }
089
090        /**
091         * Converts the entire condition to a string
092         * 
093         * @param aUseSymbols
094         *            indicates whether to return a string as a symbol or as text
095         * @return its representation as a string
096         */
097        public String toString(boolean aUseSymbols) {
098
099                StringBuffer strBuf = new StringBuffer(DBUIUtils.getFullFieldName(
100                                mTableName, mName)
101                                + " "
102                                + (aUseSymbols ? DBSelectTableUIStd.getBoolOperSymbol(mOper)
103                                                : mOper));
104                if (getCriteria().length() > 0) {
105                        if (mDataType.equals(DataType.STR))
106                                strBuf.append(" '" + getCriteria() + "'");
107                        else
108                                strBuf.append(" " + getCriteria());
109                } else {
110                        strBuf.append("  <no criteria>");
111                }
112                return strBuf.toString();
113        }
114
115        /**
116         * Converts the entire condition to a string
117         * 
118         * @return its representation as a string
119         */
120        public String toString() {
121                return toString(false);
122        }
123
124}