001: package com.jofti.query;
002:
003: import com.jofti.api.IndexQuery;
004: import com.jofti.core.QueryId;
005: import com.jofti.core.QueryType;
006: import com.jofti.util.ReflectionUtil;
007:
008: /**
009: *
010: *
011: * A utility class to enable simple queries to be done easily. The Query matches everything not equal the
012: * value passed in for that particular field. This is equivalent to !=.<p>
013: *
014: *
015: * This query cannot be combined with any other. iF you want to construct more complex queries use the @see com.jofti.query.Query class.
016: * <p>
017: * @author Steve Woodcock
018: */
019: public class MatchNotQuery implements IndexQuery, QueryId {
020:
021: Class className;
022: String propertyName;
023: Comparable value;
024:
025: public final Object alias;
026: final QueryType QUERY_ID = QueryType.NOT_QUERY;
027:
028: /**
029: * Construct a query supplying the classname of the object type to be returned,and the
030: * field to be queried and the value to be used. <p>
031: *
032: * The field type in the object and the value must be of the same type.
033: * <p>
034: *
035: * An example usage would be:
036: * <p>
037: * new MatchNotQuery(org.package.Myclass.class, "myProperty" ,"some value");
038: * <p>
039: * @param className - the class of object to be returned.
040: * @param propertyName - the field name to use
041: * @param value - the value that is used as the search value.
042: */
043:
044: public MatchNotQuery(Class className, String propertyName,
045: Comparable value) {
046: this (className, propertyName, value, null);
047: }
048:
049: public MatchNotQuery(Class className, String propertyName,
050: Comparable value, Object alias) {
051: this .className = className;
052: this .propertyName = propertyName;
053: this .value = value;
054: this .alias = alias;
055: }
056:
057: /**
058: * Construct a query supplying the classname of the object type to be returned,and the
059: * field to be queried and the value to be used. <p>
060: *
061: * The field type in the object and the value must be of the same type.
062: * <p>
063: *
064: * An example usage would be:
065: * <p>
066: * new MatchNotQuery("org.package.Myclass", "myProperty" ,"some value");
067: * <p>
068: * @param className - the class of object to be returned.
069: * @param propertyName - the field name to use
070: * @param value - the value that is used as the search value.
071: */
072:
073: public MatchNotQuery(String className, String propertyName,
074: Comparable value) {
075: this (className, propertyName, value, null);
076: }
077:
078: public MatchNotQuery(String className, String propertyName,
079: Comparable value, Object alias) {
080: Class clazz = null;
081: try {
082: clazz = ReflectionUtil.classForName(className);
083: } catch (Exception e) {
084: throw new RuntimeException(e);
085: }
086: this .className = clazz;
087: this .propertyName = propertyName;
088: this .value = value;
089: this .alias = alias;
090: }
091:
092: /**
093: * Construct a query supplying the value to be searched against.
094: * This is a convenience method for classes (such as String,Integer etc)
095: * that have no property value as such. Instead the value is the class type.
096: * <p>
097: *
098: * An example usage would be:
099: * <p>
100: * new MatchNotQuery("some value");
101: * <p>
102: * This is so you do not have to use the methods above in the manner of
103: * <p>
104: * new MatchNotQuery("java.lang.String", null ,"some value");
105: * <p>
106:
107: * @param value - the value that is used as the search value.
108: */
109: public MatchNotQuery(Comparable value) {
110: this .value = value;
111: this .alias = null;
112: }
113:
114: /**
115: * @return Returns the className.
116: */
117: public Class getClassName() {
118: return className;
119: }
120:
121: /**
122: * @return Returns the propertyName.
123: */
124: public String getPropertyName() {
125: return propertyName;
126: }
127:
128: /**
129: * @return Returns the value.
130: */
131: public Comparable getValue() {
132: return value;
133: }
134:
135: public QueryType getQueryType() {
136:
137: return QUERY_ID;
138: }
139:
140: public Object getAlias() {
141: return alias;
142: }
143:
144: public IndexQuery setParameter(String name, Object value) {
145: throw new UnsupportedOperationException(
146: "Parameters are not supported for convenience classes");
147: }
148:
149: /* (non-Javadoc)
150: * @see com.jofti.api.IndexQuery#setParameter(int, java.lang.Object)
151: */
152: public IndexQuery setParameter(int position, Object value) {
153: throw new UnsupportedOperationException(
154: "Parameters are not supported for convenience classes");
155:
156: }
157:
158: public IndexQuery setFirstResult(int firstResult) {
159: throw new UnsupportedOperationException(
160: "result limits are not supported for convenience classes");
161:
162: }
163:
164: public IndexQuery setMaxResults(int maxResults) {
165: throw new UnsupportedOperationException(
166: "result limits are not supported for convenience classes");
167:
168: }
169: }
|