001 package org.apache.ojb.broker.query;
002
003 /* Copyright 2002-2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 /**
019 * SelectionCriteria for 'between x and y'
020 *
021 * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
022 * @version $Id: BetweenCriteria.java,v 1.1 2007-08-24 22:17:36 ewestfal Exp $
023 */
024 public class BetweenCriteria extends ValueCriteria
025 {
026 private Object value2;
027
028 BetweenCriteria(Object anAttribute, Object aValue1, Object aValue2, String aClause, String anAlias)
029 {
030 super(anAttribute, aValue1, aClause, anAlias);
031 setValue2(aValue2);
032 }
033
034 // PAW
035 BetweenCriteria(Object anAttribute, Object aValue1, Object aValue2, String aClause, UserAlias aUserAlias)
036 {
037 super(anAttribute, aValue1, aClause, aUserAlias);
038 setValue2(aValue2);
039 }
040
041 /**
042 * sets the value of the criteria to newValue.
043 * Used by the ODMG OQLQuery.bind() operation
044 * BRJ: bind get's called twice so we need to know which value to set
045 */
046 public void bind(Object newValue)
047 {
048 if (getValue() == null)
049 {
050 setValue(newValue);
051 }
052 else
053 {
054 setValue2(newValue);
055 setBound(true);
056 }
057 }
058
059
060 /**
061 * Gets the value2.
062 * @return Returns a Object
063 */
064 public Object getValue2()
065 {
066 return value2;
067 }
068
069 /**
070 * Sets the value2.
071 * @param value2 The value2 to set
072 */
073 protected void setValue2(Object value2)
074 {
075 this.value2 = value2;
076 }
077
078 /**
079 * @see org.apache.ojb.broker.query.SelectionCriteria#isBindable()
080 */
081 protected boolean isBindable()
082 {
083 return (getValue() == null && getValue2() == null);
084 }
085
086 // PAW
087 /**
088 * String representation
089 */
090 public String toString()
091 {
092 return super.toString() + " AND " + value2;
093 }
094 }
095