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 30 public abstract class BaseAttachmentType extends BaseObject 31 implements org.apache.fulcrum.intake.Retrievable 32 { 33 34 private static final AttachmentTypePeer peer = 35 new AttachmentTypePeer(); 36 37 38 39 private Integer attachmentTypeId; 40 41 42 private String name; 43 44 45 private boolean searchable = false; 46 47 48 53 public Integer getAttachmentTypeId() 54 { 55 return attachmentTypeId; 56 } 57 58 59 64 public void setAttachmentTypeId(Integer v) throws TorqueException 65 { 66 67 if (!ObjectUtils.equals(this.attachmentTypeId, v)) 68 { 69 this.attachmentTypeId = v; 70 setModified(true); 71 } 72 73 74 75 if (collAttachments != null) 77 { 78 for (int i = 0; i < collAttachments.size(); i++) 79 { 80 ((Attachment) collAttachments.get(i)) 81 .setTypeId(v); 82 } 83 } 84 } 85 86 91 public String getName() 92 { 93 return name; 94 } 95 96 97 102 public void setName(String v) 103 { 104 105 if (!ObjectUtils.equals(this.name, v)) 106 { 107 this.name = v; 108 setModified(true); 109 } 110 111 112 } 113 114 119 public boolean getSearchable() 120 { 121 return searchable; 122 } 123 124 125 130 public void setSearchable(boolean v) 131 { 132 133 if (this.searchable != v) 134 { 135 this.searchable = v; 136 setModified(true); 137 } 138 139 140 } 141 142 143 144 145 148 protected List collAttachments; 149 150 155 protected void initAttachments() 156 { 157 if (collAttachments == null) 158 { 159 collAttachments = new ArrayList (); 160 } 161 } 162 163 164 171 public void addAttachment(Attachment l) throws TorqueException 172 { 173 getAttachments().add(l); 174 l.setAttachmentType((AttachmentType)this); 175 } 176 177 180 private Criteria lastAttachmentsCriteria = null; 181 182 189 public List getAttachments() throws TorqueException 190 { 191 if (collAttachments == null) 192 { 193 collAttachments = getAttachments(new Criteria(10)); 194 } 195 return collAttachments; 196 } 197 198 209 public List getAttachments(Criteria criteria) throws TorqueException 210 { 211 if (collAttachments == null) 212 { 213 if (isNew()) 214 { 215 collAttachments = new ArrayList (); 216 } 217 else 218 { 219 criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() ); 220 collAttachments = AttachmentPeer.doSelect(criteria); 221 } 222 } 223 else 224 { 225 if (!isNew()) 227 { 228 criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() ); 232 if (!lastAttachmentsCriteria.equals(criteria)) 233 { 234 collAttachments = AttachmentPeer.doSelect(criteria); 235 } 236 } 237 } 238 lastAttachmentsCriteria = criteria; 239 240 return collAttachments; 241 } 242 243 251 public List getAttachments(Connection con) throws TorqueException 252 { 253 if (collAttachments == null) 254 { 255 collAttachments = getAttachments(new Criteria(10),con); 256 } 257 return collAttachments; 258 } 259 260 272 public List getAttachments(Criteria criteria,Connection con) throws TorqueException 273 { 274 if (collAttachments == null) 275 { 276 if (isNew()) 277 { 278 collAttachments = new ArrayList (); 279 } 280 else 281 { 282 criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() ); 283 collAttachments = AttachmentPeer.doSelect(criteria,con); 284 } 285 } 286 else 287 { 288 if (!isNew()) 290 { 291 criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() ); 295 if (!lastAttachmentsCriteria.equals(criteria)) 296 { 297 collAttachments = AttachmentPeer.doSelect(criteria,con); 298 } 299 } 300 } 301 lastAttachmentsCriteria = criteria; 302 303 return collAttachments; 304 } 305 306 307 308 309 310 311 312 313 314 315 316 327 protected List getAttachmentsJoinIssue(Criteria criteria) 328 throws TorqueException 329 { 330 if (collAttachments == null) 331 { 332 if (isNew()) 333 { 334 collAttachments = new ArrayList (); 335 } 336 else 337 { 338 criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() ); 339 collAttachments = AttachmentPeer.doSelectJoinIssue(criteria); 340 } 341 } 342 else 343 { 344 348 criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() ); 349 if (!lastAttachmentsCriteria.equals(criteria)) 350 { 351 collAttachments = AttachmentPeer.doSelectJoinIssue(criteria); 352 } 353 } 354 lastAttachmentsCriteria = criteria; 355 356 return collAttachments; 357 } 358 359 360 361 362 363 364 365 366 367 378 protected List getAttachmentsJoinAttachmentType(Criteria criteria) 379 throws TorqueException 380 { 381 if (collAttachments == null) 382 { 383 if (isNew()) 384 { 385 collAttachments = new ArrayList (); 386 } 387 else 388 { 389 criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() ); 390 collAttachments = AttachmentPeer.doSelectJoinAttachmentType(criteria); 391 } 392 } 393 else 394 { 395 399 criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() ); 400 if (!lastAttachmentsCriteria.equals(criteria)) 401 { 402 collAttachments = AttachmentPeer.doSelectJoinAttachmentType(criteria); 403 } 404 } 405 lastAttachmentsCriteria = criteria; 406 407 return collAttachments; 408 } 409 410 411 412 413 414 415 416 417 418 429 protected List getAttachmentsJoinScarabUserImplRelatedByCreatedBy(Criteria criteria) 430 throws TorqueException 431 { 432 if (collAttachments == null) 433 { 434 if (isNew()) 435 { 436 collAttachments = new ArrayList (); 437 } 438 else 439 { 440 criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() ); 441 collAttachments = AttachmentPeer.doSelectJoinScarabUserImplRelatedByCreatedBy(criteria); 442 } 443 } 444 else 445 { 446 450 criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() ); 451 if (!lastAttachmentsCriteria.equals(criteria)) 452 { 453 collAttachments = AttachmentPeer.doSelectJoinScarabUserImplRelatedByCreatedBy(criteria); 454 } 455 } 456 lastAttachmentsCriteria = criteria; 457 458 return collAttachments; 459 } 460 461 462 463 464 465 466 467 468 469 480 protected List getAttachmentsJoinScarabUserImplRelatedByModifiedBy(Criteria criteria) 481 throws TorqueException 482 { 483 if (collAttachments == null) 484 { 485 if (isNew()) 486 { 487 collAttachments = new ArrayList (); 488 } 489 else 490 { 491 criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() ); 492 collAttachments = AttachmentPeer.doSelectJoinScarabUserImplRelatedByModifiedBy(criteria); 493 } 494 } 495 else 496 { 497 501 criteria.add(AttachmentPeer.ATTACHMENT_TYPE_ID, getAttachmentTypeId() ); 502 if (!lastAttachmentsCriteria.equals(criteria)) 503 { 504 collAttachments = AttachmentPeer.doSelectJoinScarabUserImplRelatedByModifiedBy(criteria); 505 } 506 } 507 lastAttachmentsCriteria = criteria; 508 509 return collAttachments; 510 } 511 512 513 514 515 private static List fieldNames = null; 516 517 522 public static synchronized List getFieldNames() 523 { 524 if (fieldNames == null) 525 { 526 fieldNames = new ArrayList (); 527 fieldNames.add("AttachmentTypeId"); 528 fieldNames.add("Name"); 529 fieldNames.add("Searchable"); 530 fieldNames = Collections.unmodifiableList(fieldNames); 531 } 532 return fieldNames; 533 } 534 535 541 public Object getByName(String name) 542 { 543 if (name.equals("AttachmentTypeId")) 544 { 545 return getAttachmentTypeId(); 546 } 547 if (name.equals("Name")) 548 { 549 return getName(); 550 } 551 if (name.equals("Searchable")) 552 { 553 return Boolean.valueOf(getSearchable()); 554 } 555 return null; 556 } 557 558 566 public Object getByPeerName(String name) 567 { 568 if (name.equals(AttachmentTypePeer.ATTACHMENT_TYPE_ID)) 569 { 570 return getAttachmentTypeId(); 571 } 572 if (name.equals(AttachmentTypePeer.ATTACHMENT_TYPE_NAME)) 573 { 574 return getName(); 575 } 576 if (name.equals(AttachmentTypePeer.SEARCHABLE)) 577 { 578 return Boolean.valueOf(getSearchable()); 579 } 580 return null; 581 } 582 583 590 public Object getByPosition(int pos) 591 { 592 if (pos == 0) 593 { 594 return getAttachmentTypeId(); 595 } 596 if (pos == 1) 597 { 598 return getName(); 599 } 600 if (pos == 2) 601 { 602 return Boolean.valueOf(getSearchable()); 603 } 604 return null; 605 } 606 607 613 public void save() throws Exception 614 { 615 save(AttachmentTypePeer.getMapBuilder() 616 .getDatabaseMap().getName()); 617 } 618 619 629 public void save(String dbName) throws TorqueException 630 { 631 Connection con = null; 632 try 633 { 634 con = Transaction.begin(dbName); 635 save(con); 636 Transaction.commit(con); 637 } 638 catch(TorqueException e) 639 { 640 Transaction.safeRollback(con); 641 throw e; 642 } 643 } 644 645 647 private boolean alreadyInSave = false; 648 658 public void save(Connection con) throws TorqueException 659 { 660 if (!alreadyInSave) 661 { 662 alreadyInSave = true; 663 664 665 666 if (isModified()) 668 { 669 if (isNew()) 670 { 671 AttachmentTypePeer.doInsert((AttachmentType)this, con); 672 setNew(false); 673 } 674 else 675 { 676 AttachmentTypePeer.doUpdate((AttachmentType)this, con); 677 } 678 679 if (isCacheOnSave()) 680 { 681 AttachmentTypeManager.putInstance(this); 682 } 683 } 684 685 686 if (collAttachments != null) 687 { 688 for (int i = 0; i < collAttachments.size(); i++) 689 { 690 ((Attachment)collAttachments.get(i)).save(con); 691 } 692 } 693 alreadyInSave = false; 694 } 695 } 696 697 701 protected boolean isCacheOnSave() 702 { 703 return true; 704 } 705 706 707 712 public void setPrimaryKey(ObjectKey attachmentTypeId) 713 throws TorqueException { 714 setAttachmentTypeId(new Integer (((NumberKey)attachmentTypeId).intValue())); 715 } 716 717 722 public void setPrimaryKey(String key) throws TorqueException 723 { 724 setAttachmentTypeId(new Integer (key)); 725 } 726 727 728 732 public ObjectKey getPrimaryKey() 733 { 734 return SimpleKey.keyFor(getAttachmentTypeId()); 735 } 736 737 741 public String getQueryKey() 742 { 743 if (getPrimaryKey() == null) 744 { 745 return ""; 746 } 747 else 748 { 749 return getPrimaryKey().toString(); 750 } 751 } 752 753 757 public void setQueryKey(String key) 758 throws TorqueException 759 { 760 setPrimaryKey(key); 761 } 762 763 769 public AttachmentType copy() throws TorqueException 770 { 771 AttachmentType copyObj = new AttachmentType(); 772 copyObj.setAttachmentTypeId(attachmentTypeId); 773 copyObj.setName(name); 774 copyObj.setSearchable(searchable); 775 776 copyObj.setAttachmentTypeId((Integer )null); 777 778 779 780 List v = getAttachments(); 781 for (int i = 0; i < v.size(); i++) 782 { 783 Attachment obj = (Attachment) v.get(i); 784 copyObj.addAttachment(obj.copy()); 785 } 786 return copyObj; 787 } 788 789 795 public AttachmentTypePeer getPeer() 796 { 797 return peer; 798 } 799 800 public String toString() 801 { 802 StringBuffer str = new StringBuffer (); 803 str.append("AttachmentType:\n"); 804 str.append("AttachmentTypeId = ") 805 .append(getAttachmentTypeId()) 806 .append("\n"); 807 str.append("Name = ") 808 .append(getName()) 809 .append("\n"); 810 str.append("Searchable = ") 811 .append(getSearchable()) 812 .append("\n"); 813 return(str.toString()); 814 } 815 } 816 | Popular Tags |