KickJava   Java API By Example, From Geeks To Geeks.

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


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  */

66 public class SQLQuery implements IndexQuery, QueryId {
67
68     int hashCode =0;
69     String JavaDoc query = null;
70      static final QueryType QUERY_ID=QueryType.UNPARSED_QUERY;
71      
72     private static final String JavaDoc TERMINATOR =";";
73     
74     public SQLQuery(String JavaDoc query){
75         this.query = query + TERMINATOR;
76     }
77     
78     public String JavaDoc getQuery(){
79         return this.query;
80     }
81
82     public QueryType getQueryType()
83     {
84         return QUERY_ID;
85     }
86     
87     public int hashCode(){
88         if (hashCode ==0){
89             hashCode = query.hashCode();
90         }
91         return hashCode;
92     }
93     
94     public boolean equals(Object JavaDoc obj){
95         return query.equals(obj);
96     }
97     
98     public IndexQuery setParameter(String JavaDoc name, Object JavaDoc value) {
99         throw new UnsupportedOperationException JavaDoc("Parameters are not supported for sql queries");
100     }
101     /* (non-Javadoc)
102      * @see com.jofti.api.IndexQuery#setParameter(int, java.lang.Object)
103      */

104     public IndexQuery setParameter(int position, Object JavaDoc value) {
105         throw new UnsupportedOperationException JavaDoc("Parameters are not supported for sql queries");
106
107     }
108     
109     public IndexQuery setFirstResult(int firstResult) {
110         throw new UnsupportedOperationException JavaDoc("result limits are not supported for sql queries");
111
112     }
113     public IndexQuery setMaxResults(int maxResults) {
114         throw new UnsupportedOperationException JavaDoc("result limits are not supported for sql queries");
115
116     }
117 }
118
Popular Tags