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: * @deprecated Use SQLQuery Object
066: */
067: public class Query implements IndexQuery, QueryId {
068:
069: int hashCode = 0;
070: String query = null;
071: static final QueryType QUERY_ID = QueryType.UNPARSED_QUERY;
072:
073: private static final String TERMINATOR = ";";
074:
075: /**
076: * @param query
077: */
078: public Query(String query) {
079: this .query = query + TERMINATOR;
080: }
081:
082: public String getQuery() {
083: return this .query;
084: }
085:
086: public QueryType getQueryType() {
087: return QUERY_ID;
088: }
089:
090: public int hashCode() {
091: if (hashCode == 0) {
092: hashCode = query.hashCode();
093: }
094: return hashCode;
095: }
096:
097: public boolean equals(Object obj) {
098: return query.equals(obj);
099: }
100:
101: public IndexQuery setParameter(String name, Object value) {
102: throw new UnsupportedOperationException(
103: "Parameters are not supported for convenience classes");
104: }
105:
106: /* (non-Javadoc)
107: * @see com.jofti.api.IndexQuery#setParameter(int, java.lang.Object)
108: */
109: public IndexQuery setParameter(int position, Object value) {
110: throw new UnsupportedOperationException(
111: "Parameters are not supported for convenience classes");
112:
113: }
114:
115: public IndexQuery setFirstResult(int firstResult) {
116: // TODO Auto-generated method stub
117: return null;
118: }
119:
120: public IndexQuery setMaxResults(int maxResults) {
121: // TODO Auto-generated method stub
122: return null;
123: }
124: }
|