1 package org.tigris.scarab.om; 2 3 4 import java.math.BigDecimal ; 5 import java.sql.Connection ; 6 import java.util.ArrayList ; 7 import java.util.Collections ; 8 import java.util.Date ; 9 import java.util.List ; 10 11 import org.apache.commons.lang.ObjectUtils; 12 import org.apache.fulcrum.intake.Retrievable; 13 import org.apache.torque.TorqueException; 14 import org.apache.torque.om.BaseObject; 15 import org.apache.torque.om.ComboKey; 16 import org.apache.torque.om.DateKey; 17 import org.apache.torque.om.NumberKey; 18 import org.apache.torque.om.ObjectKey; 19 import org.apache.torque.om.SimpleKey; 20 import org.apache.torque.om.StringKey; 21 import org.apache.torque.om.Persistent; 22 import org.apache.torque.util.Criteria; 23 import org.apache.torque.util.Transaction; 24 25 26 27 28 29 33 public abstract class BaseMITListItem extends BaseObject 34 implements org.apache.fulcrum.intake.Retrievable 35 { 36 37 private static final MITListItemPeer peer = 38 new MITListItemPeer(); 39 40 41 42 private Long itemId; 43 44 45 private Integer moduleId; 46 47 48 private Integer issueTypeId; 49 50 51 private Long listId; 52 53 54 59 public Long getItemId() 60 { 61 return itemId; 62 } 63 64 65 70 public void setItemId(Long v) 71 { 72 73 if (!ObjectUtils.equals(this.itemId, v)) 74 { 75 this.itemId = v; 76 setModified(true); 77 } 78 79 80 } 81 82 87 public Integer getModuleId() 88 { 89 return moduleId; 90 } 91 92 93 98 public void setModuleId(Integer v) throws TorqueException 99 { 100 101 if (!ObjectUtils.equals(this.moduleId, v)) 102 { 103 this.moduleId = v; 104 setModified(true); 105 } 106 107 108 if (aModule != null && !ObjectUtils.equals(aModule.getModuleId(), v)) 109 { 110 aModule = null; 111 } 112 113 } 114 115 120 public Integer getIssueTypeId() 121 { 122 return issueTypeId; 123 } 124 125 126 131 public void setIssueTypeId(Integer v) throws TorqueException 132 { 133 134 if (!ObjectUtils.equals(this.issueTypeId, v)) 135 { 136 this.issueTypeId = v; 137 setModified(true); 138 } 139 140 141 if (aIssueType != null && !ObjectUtils.equals(aIssueType.getIssueTypeId(), v)) 142 { 143 aIssueType = null; 144 } 145 146 } 147 148 153 public Long getListId() 154 { 155 return listId; 156 } 157 158 159 164 public void setListId(Long v) throws TorqueException 165 { 166 167 if (!ObjectUtils.equals(this.listId, v)) 168 { 169 this.listId = v; 170 setModified(true); 171 } 172 173 174 if (aMITList != null && !ObjectUtils.equals(aMITList.getListId(), v)) 175 { 176 aMITList = null; 177 } 178 179 } 180 181 182 183 184 private MITList aMITList; 185 186 192 public void setMITList(MITList v) throws TorqueException 193 { 194 if (v == null) 195 { 196 setListId((Long ) null); 197 } 198 else 199 { 200 setListId(v.getListId()); 201 } 202 aMITList = v; 203 } 204 205 206 212 public MITList getMITList() throws TorqueException 213 { 214 if ( !ObjectUtils.equals(getListId(), null) ) 215 { 216 return MITListManager.getInstance(SimpleKey.keyFor(getListId())); 217 } 218 return aMITList; 219 } 220 221 227 public void setMITListKey(ObjectKey key) throws TorqueException 228 { 229 230 setListId(new Long (((NumberKey) key).longValue())); 231 } 232 233 234 235 private Module aModule; 236 237 243 public void setModule(Module v) throws TorqueException 244 { 245 if (v == null) 246 { 247 setModuleId((Integer ) null); 248 } 249 else 250 { 251 setModuleId(v.getModuleId()); 252 } 253 aModule = v; 254 } 255 256 257 263 public Module getModule() throws TorqueException 264 { 265 if ( !ObjectUtils.equals(getModuleId(), null) ) 266 { 267 return ModuleManager.getInstance(SimpleKey.keyFor(getModuleId())); 268 } 269 return aModule; 270 } 271 272 278 public void setModuleKey(ObjectKey key) throws TorqueException 279 { 280 281 setModuleId(new Integer (((NumberKey) key).intValue())); 282 } 283 284 285 286 private IssueType aIssueType; 287 288 294 public void setIssueType(IssueType v) throws TorqueException 295 { 296 if (v == null) 297 { 298 setIssueTypeId((Integer ) null); 299 } 300 else 301 { 302 setIssueTypeId(v.getIssueTypeId()); 303 } 304 aIssueType = v; 305 } 306 307 308 314 public IssueType getIssueType() throws TorqueException 315 { 316 if ( !ObjectUtils.equals(getIssueTypeId(), null) ) 317 { 318 return IssueTypeManager.getInstance(SimpleKey.keyFor(getIssueTypeId())); 319 } 320 return aIssueType; 321 } 322 323 329 public void setIssueTypeKey(ObjectKey key) throws TorqueException 330 { 331 332 setIssueTypeId(new Integer (((NumberKey) key).intValue())); 333 } 334 335 336 private static List fieldNames = null; 337 338 343 public static synchronized List getFieldNames() 344 { 345 if (fieldNames == null) 346 { 347 fieldNames = new ArrayList (); 348 fieldNames.add("ItemId"); 349 fieldNames.add("ModuleId"); 350 fieldNames.add("IssueTypeId"); 351 fieldNames.add("ListId"); 352 fieldNames = Collections.unmodifiableList(fieldNames); 353 } 354 return fieldNames; 355 } 356 357 363 public Object getByName(String name) 364 { 365 if (name.equals("ItemId")) 366 { 367 return getItemId(); 368 } 369 if (name.equals("ModuleId")) 370 { 371 return getModuleId(); 372 } 373 if (name.equals("IssueTypeId")) 374 { 375 return getIssueTypeId(); 376 } 377 if (name.equals("ListId")) 378 { 379 return getListId(); 380 } 381 return null; 382 } 383 384 392 public Object getByPeerName(String name) 393 { 394 if (name.equals(MITListItemPeer.ITEM_ID)) 395 { 396 return getItemId(); 397 } 398 if (name.equals(MITListItemPeer.MODULE_ID)) 399 { 400 return getModuleId(); 401 } 402 if (name.equals(MITListItemPeer.ISSUE_TYPE_ID)) 403 { 404 return getIssueTypeId(); 405 } 406 if (name.equals(MITListItemPeer.LIST_ID)) 407 { 408 return getListId(); 409 } 410 return null; 411 } 412 413 420 public Object getByPosition(int pos) 421 { 422 if (pos == 0) 423 { 424 return getItemId(); 425 } 426 if (pos == 1) 427 { 428 return getModuleId(); 429 } 430 if (pos == 2) 431 { 432 return getIssueTypeId(); 433 } 434 if (pos == 3) 435 { 436 return getListId(); 437 } 438 return null; 439 } 440 441 447 public void save() throws Exception 448 { 449 save(MITListItemPeer.getMapBuilder() 450 .getDatabaseMap().getName()); 451 } 452 453 463 public void save(String dbName) throws TorqueException 464 { 465 Connection con = null; 466 try 467 { 468 con = Transaction.begin(dbName); 469 save(con); 470 Transaction.commit(con); 471 } 472 catch(TorqueException e) 473 { 474 Transaction.safeRollback(con); 475 throw e; 476 } 477 } 478 479 481 private boolean alreadyInSave = false; 482 492 public void save(Connection con) throws TorqueException 493 { 494 if (!alreadyInSave) 495 { 496 alreadyInSave = true; 497 498 499 500 if (isModified()) 502 { 503 if (isNew()) 504 { 505 MITListItemPeer.doInsert((MITListItem)this, con); 506 setNew(false); 507 } 508 else 509 { 510 MITListItemPeer.doUpdate((MITListItem)this, con); 511 } 512 513 if (isCacheOnSave()) 514 { 515 MITListItemManager.putInstance(this); 516 } 517 } 518 519 alreadyInSave = false; 520 } 521 } 522 523 527 protected boolean isCacheOnSave() 528 { 529 return true; 530 } 531 532 533 538 public void setPrimaryKey(ObjectKey itemId) 539 { 540 setItemId(new Long (((NumberKey)itemId).longValue())); 541 } 542 543 548 public void setPrimaryKey(String key) 549 { 550 setItemId(new Long (key)); 551 } 552 553 554 558 public ObjectKey getPrimaryKey() 559 { 560 return SimpleKey.keyFor(getItemId()); 561 } 562 563 567 public String getQueryKey() 568 { 569 if (getPrimaryKey() == null) 570 { 571 return ""; 572 } 573 else 574 { 575 return getPrimaryKey().toString(); 576 } 577 } 578 579 583 public void setQueryKey(String key) 584 throws TorqueException 585 { 586 setPrimaryKey(key); 587 } 588 589 595 public MITListItem copy() throws TorqueException 596 { 597 MITListItem copyObj = new MITListItem(); 598 copyObj.setItemId(itemId); 599 copyObj.setModuleId(moduleId); 600 copyObj.setIssueTypeId(issueTypeId); 601 copyObj.setListId(listId); 602 603 copyObj.setItemId((Long )null); 604 605 return copyObj; 606 } 607 608 614 public MITListItemPeer getPeer() 615 { 616 return peer; 617 } 618 619 public String toString() 620 { 621 StringBuffer str = new StringBuffer (); 622 str.append("MITListItem:\n"); 623 str.append("ItemId = ") 624 .append(getItemId()) 625 .append("\n"); 626 str.append("ModuleId = ") 627 .append(getModuleId()) 628 .append("\n"); 629 str.append("IssueTypeId = ") 630 .append(getIssueTypeId()) 631 .append("\n"); 632 str.append("ListId = ") 633 .append(getListId()) 634 .append("\n"); 635 return(str.toString()); 636 } 637 } 638 | Popular Tags |