KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Created on 13-Jul-2005
3  *
4  */

5 package com.jofti.query;
6
7 import com.jofti.api.IndexQuery;
8 import com.jofti.core.QueryId;
9 import com.jofti.core.QueryType;
10
11 /**
12  *
13  *
14  * Basic usage is "select ${classname} where ${propertyname} [=,<,>,!=,>=,<=] 'value'"
15  * <p>
16  * multiproperty queries are of the form<br>
17  * "select ${classname} where ${propertyname} [=,<,>,!=,>=,<=] 'value' [and,or] ${propertyname} [=,<,>,!=,>=,<=] 'value'"
18  * <p>
19  * compound queries are supported as ${query} [and,or] ${query}
20  * <p>
21  * ordering for compound queries is achieved through use of bracket groups<br>
22   * "select ${classname} where ($propertyname} [=,<,>,!=,>=,<=] 'value' [and,or] ${propertyname} [=,<,>,!=,>=,<=] 'value') [and,or] ${propertyname} [=,<,>,!=,>=,<=] 'value'"
23   <p>
24  *
25  * multiclass queries are of the form
26  * <p>
27  * select ${classname} as A, ${classname} as B where A.${propertyname} [=,<,>,!=,>=,<=] 'value' [and.or] B.${propertyname} [=,<,>,!=,>=,<=] 'value'"
28  * <p>
29  *
30  * All values are created using a reflective String constructor .So if you want to Compare an Integer(22) you just specify
31  * value=22 - the value type is chosen based on the declared type of the field.
32  * <p>
33  * For primitive wrappers in the JVM the propertyname is always the literal string 'VALUE' (case insensitive)
34  * * <li>
35  * java.lang.String.class,
36             java.lang.Integer.class,
37             java.lang.Double.class,
38             java.lang.Float.class,
39             java.lang.Long.class,
40             java.lang.Short.class,
41             java.math.BigInteger.class,
42             java.math.BigDecimal.class,
43             java.util.Date.class,
44             java.net.URI.class
45             </li>
46  * <p>
47  * For example to query an integer you would write
48  * <p>
49  * select java.lang.Integer where VALUE = 20
50  * <p>
51  * or <br>
52  * select java.lang.Integer as i where i.VALUE =20
53  * <p>
54  *
55  * Dates are constructed using the default encoding of the JVM. So a UK encoding would be:
56  * <p>
57  * select java.util.Date where value <='4/10/1901 00:00:00'
58  * <p>
59  * For user defined classes in order to query the property type must have a String constructor and must
60  * implement equals and hashCode correctly.
61  * <p>
62  *
63  * @author Steve Woodcock
64  * @version 1.0
65  * @deprecated Use SQLQuery Object
66  */

67 public class Query implements IndexQuery, QueryId {
68
69     int hashCode =0;
70     String JavaDoc query = null;
71      static final QueryType QUERY_ID=QueryType.UNPARSED_QUERY;
72      
73     private static final String JavaDoc TERMINATOR =";";
74     
75     /**
76      * @param query
77      */

78     public Query(String JavaDoc query){
79         this.query = query + TERMINATOR;
80     }
81     
82     public String JavaDoc getQuery(){
83         return this.query;
84     }
85
86     public QueryType getQueryType()
87     {
88         return QUERY_ID;
89     }
90     
91     public int hashCode(){
92         if (hashCode ==0){
93             hashCode = query.hashCode();
94         }
95         return hashCode;
96     }
97     
98     public boolean equals(Object JavaDoc obj){
99         return query.equals(obj);
100     }
101     
102     public IndexQuery setParameter(String JavaDoc name, Object JavaDoc value) {
103         throw new UnsupportedOperationException JavaDoc("Parameters are not supported for convenience classes");
104     }
105     /* (non-Javadoc)
106      * @see com.jofti.api.IndexQuery#setParameter(int, java.lang.Object)
107      */

108     public IndexQuery setParameter(int position, Object JavaDoc value) {
109         throw new UnsupportedOperationException JavaDoc("Parameters are not supported for convenience classes");
110
111     }
112
113     public IndexQuery setFirstResult(int firstResult) {
114         // TODO Auto-generated method stub
115
return null;
116     }
117
118     public IndexQuery setMaxResults(int maxResults) {
119         // TODO Auto-generated method stub
120
return null;
121     }
122 }
123
Popular Tags