KickJava   Java API By Example, From Geeks To Geeks.

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


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 everything not equal the
12  * value passed in for that particular field. This is equivalent to !=.<p>
13  *
14  *
15  * This query cannot be combined with any other. iF you want to construct more complex queries use the @see com.jofti.query.Query class.
16  * <p>
17  * @author Steve Woodcock
18  */

19 public class MatchNotQuery implements IndexQuery, QueryId {
20
21     Class JavaDoc className;
22     String JavaDoc propertyName;
23     Comparable JavaDoc value;
24     
25     public final Object JavaDoc alias;
26     final QueryType QUERY_ID =QueryType.NOT_QUERY;
27     
28     /**
29      * Construct a query supplying the classname of the object type to be returned,and the
30      * field to be queried and the value to be used. <p>
31      *
32      * The field type in the object and the value must be of the same type.
33      * <p>
34      *
35      * An example usage would be:
36      * <p>
37      * new MatchNotQuery(org.package.Myclass.class, "myProperty" ,"some value");
38      * <p>
39      * @param className - the class of object to be returned.
40      * @param propertyName - the field name to use
41      * @param value - the value that is used as the search value.
42      */

43     
44     public MatchNotQuery(Class JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc value){
45         this(className,propertyName,value,null);
46     }
47     
48     public MatchNotQuery(Class JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc value,Object JavaDoc alias){
49         this.className = className;
50         this.propertyName = propertyName;
51         this.value = value;
52         this.alias =alias;
53     }
54     
55     /**
56      * Construct a query supplying the classname of the object type to be returned,and the
57      * field to be queried and the value to be used. <p>
58      *
59      * The field type in the object and the value must be of the same type.
60      * <p>
61      *
62      * An example usage would be:
63      * <p>
64      * new MatchNotQuery("org.package.Myclass", "myProperty" ,"some value");
65      * <p>
66      * @param className - the class of object to be returned.
67      * @param propertyName - the field name to use
68      * @param value - the value that is used as the search value.
69      */

70     
71     public MatchNotQuery(String JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc value){
72         this(className,propertyName,value,null);
73     }
74     
75     public MatchNotQuery(String JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc value,Object JavaDoc alias){
76         Class JavaDoc clazz = null;
77         try{
78             clazz = ReflectionUtil.classForName(className);
79         }catch (Exception JavaDoc e){
80             throw new RuntimeException JavaDoc(e);
81         }
82         this.className = clazz;
83         this.propertyName = propertyName;
84         this.value = value;
85         this.alias =alias;
86     }
87     /**
88      * Construct a query supplying the value to be searched against.
89      * This is a convenience method for classes (such as String,Integer etc)
90      * that have no property value as such. Instead the value is the class type.
91      * <p>
92      *
93      * An example usage would be:
94      * <p>
95      * new MatchNotQuery("some value");
96      * <p>
97      * This is so you do not have to use the methods above in the manner of
98      * <p>
99      * new MatchNotQuery("java.lang.String", null ,"some value");
100      * <p>
101
102      * @param value - the value that is used as the search value.
103      */

104     public MatchNotQuery(Comparable JavaDoc value){
105         this.value = value;
106         this.alias =null;
107     }
108     /**
109      * @return Returns the className.
110      */

111     public Class JavaDoc getClassName() {
112         return className;
113     }
114
115     /**
116      * @return Returns the propertyName.
117      */

118     public String JavaDoc getPropertyName() {
119         return propertyName;
120     }
121
122     /**
123      * @return Returns the value.
124      */

125     public Comparable JavaDoc getValue() {
126         return value;
127     }
128
129     public QueryType getQueryType()
130     {
131        
132         return QUERY_ID;
133     }
134
135     
136     public Object JavaDoc getAlias() {
137         return alias;
138     }
139     
140     public IndexQuery setParameter(String JavaDoc name, Object JavaDoc value) {
141         throw new UnsupportedOperationException JavaDoc("Parameters are not supported for convenience classes");
142     }
143     /* (non-Javadoc)
144      * @see com.jofti.api.IndexQuery#setParameter(int, java.lang.Object)
145      */

146     public IndexQuery setParameter(int position, Object JavaDoc value) {
147         throw new UnsupportedOperationException JavaDoc("Parameters are not supported for convenience classes");
148
149     }
150     
151     public IndexQuery setFirstResult(int firstResult) {
152         throw new UnsupportedOperationException JavaDoc("result limits are not supported for convenience classes");
153
154     }
155     public IndexQuery setMaxResults(int maxResults) {
156         throw new UnsupportedOperationException JavaDoc("result limits are not supported for convenience classes");
157
158     }
159 }
160
Popular Tags