KickJava   Java API By Example, From Geeks To Geeks.

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


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 in the
12  * value array passed in for that particular field. For example, x IN [val1, val2, val3] is equivalent to testing [x = val1, or x= = val2, or x = val3].
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 or EJBQuery class.
16   *<p>
17   *@author Steve Woodcock
18  */

19 public class MatchInQuery implements IndexQuery, QueryId {
20
21     int hashCode =0;
22     Class JavaDoc className;
23     String JavaDoc propertyName;
24     Comparable JavaDoc[] values;
25     final public Object JavaDoc alias;
26     static final QueryType QUERY_ID=QueryType.IN_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 values to be used. <p>
31      *
32      * The field type in the object and each of the values must be of the same type or be able
33      * to be coerced using java's assingability rules.
34      *
35      * <p>
36      * An example usage would be:
37      * <p>
38      * new MatchInQuery(org.package.Myclass.class, "myProperty" ,[20,21,22]);
39      * <p>
40      * @param className - the class of object to be returned.
41      * @param propertyName - the field name to use
42      * @param values - the values that are used as the search value.
43      */

44     public MatchInQuery(Class JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc[] values){
45         this(className, propertyName,values,null);
46     }
47     
48     
49     public MatchInQuery(Class JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc[] values, Object JavaDoc alias){
50         this.className = className;
51         this.propertyName = propertyName;
52         this.values = values;
53         this.alias =alias;
54     }
55     
56     /**
57      * Construct a query supplying the classname of the object type to be returned,and the
58      * field to be queried and the values to be used. <p>
59      *
60      * The field type in the object and each of the values must be of the same type or be able
61      * to be coerced using java's assingability rules.
62      *
63      * <p>
64      * An example usage would be:
65      * <p>
66      * new MatchInQuery("org.package.Myclass", "myProperty" ,[20,21,22]);
67      * <p>
68      * @param className - the class of object to be returned.
69      * @param propertyName - the field name to use
70      * @param values - the values that are used as the search value.
71      */

72     
73     public MatchInQuery(String JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc[] values){
74         this(className, propertyName,values,null);
75     }
76     
77     public MatchInQuery(String JavaDoc className, String JavaDoc propertyName, Comparable JavaDoc[] values, 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.values = values;
87         this.alias =alias;
88     }
89     /**
90      * Construct a query supplying the values to be searched against.
91      * This is a convenience method for classes (such as String,Integer etc)
92      * that have no property value as such. Instead the value is the class type of the values
93      * in the array.
94      * <p>
95      *
96      * An example usage would be:
97      * <p>
98      * new MatchInQuery(["test","test1"]);
99      * <p>
100      * This is so you do not have to use the methods above in the manner of
101      * <p>
102      * new MatchInQuery("java.lang.String", null ,["test","test1"]);
103      * <p>
104      * @param values - the values that are used as the search value.
105      */

106     public MatchInQuery(Comparable JavaDoc[] values){
107         this.values = values;
108         this.alias =null;
109     }
110     /**
111      * @return Returns the className.
112      */

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

120     public String JavaDoc getPropertyName() {
121         return propertyName;
122     }
123
124     /**
125      * @return Returns the values.
126      */

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

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