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