1 package com.jofti.query.namespace; 2 3 import com.jofti.api.IndexQuery; 4 import com.jofti.cache.adapter.NameSpaceWrapper; 5 import com.jofti.core.INameSpace; 6 import com.jofti.core.INameSpaceAware; 7 import com.jofti.core.QueryId; 8 import com.jofti.core.QueryType; 9 import com.jofti.util.ReflectionUtil; 10 11 25 public class MatchNSQuery implements IndexQuery,INameSpaceAware,QueryId { 26 27 public final Object alias; 28 private int hashCode =0; 29 Class className; 30 Object nameSpace; 31 String propertyName; 32 Comparable value; 33 static final QueryType QUERY_ID=QueryType.MATCH_NS_QUERY; 34 35 51 public MatchNSQuery(Class className, Object nameSpace,String propertyName, Comparable value){ 52 this(className,nameSpace,propertyName,value,null); 53 } 54 55 public MatchNSQuery(Class className, Object nameSpace,String propertyName, Comparable value,Object alias){ 56 this.className = className; 57 this.propertyName = propertyName; 58 this.value = value; 59 this.nameSpace = nameSpace; 60 this.alias = alias; 61 } 62 63 64 public MatchNSQuery(String className, Object nameSpace,String propertyName, Comparable value){ 65 this(className, nameSpace,propertyName,value,null); 66 } 67 68 public MatchNSQuery(String className, Object nameSpace,String propertyName, Comparable value,Object alias){ 69 Class clazz = null; 70 try{ 71 clazz = ReflectionUtil.classForName(className); 72 }catch (Exception e){ 73 throw new RuntimeException (e); 74 } 75 this.className = clazz; 76 this.propertyName = propertyName; 77 this.value = value; 78 this.nameSpace = nameSpace; 79 this.alias = alias; 80 } 81 99 100 public MatchNSQuery(Object nameSpace,Comparable value){ 101 this(nameSpace,value,null); 102 } 103 public MatchNSQuery(Object nameSpace,Comparable value,Object alias){ 104 this.value = value; 105 this.nameSpace = nameSpace; 106 this.alias = alias; 107 108 } 109 110 public MatchNSQuery(Object nameSpace){ 111 this(nameSpace,null); 112 } 113 public MatchNSQuery(Object nameSpace,Object alias){ 114 this.nameSpace = nameSpace; 115 this.alias = alias; 116 117 } 118 121 public Class getClassName() { 122 return className; 123 } 124 125 128 public String getPropertyName() { 129 return propertyName; 130 } 131 132 135 public Comparable getValue() { 136 return value; 137 } 138 139 140 141 142 145 public synchronized INameSpace getNameSpaceWrapper() { 146 147 if (nameSpace instanceof INameSpace){ 148 return (INameSpace) nameSpace; 149 }else{ 150 return new NameSpaceWrapper(nameSpace); 151 } 152 } 153 154 157 public synchronized Object getNameSpace() { 158 return nameSpace; 159 } 160 163 public synchronized void setNameSpace(Object nameSpace) { 164 this.nameSpace = nameSpace; 165 } 166 167 public boolean equals(Object o){ 168 if (o instanceof MatchNSQuery){ 169 MatchNSQuery temp = (MatchNSQuery)o; 170 boolean result = nameSpace.equals(temp.nameSpace); 171 if (!result){ 172 return result; 173 } 174 if (className != null && temp.className != null){ 175 result = className.equals(temp.className); 176 if (!result){ 177 return result; 178 } 179 }else { 180 result = className == null & temp.className == null; 181 if (!result){ 182 return result; 183 } 184 } 185 186 if (propertyName != null && temp.propertyName != null){ 187 result = propertyName.equals(temp.propertyName); 188 if (!result){ 189 return result; 190 } 191 }else { 192 result = propertyName == null & temp.propertyName == null; 193 if (!result){ 194 return result; 195 } 196 } 197 if (value != null && temp.value != null){ 198 result = value.equals(temp.value); 199 if (!result){ 200 return result; 201 } 202 }else { 203 result = value == null & temp.value == null; 204 if (!result){ 205 return result; 206 } 207 } 208 return result; 209 } 210 return false; 211 } 212 213 public int hashCode(){ 214 if (hashCode == 0){ 215 int temp = nameSpace ==null?0:nameSpace.hashCode(); 216 if (className != null){ 217 temp+= className.hashCode(); 218 } 219 if (propertyName != null){ 220 temp+= propertyName.hashCode(); 221 } 222 if (value != null){ 223 temp+= value.hashCode(); 224 } 225 hashCode = temp; 226 227 } 228 return hashCode; 229 } 230 public Object getAlias() { 231 return alias; 232 } 233 234 public QueryType getQueryType() { 235 236 return QUERY_ID; 237 } 238 239 public IndexQuery setParameter(String name, Object value) { 240 throw new UnsupportedOperationException ("Parameters are not supported for convenience classes"); 241 } 242 245 public IndexQuery setParameter(int position, Object value) { 246 throw new UnsupportedOperationException ("Parameters are not supported for convenience classes"); 247 248 } 249 250 public IndexQuery setFirstResult(int firstResult) { 251 throw new UnsupportedOperationException ("Result limitation is not supported for convenience classes"); 252 } 253 254 public IndexQuery setMaxResults(int maxResults) { 255 throw new UnsupportedOperationException ("Result limitation is not supported for convenience classes"); 256 } 257 } 258 | Popular Tags |