001: /*
002: * Created on 13-Jul-2005
003: *
004: */
005: package com.jofti.query;
006:
007: import com.jofti.api.IndexQuery;
008: import com.jofti.core.QueryId;
009: import com.jofti.core.QueryType;
010:
011: /**
012: *
013: *
014: * Basic usage is "select ${classname} where ${propertyname} [=,<,>,!=,>=,<=] 'value'"
015: * <p>
016: * multiproperty queries are of the form<br>
017: * "select ${classname} where ${propertyname} [=,<,>,!=,>=,<=] 'value' [and,or] ${propertyname} [=,<,>,!=,>=,<=] 'value'"
018: * <p>
019: * compound queries are supported as ${query} [and,or] ${query}
020: * <p>
021: * ordering for compound queries is achieved through use of bracket groups<br>
022: * "select ${classname} where ($propertyname} [=,<,>,!=,>=,<=] 'value' [and,or] ${propertyname} [=,<,>,!=,>=,<=] 'value') [and,or] ${propertyname} [=,<,>,!=,>=,<=] 'value'"
023: <p>
024: *
025: * multiclass queries are of the form
026: * <p>
027: * select ${classname} as A, ${classname} as B where A.${propertyname} [=,<,>,!=,>=,<=] 'value' [and.or] B.${propertyname} [=,<,>,!=,>=,<=] 'value'"
028: * <p>
029: *
030: * All values are created using a reflective String constructor .So if you want to Compare an Integer(22) you just specify
031: * value=22 - the value type is chosen based on the declared type of the field.
032: * <p>
033: * For primitive wrappers in the JVM the propertyname is always the literal string 'VALUE' (case insensitive)
034: * * <li>
035: * java.lang.String.class,
036: java.lang.Integer.class,
037: java.lang.Double.class,
038: java.lang.Float.class,
039: java.lang.Long.class,
040: java.lang.Short.class,
041: java.math.BigInteger.class,
042: java.math.BigDecimal.class,
043: java.util.Date.class,
044: java.net.URI.class
045: </li>
046: * <p>
047: * For example to query an integer you would write
048: * <p>
049: * select java.lang.Integer where VALUE = 20
050: * <p>
051: * or <br>
052: * select java.lang.Integer as i where i.VALUE =20
053: * <p>
054: *
055: * Dates are constructed using the default encoding of the JVM. So a UK encoding would be:
056: * <p>
057: * select java.util.Date where value <='4/10/1901 00:00:00'
058: * <p>
059: * For user defined classes in order to query the property type must have a String constructor and must
060: * implement equals and hashCode correctly.
061: * <p>
062: *
063: * @author Steve Woodcock
064: * @version 1.0
065: */
066: public class SQLQuery implements IndexQuery, QueryId {
067:
068: int hashCode = 0;
069: String query = null;
070: static final QueryType QUERY_ID = QueryType.UNPARSED_QUERY;
071:
072: private static final String TERMINATOR = ";";
073:
074: public SQLQuery(String query) {
075: this .query = query + TERMINATOR;
076: }
077:
078: public String getQuery() {
079: return this .query;
080: }
081:
082: public QueryType getQueryType() {
083: return QUERY_ID;
084: }
085:
086: public int hashCode() {
087: if (hashCode == 0) {
088: hashCode = query.hashCode();
089: }
090: return hashCode;
091: }
092:
093: public boolean equals(Object obj) {
094: return query.equals(obj);
095: }
096:
097: public IndexQuery setParameter(String name, Object value) {
098: throw new UnsupportedOperationException(
099: "Parameters are not supported for sql queries");
100: }
101:
102: /* (non-Javadoc)
103: * @see com.jofti.api.IndexQuery#setParameter(int, java.lang.Object)
104: */
105: public IndexQuery setParameter(int position, Object value) {
106: throw new UnsupportedOperationException(
107: "Parameters are not supported for sql queries");
108:
109: }
110:
111: public IndexQuery setFirstResult(int firstResult) {
112: throw new UnsupportedOperationException(
113: "result limits are not supported for sql queries");
114:
115: }
116:
117: public IndexQuery setMaxResults(int maxResults) {
118: throw new UnsupportedOperationException(
119: "result limits are not supported for sql queries");
120:
121: }
122: }
|