1 package org.tigris.scarab.da; 2 3 48 49 import java.io.Serializable ; 50 import java.util.ArrayList ; 51 import java.util.Collection ; 52 import java.util.HashSet ; 53 import java.util.Iterator ; 54 import java.util.List ; 55 import java.util.Set ; 56 57 import org.apache.torque.util.Criteria; 58 import com.workingdogs.village.Record; 59 60 import org.tigris.scarab.om.AttributePeer; 61 import org.tigris.scarab.om.AttributeGroupPeer; 62 import org.tigris.scarab.om.RAttributeAttributeGroupPeer; 63 import org.tigris.scarab.om.RModuleAttributePeer; 64 import org.tigris.scarab.om.RModuleUserAttributePeer; 65 import org.tigris.scarab.services.cache.ScarabCache; 66 import org.tigris.scarab.tools.localization.L10NKeySet; 67 68 76 public class AttributeAccess 77 { 78 79 private static final String RETRIEVE_QUERY_COLUMN_IDS = 80 "retrieveQueryColumnIDs"; 81 private static final String RETRIEVE_QUICK_SEARCH_ATTRIBUTES = 82 "retrieveQuickSearchAttributeIDs"; 83 private static final String RETRIEVE_REQUIRED_ATTRIBUTES = 84 "retrieveRequiredAttributeIDs"; 85 private static final String RETRIEVE_ACTIVE_ATTRIBUTES = 86 "retrieveActiveAttributes"; 87 private static final String RETRIEVE_DEFAULT_TEXT_ATTRIBUTE = 88 "retrieveDefaultTextAttributeID"; 89 private static final String RETRIEVE_FIRST_ACTIVE_TEXT_ATTRIBUTE = 90 "retrieveFirstActiveTextAttributeID"; 91 92 private Serializable thisKey = AttributeAccess.class; 93 94 95 98 public AttributeAccess() 99 { 100 } 101 102 117 public List retrieveQueryColumnIDs(String userID, String listID, 118 String moduleID, String artifactTypeID) throws DAException 119 { 120 List result = null; 121 Object obj = ScarabCache.get(thisKey, 122 RETRIEVE_QUERY_COLUMN_IDS, 123 userID, moduleID, artifactTypeID); 124 if (obj == null) 125 { 126 Criteria crit = new Criteria(); 127 crit.addSelectColumn(RModuleUserAttributePeer.ATTRIBUTE_ID); 128 crit.add(RModuleUserAttributePeer.USER_ID, userID); 129 if (moduleID != null) 130 { 131 crit.add(RModuleUserAttributePeer.MODULE_ID, moduleID); 132 } 133 if (artifactTypeID != null) 134 { 135 crit.add(RModuleUserAttributePeer.ISSUE_TYPE_ID, 136 artifactTypeID); 137 } 138 crit.add(RModuleUserAttributePeer.LIST_ID, listID) 140 .addAscendingOrderByColumn 141 (RModuleUserAttributePeer.PREFERRED_ORDER); 142 143 try 144 { 145 List records = 146 RModuleUserAttributePeer.doSelectVillageRecords(crit); 147 result = new ArrayList (records.size()); 148 for (Iterator i = records.iterator(); i.hasNext();) 149 { 150 result.add(((Record) i.next()).getValue(1).asString()); 151 } 152 } 153 catch (Exception e) 154 { 155 throw new DAException(L10NKeySet.ExceptionFailedToReadIdentifierList, 156 e); 157 } 158 ScarabCache.put(result, AttributeAccess.class, 159 RETRIEVE_QUERY_COLUMN_IDS, 160 userID, moduleID, artifactTypeID); 161 } 162 else 163 { 164 result = (List ) obj; 165 } 166 return result; 167 } 168 169 182 public void deleteQueryColumnIDs(String userID, String listID, 183 String moduleID, String artifactTypeID) 184 throws DAException 185 { 186 Criteria crit = new Criteria(); 187 crit.add(RModuleUserAttributePeer.USER_ID, userID); 188 if (moduleID != null) 189 { 190 crit.add(RModuleUserAttributePeer.MODULE_ID, moduleID); 191 } 192 if (artifactTypeID != null) 193 { 194 crit.add(RModuleUserAttributePeer.ISSUE_TYPE_ID, 195 artifactTypeID); 196 } 197 crit.add(RModuleUserAttributePeer.LIST_ID, listID); 198 try 199 { 200 RModuleUserAttributePeer.doDelete(crit); 201 } 202 catch (Exception e) 203 { 204 throw new DAException(L10NKeySet.ExceptionFailedToDeleteIdentifierList, 205 e); 206 } 207 } 208 209 210 221 public Set retrieveRequiredAttributeIDs(String moduleID, 222 String artifactTypeID) 223 throws DAException 224 { 225 Set attributes = null; 226 Object obj = ScarabCache.get(thisKey, RETRIEVE_REQUIRED_ATTRIBUTES, 227 moduleID, artifactTypeID); 228 if (obj == null) 229 { 230 Criteria crit = new Criteria(7) 231 .add(RModuleAttributePeer.REQUIRED, true) 232 .add(RModuleAttributePeer.ACTIVE, true) 233 .add(RModuleAttributePeer.MODULE_ID, moduleID) 234 .add(RModuleAttributePeer.ISSUE_TYPE_ID, artifactTypeID); 235 addGroupCriteria(crit, moduleID, artifactTypeID); 236 attributes = getRMAAttributeIdSet(crit); 237 ScarabCache.put(attributes, thisKey, RETRIEVE_REQUIRED_ATTRIBUTES, 238 moduleID, artifactTypeID); 239 } 240 else 241 { 242 attributes = (Set ) obj; 243 } 244 return attributes; 245 } 246 247 259 public Set retrieveQuickSearchAttributeIDs(String moduleID, 260 String artifactTypeID) 261 throws DAException 262 { 263 Set attributes = null; 264 Object obj = ScarabCache.get(thisKey, RETRIEVE_QUICK_SEARCH_ATTRIBUTES, 265 moduleID, artifactTypeID); 266 if (obj == null) 267 { 268 Criteria crit = new Criteria(3) 269 .add(RModuleAttributePeer.QUICK_SEARCH, true) 270 .add(RModuleAttributePeer.MODULE_ID, moduleID) 271 .add(RModuleAttributePeer.ISSUE_TYPE_ID, artifactTypeID); 272 attributes = getRMAAttributeIdSet(crit); 273 ScarabCache.put(attributes, thisKey, 274 RETRIEVE_QUICK_SEARCH_ATTRIBUTES, 275 moduleID, artifactTypeID); 276 } 277 else 278 { 279 attributes = (Set ) obj; 280 } 281 return attributes; 282 } 283 284 private Set getRMAAttributeIdSet(Criteria crit) 285 throws DAException 286 { 287 crit.addSelectColumn(RModuleAttributePeer.ATTRIBUTE_ID); 288 Set attributes = null; 289 try 290 { 291 List records = RModuleAttributePeer.doSelectVillageRecords(crit); 292 attributes = new HashSet (records.size()); 293 for (Iterator i = records.iterator(); i.hasNext(); ) 294 { 295 attributes.add(((Record) i.next()).getValue(1).asString()); 296 } 297 } 298 catch (Exception e) 299 { 300 throw new DAException(L10NKeySet.ExceptionFailedToReadIdentifierList, e); 301 } 302 return attributes; 303 } 304 305 private void addGroupCriteria(Criteria crit, 306 String moduleID, String artifactTypeID) 307 { 308 crit.addJoin(RAttributeAttributeGroupPeer.ATTRIBUTE_ID, 309 RModuleAttributePeer.ATTRIBUTE_ID) 310 .addJoin(RAttributeAttributeGroupPeer.GROUP_ID, 311 AttributeGroupPeer.ATTRIBUTE_GROUP_ID) 312 .add(AttributeGroupPeer.MODULE_ID, moduleID) 313 .add(AttributeGroupPeer.ISSUE_TYPE_ID, artifactTypeID) 314 .add(AttributeGroupPeer.ACTIVE, true); 315 } 316 317 318 333 public Collection retrieveActiveAttributeOMs(String moduleID, 334 String artifactTypeID, 335 boolean isOrdered) 336 throws DAException 337 { 338 Collection attributes = null; 339 Boolean ordered = isOrdered ? Boolean.TRUE : Boolean.FALSE; 340 Object obj = ScarabCache.get(thisKey, RETRIEVE_ACTIVE_ATTRIBUTES, 341 moduleID, artifactTypeID, ordered); 342 if (obj == null) 343 { 344 Criteria crit = new Criteria(2); 345 crit.add(RModuleAttributePeer.ACTIVE, true); 346 crit.add(RModuleAttributePeer.MODULE_ID, moduleID); 347 crit.add(RModuleAttributePeer.ISSUE_TYPE_ID, artifactTypeID); 348 356 if (isOrdered) 357 { 358 crit.addAscendingOrderByColumn( 359 RModuleAttributePeer.PREFERRED_ORDER); 360 crit.addAscendingOrderByColumn( 361 RModuleAttributePeer.DISPLAY_VALUE); 362 } 363 364 crit.addJoin(AttributePeer.ATTRIBUTE_ID, 365 RModuleAttributePeer.ATTRIBUTE_ID); 366 List records = null; 367 try 368 { 369 records = AttributePeer.doSelect(crit); 370 } 371 catch (Exception e) 372 { 373 throw new DAException(L10NKeySet.ExceptionFailedToReadIdentifierList, e); 374 } 375 if (isOrdered) 376 { 377 attributes = new ArrayList (records.size()); 378 } 379 else 380 { 381 attributes = new HashSet (records.size()); 382 } 383 384 for (Iterator i = records.iterator(); i.hasNext();) 385 { 386 attributes.add(i.next()); 387 } 388 389 ScarabCache.put(attributes, thisKey, RETRIEVE_ACTIVE_ATTRIBUTES, 390 moduleID, artifactTypeID, ordered); 391 } 392 else 393 { 394 attributes = (Collection )obj; 395 } 396 return attributes; 397 } 398 399 400 412 public String retrieveDefaultTextAttributeID(String moduleID, 413 String artifactTypeID) 414 throws DAException 415 { 416 String result = null; 417 Object obj = ScarabCache.get(thisKey, RETRIEVE_DEFAULT_TEXT_ATTRIBUTE, 418 moduleID, artifactTypeID); 419 if (obj == null) 420 { 421 Criteria crit = new Criteria(7); 422 crit.add(RModuleAttributePeer.DEFAULT_TEXT_FLAG, true) 423 .add(RModuleAttributePeer.ACTIVE, true) 424 .add(RModuleAttributePeer.MODULE_ID, moduleID) 425 .add(RModuleAttributePeer.ISSUE_TYPE_ID, artifactTypeID); 426 addGroupCriteria(crit, moduleID, artifactTypeID); 427 result = getRMAAttributeId(crit); 428 ScarabCache.put(result, thisKey, RETRIEVE_DEFAULT_TEXT_ATTRIBUTE, 429 moduleID, artifactTypeID); 430 } 431 else 432 { 433 result = (String ) obj; 434 } 435 436 return result.length() == 0 ? null : result; 437 } 438 439 private String getRMAAttributeId(Criteria crit) 440 throws DAException 441 { 442 String result = null; 443 crit.addSelectColumn(RModuleAttributePeer.ATTRIBUTE_ID); 444 try 445 { 446 List records = RModuleAttributePeer.doSelectVillageRecords(crit); 447 if (records.isEmpty()) 448 { 449 result = ""; } 451 else 452 { 453 result = ((Record) records.get(0)).getValue(1).asString(); 454 } 455 } 456 catch (Exception e) 457 { 458 throw new DAException(L10NKeySet.ExceptionFailedToReadIdentifierList, e); 459 } 460 return result; 461 } 462 463 464 477 public String retrieveFirstActiveTextAttributeID(String moduleID, 478 String artifactTypeID) 479 throws DAException 480 { 481 String result = null; 482 483 Object obj = ScarabCache.get(thisKey, 484 RETRIEVE_FIRST_ACTIVE_TEXT_ATTRIBUTE, 485 moduleID, artifactTypeID); 486 if (obj == null) 487 { 488 Criteria crit = new Criteria(7); 489 crit.add(RModuleAttributePeer.ACTIVE, true) 490 .add(RModuleAttributePeer.MODULE_ID, moduleID) 491 .add(RModuleAttributePeer.ISSUE_TYPE_ID, artifactTypeID); 492 addGroupCriteria(crit, moduleID, artifactTypeID); 493 494 crit.addAscendingOrderByColumn( 495 RModuleAttributePeer.PREFERRED_ORDER); 496 crit.addAscendingOrderByColumn( 497 RModuleAttributePeer.DISPLAY_VALUE); 498 499 result = getRMAAttributeId(crit); 500 ScarabCache.put(result, thisKey, 501 RETRIEVE_FIRST_ACTIVE_TEXT_ATTRIBUTE, 502 moduleID, artifactTypeID); 503 } 504 else 505 { 506 result = (String ) obj; 507 } 508 509 return result.length() == 0 ? null : result; 510 } 511 } 512 | Popular Tags |