KickJava   Java API By Example, From Geeks To Geeks.

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


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 equal to 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 @link com.jofti.query.Query class.
16   *<p>
17   *@author Steve Woodcock
18  */

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

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

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

100     public MatchQuery(Comparable JavaDoc value){
101         this.value = value;
102         alias =null;
103         className =null;
104         propertyName =null;
105     }
106     /**
107      * @return Returns the className.
108      */

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

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

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

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