1 22 package org.jboss.ejb.plugins.cmp.jdbc.metadata; 23 24 import java.lang.reflect.Method ; 25 26 import org.w3c.dom.Element ; 27 28 import org.jboss.deployment.DeploymentException; 29 import org.jboss.metadata.MetaData; 30 31 32 38 public final class JDBCDeclaredQueryMetaData implements JDBCQueryMetaData 39 { 40 43 private final Method method; 44 45 48 private final String additionalColumns; 49 50 53 private final String from; 54 55 58 private final String where; 59 60 63 private final String order; 64 65 69 private final String other; 70 71 74 private final boolean distinct; 75 76 79 private final String ejbName; 80 81 84 private final String fieldName; 85 86 89 private final String alias; 90 93 private final JDBCReadAheadMetaData readAhead; 94 95 98 private final boolean resultTypeMappingLocal; 99 100 private final Class compiler; 101 102 private final boolean lazyResultSetLoading; 103 104 112 public JDBCDeclaredQueryMetaData(JDBCDeclaredQueryMetaData defaults, 113 JDBCReadAheadMetaData readAhead, 114 Class compiler, 115 boolean lazyResultSetLoading) 116 throws DeploymentException 117 { 118 this.method = defaults.getMethod(); 119 this.readAhead = readAhead; 120 121 this.from = defaults.getFrom(); 122 this.where = defaults.getWhere(); 123 this.order = defaults.getOrder(); 124 this.other = defaults.getOther(); 125 126 this.resultTypeMappingLocal = defaults.isResultTypeMappingLocal(); 127 128 this.distinct = defaults.isSelectDistinct(); 129 this.ejbName = defaults.getEJBName(); 130 this.fieldName = defaults.getFieldName(); 131 this.alias = defaults.getAlias(); 132 this.additionalColumns = defaults.getAdditionalColumns(); 133 134 this.compiler = compiler; 135 this.lazyResultSetLoading = lazyResultSetLoading; 136 } 137 138 139 148 public JDBCDeclaredQueryMetaData(boolean isResultTypeMappingLocal, 149 Element queryElement, 150 Method method, 151 JDBCReadAheadMetaData readAhead, 152 Class compiler, 153 boolean lazyResultSetLoading) 154 throws DeploymentException 155 { 156 this.compiler = compiler; 157 this.lazyResultSetLoading = lazyResultSetLoading; 158 159 this.method = method; 160 this.readAhead = readAhead; 161 162 from = nullIfEmpty(MetaData.getOptionalChildContent(queryElement, "from")); 163 where = nullIfEmpty(MetaData.getOptionalChildContent(queryElement, "where")); 164 order = nullIfEmpty(MetaData.getOptionalChildContent(queryElement, "order")); 165 other = nullIfEmpty(MetaData.getOptionalChildContent(queryElement, "other")); 166 167 this.resultTypeMappingLocal = isResultTypeMappingLocal; 168 169 Element selectElement = 171 MetaData.getOptionalChild(queryElement, "select"); 172 173 if(selectElement != null) 174 { 175 distinct = 177 (MetaData.getOptionalChild(selectElement, "distinct") != null); 178 179 if(method.getName().startsWith("ejbSelect")) 180 { 181 ejbName = MetaData.getUniqueChildContent(selectElement, "ejb-name"); 182 fieldName = nullIfEmpty(MetaData.getOptionalChildContent(selectElement, "field-name")); 183 } 184 else 185 { 186 if(MetaData.getOptionalChild(selectElement, "ejb-name") != null) 188 { 189 throw new DeploymentException( 190 "The ejb-name element of declared-sql select is only " + 191 "allowed for ejbSelect queries." 192 ); 193 } 194 if(MetaData.getOptionalChild(selectElement, "field-name") != null) 195 { 196 throw new DeploymentException( 197 "The field-name element of declared-sql select is only " + 198 "allowed for ejbSelect queries." 199 ); 200 } 201 ejbName = null; 202 fieldName = null; 203 } 204 alias = nullIfEmpty(MetaData.getOptionalChildContent(selectElement, "alias")); 205 additionalColumns = nullIfEmpty(MetaData.getOptionalChildContent(selectElement, "additional-columns")); 206 } 207 else 208 { 209 if(method.getName().startsWith("ejbSelect")) 210 { 211 throw new DeploymentException( 212 "The select element of " + 213 "declared-sql is required for ejbSelect queries." 214 ); 215 } 216 distinct = false; 217 ejbName = null; 218 fieldName = null; 219 alias = null; 220 additionalColumns = null; 221 } 222 } 223 224 public Method getMethod() 226 { 227 return method; 228 } 229 230 public boolean isResultTypeMappingLocal() 232 { 233 return resultTypeMappingLocal; 234 } 235 236 241 public JDBCReadAheadMetaData getReadAhead() 242 { 243 return readAhead; 244 } 245 246 public Class getQLCompilerClass() 247 { 248 return compiler; 249 } 250 251 256 public String getFrom() 257 { 258 return from; 259 } 260 261 266 public String getWhere() 267 { 268 return where; 269 } 270 271 276 public String getOrder() 277 { 278 return order; 279 } 280 281 288 public String getOther() 289 { 290 return other; 291 } 292 293 298 public boolean isSelectDistinct() 299 { 300 return distinct; 301 } 302 303 309 public String getEJBName() 310 { 311 return ejbName; 312 } 313 314 320 public String getFieldName() 321 { 322 return fieldName; 323 } 324 325 331 public String getAlias() 332 { 333 return alias; 334 } 335 336 342 public String getAdditionalColumns() 343 { 344 return additionalColumns; 345 } 346 347 public boolean isLazyResultSetLoading() 348 { 349 return lazyResultSetLoading; 350 } 351 352 361 public boolean equals(Object o) 362 { 363 if(o instanceof JDBCDeclaredQueryMetaData) 364 { 365 return ((JDBCDeclaredQueryMetaData) o).method.equals(method); 366 } 367 return false; 368 } 369 370 376 public int hashCode() 377 { 378 return method.hashCode(); 379 } 380 381 391 public String toString() 392 { 393 return "[JDBCDeclaredQueryMetaData : method=" + method + "]"; 394 } 395 396 private static String nullIfEmpty(String s) 397 { 398 if(s != null && s.trim().length() == 0) 399 { 400 s = null; 401 } 402 return s; 403 } 404 } 405 | Popular Tags |