View Javadoc

1   /***
2   Copyright (C) 2005 The Java Community
3   
4   This program is free software; you can redistribute it and/or modify  it under
5   the terms of the GNU General Public License as published by  the Free Software
6   Foundation; either version 2 of the License, or  (at your option) any later
7   version.
8   
9   This program is distributed in the hope that it will be useful,  but WITHOUT
10  ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS
11  FOR A PARTICULAR PURPOSE. See the  GNU General Public License for more details.
12  
13  You should have received a copy of the GNU General Public License  along with
14  this program; if not, write to the Free Software  Foundation, Inc., 59 Temple
15  Place, Suite 330, Boston, MA 02111-1307 USA.
16  
17  */
18  package org.bejug.javacareers.common.search;
19  
20  /***
21   * For use only in the SearchCriteria-class.
22   * @author Bart Meyers (last modified by $Author: shally $)
23   * @version $Revision: 1.4 $ $Date: 2005/12/20 15:36:43 $
24   */
25  public class Criterium {
26      /***
27       * constant for the sql-equal.
28       */
29      public static final String EQUALS = "equals";
30      
31      /***
32       * constant for the sql-not-equals.
33       */
34      public static final String NOT_EQUALS = "notEquals";
35      
36      /***
37       * constant for the sql-greaterThen.
38       */
39      public static final String GREATER_THAN = "greaterThan";
40      
41      /***
42       * constant for the sql-greaterThanEquals.
43       */
44      public static final String GREATER_THAN_EQUALS = "greaterThanEquals";
45      
46      /***
47       * constant for the sql-lowerThan.
48       */
49      public static final String LOWER_THAN = "lowerThan";
50      
51      /***
52       * constant for the sql-lowerThanEquals.
53       */
54      public static final String LOWER_THAN_EQUALS = "lowerThanEquals";
55      
56      /***
57       * constant for the sql-not.
58       */
59      public static final String NOT = "not";
60      
61      /***
62       * constant for the sql-like.
63       */
64      public static final String LIKE = "like";
65      
66      /***
67       * constant for the sql-not-like.
68       */
69      public static final String NOT_LIKE = "notLike";
70      
71      /***
72       * constant for the sql-betweeb.
73       */
74      public static final String BETWEEN = "between";
75      
76      
77      /***
78       * constant for the sql-in 
79       */
80      public static final String IN = "in";
81      
82      
83      /***
84       * constant for the logical-and
85       */
86      public static final int LOGICAL_AND = 1;
87      
88      /***
89       * constant for the logical-or
90       */
91      public static final int LOGICAL_OR = 2;
92      
93      /***
94       * boolean to indicate whether this is an equals-criterium.
95       */
96      private boolean equals = false;
97      
98      /***
99       * boolean to indicate whether this is an not-equals-criterium.
100      */
101     private boolean notEquals = false;
102     
103     /***
104      * boolean to indicate whether this is an greaterThan-criterium.
105      */
106     private boolean greaterThan = false;
107     
108     /***
109      * boolean to indicate whether this is an greaterThanEquals-criterium.
110      */
111     private boolean greaterThanEquals = false;
112     
113     /***
114      * boolean to indicate whether this is an lowerThan-criterium.
115      */
116     private boolean lowerThan = false;
117     
118     /***
119      * boolean to indicate whether this is an lowerThanEquals-criterium.
120      */
121     private boolean lowerThanEquals = false;
122     
123     /***
124      * boolean to indicate whether this is a not-criterium.
125      */
126     private boolean not = false;
127     
128     /***
129      * boolean to indicate whether this is an like-criterium.
130      */
131     private boolean like = false;
132     
133     /***
134      * boolean to indicate whether this is an notLike-criterium.
135      */
136     private boolean notLike = false;
137     
138     /***
139      * boolean to indicate whether this is an between-criterium.
140      */
141     private boolean between = false;
142     
143     
144     /***
145      * boolean to indicate whether this is an in-criterium. 
146      */
147     private boolean in = false;
148     
149         
150     /***
151      * the name of the column to put the restriction on
152      */
153     private String name = null;
154     
155     /***
156      * the first value of the restriction to match.
157      */
158     private Object value1 = null;
159     
160     /***
161      * the second value of the restriction to match.
162      */
163     private Object value2 = null;
164     
165     /***
166      * if more than two values needs to be matched(for the in-operator).
167      */
168     private Object[] values = null;
169     
170     
171     /***
172      * boolean indicating whether the logical operator is and.
173      */
174     private boolean and = false;
175     
176     /***
177      * boolean indicating whether the logical operator is or.
178      */
179     private boolean or = false;
180     
181     
182     /***
183      * main constructor with default and-behavior and equals funtionality.
184      * @param name the name of the column to put the restriction on.
185      * @param value the value to match.
186      */
187     public Criterium(String name, Object value) {
188         this(name, value, EQUALS, LOGICAL_AND);        
189     }
190     
191     /***
192      * constructor.
193      * @param name the name of the column to put the restriction on.
194      * @param value the value to match.
195      * @param operation the operation to perform.
196      * @param logicalOperator int
197      */
198     public Criterium(String name, Object value, String operation, 
199             int logicalOperator) {
200         this.name = name;
201         this.value1 = value;
202         setOperation(operation);
203         if (LOGICAL_OR == logicalOperator){
204         	this.or = true;
205         }
206         else {
207         	this.and = true;
208         }
209     }
210     
211     /***
212      * constructor, assuming default logical operator: and.
213      * @param name the name of the column to put the restriction on.
214      * @param value the value to match.
215      * @param operation the operatoon for this criterium.
216      */
217     public Criterium(String name, Object value, String operation) {
218         this(name, value, operation, LOGICAL_AND);
219     }
220     
221     /***
222      * constructor for operations that needs two values. Logical operator: and.
223      * @param name the name of the column to put the restriction on.
224      * @param value1 the first value to match.
225      * @param value2 the second value to match.
226      * @param operation the operation to perform.
227      */
228     public Criterium(String name, Object value1, Object value2, 
229             String operation) {
230         this(name, value1, value2, operation, LOGICAL_AND);
231     }
232     
233     /***
234      * constructor for operations that needs two values.
235      * @param name the name of the column to put the restriction on.
236      * @param value1 the first value to match.
237      * @param value2 the second value to match.
238      * @param operation the operation to perform.
239      * @param logicalOperator an int indicating the logicaloperator to use.
240      */
241     public Criterium(String name, Object value1, Object value2, 
242             String operation, int logicalOperator) {
243         this(name, value1, operation, logicalOperator);
244         this.value2 = value2;
245     }
246     
247     /***
248      * constructor for operations that needs more than two values.
249      * This is only for the in-operator, so the operation doens't need to be
250      * provided.
251      * @param name the name of the column to put the restriction on.
252      * @param values [] the array of values to put the restriction on.
253      * @param operation String.
254      */
255     public Criterium(String name, Object[] values, String operation) {
256         this(name, values, operation, LOGICAL_AND);
257         this.values = values;
258     }
259     
260     /***
261      * constructor for operations that needs more than two values.
262      * This is only for the in-operator, so the operation doens't need to be
263      * provided.
264      * @param name the name of the column to put the restriction on.
265      * @param values [] the array of values to put the restriction on.
266      * @param logicalOperator an int indicating the logicaloperator to use.
267      * @param operation String.
268      */
269     public Criterium(String name, Object[] values, String operation, int logicalOperator) {
270     	this.name = name;
271     	this.values = values;
272         setOperation(Criterium.IN);
273         if (LOGICAL_OR == logicalOperator){
274         	this.or = true;
275         }
276         else {
277         	this.and = true;
278         }
279         this.values = values;
280     }
281     
282     /***
283      * @return the wanted name.
284      */
285     public String getName() {
286         return this.name;
287     }
288     
289     /***
290      * @param criteriaName the name to set.
291      */
292     public void setName(String criteriaName) {
293         this.name = criteriaName;
294     }
295     
296     /***
297      * @return the wanted first value.
298      */
299     public Object getValue1() {
300         return this.value1;
301     }
302     
303     /***
304      * @param value the first value.
305      */
306     public void setValue1(Object value) {
307         this.value1 = value;
308     }
309     
310     /***
311      * @return the wanted second value.
312      */
313     public Object getValue2() {
314         return this.value2;
315     }
316     
317     /***
318      * @param values the values to set.
319      */
320     public void setValues(Object[] values) {
321         this.values = values;
322     }
323     
324     /***
325      * @return the wanted values-array.
326      */
327     public Object[] getValues() {
328         return this.values;
329     }
330     
331     
332     /***
333      * @param value the second value.
334      */
335     public void setValue2(Object value) {
336         this.value2 = value;
337     }
338     
339     /***
340      * sets the operation of the Criterium.
341      * @param operation the operation to set, should be a consant defined in 
342      * this class.
343      */
344     private void setOperation(String operation) {
345         if (EQUALS.equals(operation)) {
346             this.equals = true;
347             return;
348         }
349         if (NOT_EQUALS.equals(operation)) {
350             notEquals = true;
351             return;
352         } 
353         if (GREATER_THAN.equals(operation)) {
354             greaterThan = true;
355             return;
356         }
357         if (GREATER_THAN_EQUALS.equals(operation)) {
358             greaterThanEquals = true;
359             return;
360         }
361         if (LOWER_THAN.equals(operation)) {
362             lowerThan = true;
363             return;
364         }
365         if (LOWER_THAN_EQUALS.equals(operation)) {
366             lowerThanEquals = true;
367             return;
368         }
369         if (LIKE.equals(operation)) {
370             like = true;
371             return;
372         }
373         if (NOT_LIKE.equals(operation)) {
374             notLike = true;
375             return;
376         }
377         if (BETWEEN.equals(operation)) {
378             between = true;
379             return;
380         }
381         if (IN.equals(operation)) {
382             in = true;
383             return;
384         }
385         if (NOT.equals(operation)) {        
386             not = true;
387             return;
388         }
389     }
390     
391     /***
392      * @return whether the sql-action is not.
393      */
394     public boolean isNot() {
395         return not;
396     }
397     
398     /***
399      * @param not set the sql-action to not.
400      */
401     public void setNot(boolean not) {
402         this.not = not;
403     }
404     
405     /***
406      * @return whether the sql-action is equal.
407      */
408     public boolean isEquals() {
409         return equals;
410     }
411     
412     /***
413      * @param equals set the sql-action to equal.
414      */
415     public void setEquals(boolean equals) {
416         this.equals = equals;
417     }
418     
419     /***
420      * @return whether the sql-action is notequal.
421      */
422     public boolean isNotEquals() {
423         return notEquals;
424     }
425     
426     /***
427      * @param notEquals set the sql-action to notequal.
428      */
429     public void setNotEquals(boolean notEquals) {
430         this.notEquals = notEquals;
431     }
432     
433     /***
434      * @return whether the sql-action is greaterThen.
435      */
436     public boolean isGreaterThan() {
437         return greaterThan;
438     }
439     
440     /***
441      * @param greaterThan set the sql-action to greaterThan.
442      */
443     public void setGreaterThan(boolean greaterThan) {
444         this.greaterThan = greaterThan;
445     }
446     
447     /***
448      * @return whether the sql-action is greaterThanEquals.
449      */
450     public boolean isGreaterThanEquals() {
451         return greaterThanEquals;
452     }
453     
454     /***
455      * @param greaterThanEquals set the sql-action to greaterThanEquals.
456      */
457     public void setGreaterThanEquals(boolean greaterThanEquals) {
458         this.greaterThanEquals = greaterThanEquals;
459     }
460     
461     /***
462      * @return whether the sql-action is like.
463      */
464     public boolean isLike() {
465         return like;
466     }
467     
468     /***
469      * @param like set the sql-action to like.
470      */
471     public void setLike(boolean like) {
472         this.like = like;
473     }
474     
475     /***
476      * @return whether the sql-action is lowerThan.
477      */
478     public boolean isLowerThan() {
479         return lowerThan;
480     }
481     
482     /***
483      * @param lowerThan set the sql-action to lowerThan.
484      */
485     public void setLowerThan(boolean lowerThan) {
486         this.lowerThan = lowerThan;
487     }
488     
489     /***
490      * @return whether the sql-action is lowerThanEquals.
491      */
492     public boolean isLowerThanEquals() {
493         return lowerThanEquals;
494     }
495     
496     /***
497      * @param lowerThanEquals set the sql-action to lowerThanEquals.
498      */
499     public void setLowerThanEquals(boolean lowerThanEquals) {
500         this.lowerThanEquals = lowerThanEquals;
501     }
502     
503     /***
504      * @return whether the sql-action is not like.
505      */
506     public boolean isNotLike() {
507         return notLike;
508     }
509     
510     /***
511      * @param notLike set the sql-action to not like.
512      */
513     public void setNotLike(boolean notLike) {
514         this.notLike = notLike;
515     }
516     
517     /***
518      * @return whether the sql-action is between.
519      */
520     public boolean isBetween() {
521         return between;
522     }
523     
524     /***
525      * @param between set the sql-action to between.
526      */
527     public void setBetween(boolean between) {
528         this.between = between;
529     }
530     
531     /***
532      * @return whether the sql-action is in.
533      */
534     public boolean isIn() {
535         return in;
536     }
537     
538     /***
539      * @param in set the sql-action to in.
540      */
541     public void setIn(boolean in) {
542         this.in = in;
543     }
544     
545     /***
546      * is de logical operator and.
547      * @return and boolean
548      */
549     public boolean isAnd() {
550         return and;
551     }
552     
553     /***
554      * @param and set the logical-operator to and.
555      */
556     public void setAnd(boolean and) {
557         this.and = and;
558     }
559     
560     /***
561      * is de logical operator or.
562      * @return or boolean
563      */
564     public boolean isOr() {
565         return or;
566     }
567     
568     /***
569      * @param or set the logical-operator to or
570      */
571     public void setOr(boolean or) {
572         this.or = or;
573     }
574 }
575 /***
576  * $Log: Criterium.java,v $
577  * Revision 1.4  2005/12/20 15:36:43  shally
578  * CheckStyle and PMD changes.
579  *
580  * Revision 1.3  2005/12/09 10:46:52  shally
581  * Opkuis voor checkstyle en PMD
582  *
583  * Revision 1.2  2005/12/08 14:53:43  shally
584  * Opkuis voor checkstyle.
585  *
586  * Revision 1.1  2005/08/26 07:58:25  ge0ffrey
587  * split up the sources in service, serviceimpl and webclient
588  *
589  * Revision 1.4  2005/06/17 12:20:01  schauwvliege
590  * CheckStyle/ PMD
591  *
592  * Revision 1.3  2005/06/14 12:05:53  schauwvliege
593  * CheckStyle and fixing tests
594  *
595  * Revision 1.2  2005/06/09 08:18:41  bejug_cc
596  * Fix initial import
597  *
598  * Revision 1.7  2005/05/31 07:36:27  bme
599  * introduced count-functionality
600  *
601  * Revision 1.6  2005/05/26 17:55:16  bme
602  * *** empty log message ***
603  *
604  * Revision 1.4  2005/05/17 07:12:05  ssc
605  * checkstyle
606  *
607  * Revision 1.3  2005/05/13 10:28:35  bme
608  * added functionality
609  *
610  * Revision 1.2  2005/05/13 09:19:41  sja
611  * Added CVS Log tag.
612  *
613  */
614