KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jofti > query > MatchRangeQuery


1 package com.jofti.query;
2
3 import com.jofti.api.IndexQuery;
4 import com.jofti.core.QueryId;
5 import com.jofti.core.QueryType;
6 import com.jofti.util.ReflectionUtil;
7
8 /**
9  *
10  *
11 * A utility class to enable simple queries to be done easily. The Query matches
12 * ranges for particular field. This is equivalent to (>= and <=) or (> and <).<p>
13  *
14  *
15  * This query cannot be combined with any other. iF you want to construct more complex queries use the @link com.jofti.query.Query class.
16  <p>
17  * @author steve Woodcock
18  */

19
20 public class MatchRangeQuery implements IndexQuery, QueryId {
21
22     public final Object JavaDoc alias;
23     int hashCode =0;
24     Class JavaDoc className;
25     String JavaDoc propertyName;
26     Comparable JavaDoc startValue;
27     Comparable JavaDoc endValue;
28     boolean inclusive =true;
29     
30      static final QueryType QUERY_ID=QueryType.RANGE_QUERY;
31     
32     /**
33      * Construct a query supplying the classname of the object type to be returned, the field to be queried and the start and finish values to be used.
34      * <p>
35      * The field type in the object and the values must be of the same type. In addition the end value must
36      * be greater (comparaison >0 ) than the start value;
37      * <p>
38      * An example usage would be:
39      * <p>
40      * new MatchNSQuery(org.package.Myclass.class, "myProperty" ,10,20);
41      * <p>
42      * @param className - the class of object to be returned.
43      * @param propertyName - the field name to use
44      * @param startValue - the value that is used as the start search value.
45      * @param endValue - the value that is used as the end search value.
46      */

47      public MatchRangeQuery(Class JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc startValue,Comparable JavaDoc endValue){
48         this(className,propertyName,startValue,endValue,null);
49     }
50      
51     public MatchRangeQuery(Class JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc startValue,Comparable JavaDoc endValue,Object JavaDoc alias){
52         this.className = className;
53         this.propertyName = propertyName;
54         this.startValue = startValue;
55         this.endValue = endValue;
56         this.alias = alias;
57     }
58     
59     /**
60      * Construct a query supplying the classname of the object type to be returned, the field to be queried and the start and finish values to be used.
61      * <p>
62      * The field type in the object and the values must be of the same type. In addition the end value must
63      * be greater (comparaison >0 ) than the start value;
64      * <p>
65      * An example usage would be:
66      * <p>
67      * new MatchNSQuery("org.package.Myclass", "myProperty" ,10,20);
68      * <p>
69      * @param className - the class of object to be returned.
70      * @param propertyName - the field name to use
71      * @param startValue - the value that is used as the start search value.
72      * @param endValue - the value that is used as the end search value.
73      */

74     public MatchRangeQuery(String JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc startValue,Comparable JavaDoc endValue){
75         this(className,propertyName,startValue,endValue,null);
76     }
77     public MatchRangeQuery(String JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc startValue,Comparable JavaDoc endValue,Object JavaDoc alias){
78         Class JavaDoc clazz = null;
79         try{
80             clazz = ReflectionUtil.classForName(className);
81         }catch (Exception JavaDoc e){
82             throw new RuntimeException JavaDoc(e);
83         }
84         this.className = clazz;
85         this.propertyName = propertyName;
86         this.startValue = startValue;
87         this.endValue = endValue;
88         this.alias =alias;
89     }
90     /**
91      * Construct a query supplying the classname of the object type to be returned, the field to be queried and the start and finish values to be used.
92      * <p>
93      * The field type in the object and the values must be of the same type. In addition the end value must
94      * be greater (comparaison >0 ) than the start value. thi method also allows the setting of search inclusivity.
95      * <p>
96      * An example usage would be:
97      * <p>
98      * new MatchNSQuery(org.package.Myclass.class, "myProperty" ,10,20, true);
99      * <p>
100      * @param className - the class of object to be returned.
101      * @param propertyName - the field name to use
102      * @param startValue - the value that is used as the start search value.
103      * @param endValue - the value that is used as the end search value.
104      * @param inclusive - whether a search is inclusive of values
105      */

106     public MatchRangeQuery(Class JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc startValue,Comparable JavaDoc endValue,boolean inclusive){
107         this(className,propertyName,startValue,endValue,null);
108     }
109     public MatchRangeQuery(Class JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc startValue,Comparable JavaDoc endValue,boolean inclusive,Object JavaDoc alias){
110         this.className = className;
111         this.propertyName = propertyName;
112         this.startValue = startValue;
113         this.endValue = endValue;
114         this.inclusive = inclusive;
115         this.alias = alias;
116     }
117     
118     /**
119      * Construct a query supplying the classname of the object type to be returned, the field to be queried and the start and finish values to be used.
120      * <p>
121      * The field type in the object and the values must be of the same type. In addition the end value must
122      * be greater (comparaison >0 ) than the start value. thi method also allows the setting of search inclusivity.
123      * <p>
124      * An example usage would be:
125      * <p>
126      * new MatchNSQuery("org.package.Myclass", "myProperty" ,10,20, true);
127      * <p>
128      * @param className - the class of object to be returned.
129      * @param propertyName - the field name to use
130      * @param startValue - the value that is used as the start search value.
131      * @param endValue - the value that is used as the end search value.
132      * @param inclusive - whether a search is inclusive of values
133      */

134     public MatchRangeQuery(String JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc startValue,Comparable JavaDoc endValue,boolean inclusive){
135         this(className, propertyName,startValue,endValue,inclusive,null);
136     }
137     
138     public MatchRangeQuery(String JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc startValue,Comparable JavaDoc endValue,boolean inclusive,Object JavaDoc alias){
139         Class JavaDoc clazz = null;
140         try{
141             clazz = ReflectionUtil.classForName(className);
142         }catch (Exception JavaDoc e){
143             throw new RuntimeException JavaDoc(e);
144         }
145         this.className = clazz;
146         this.propertyName = propertyName;
147         this.startValue = startValue;
148         this.endValue = endValue;
149         this.inclusive = inclusive;
150         this.alias =alias;
151     }
152     /**
153      * Construct a query supplying the start and finish values to be used.
154      * <p>
155      * The values must be of the same type. In addition the end value must
156      * be greater (comparaison >0 ) than the start value. This is a convenience method for classes (such as String,Integer etc)
157      * that have no property value as such. Instead the value is the class type. This method also allows the setting of search inclusivity.
158      * <p>
159      * An example usage would be:
160      * <p>
161      * new MatchRangeQuery(new Integer(10), new Integer(20), true);
162      * <p>
163      * @param startValue - the value that is used as the start search value.
164      * @param endValue - the value that is used as the end search value.
165      * @param inclusive - whether a search is inclusive of values
166      */

167     public MatchRangeQuery(Comparable JavaDoc startValue,Comparable JavaDoc endValue, boolean inclusive){
168         this(startValue,endValue,inclusive,null);
169     }
170     public MatchRangeQuery(Comparable JavaDoc startValue,Comparable JavaDoc endValue, boolean inclusive,Object JavaDoc alias){
171         this.startValue = startValue;
172         this.endValue = endValue;
173         this.inclusive = inclusive;
174         this.alias =alias;
175     }
176     /**
177      * @return Returns the className.
178      */

179     public Class JavaDoc getClassName() {
180         return className;
181     }
182
183     /**
184      * @return Returns the propertyName.
185      */

186     public String JavaDoc getPropertyName() {
187         return propertyName;
188     }
189
190     /**
191      * @return Returns the value.
192      */

193     
194     
195     /**
196      * @return Returns the endValue.
197      */

198     public Comparable JavaDoc getEndValue() {
199         return endValue;
200     }
201
202     /**
203      * @return Returns the startValue.
204      */

205     public Comparable JavaDoc getStartValue() {
206         return startValue;
207     }
208     public boolean isInclusive() {
209         return inclusive;
210     }
211     public void setInclusive(boolean inclusive) {
212         this.inclusive = inclusive;
213     }
214
215     public QueryType getQueryType()
216     {
217         
218         return QUERY_ID;
219     }
220     
221  
222     public Object JavaDoc getAlias() {
223         return alias;
224     }
225     
226     public IndexQuery setParameter(String JavaDoc name, Object JavaDoc value) {
227         throw new UnsupportedOperationException JavaDoc("Parameters are not supported for convenience classes");
228     }
229     /* (non-Javadoc)
230      * @see com.jofti.api.IndexQuery#setParameter(int, java.lang.Object)
231      */

232     public IndexQuery setParameter(int position, Object JavaDoc value) {
233         throw new UnsupportedOperationException JavaDoc("Parameters are not supported for convenience classes");
234
235     }
236
237     public IndexQuery setFirstResult(int firstResult) {
238         throw new UnsupportedOperationException JavaDoc("result limits are not supported for convenience classes");
239
240     }
241     public IndexQuery setMaxResults(int maxResults) {
242         throw new UnsupportedOperationException JavaDoc("result limits are not supported for convenience classes");
243
244     }
245 }
246
Popular Tags