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 30 34 public abstract class BaseReport extends BaseObject 35 implements org.apache.fulcrum.intake.Retrievable 36 { 37 38 private static final ReportPeer peer = 39 new ReportPeer(); 40 41 42 43 private Integer reportId; 44 45 46 private Integer userId; 47 48 49 private Integer moduleId; 50 51 52 private Integer issueTypeId; 53 54 55 private String name; 56 57 58 private String description; 59 60 61 private String queryString; 62 63 64 private Integer scopeId; 65 66 67 private boolean deleted = false; 68 69 70 private Date createdDate; 71 72 73 78 public Integer getReportId() 79 { 80 return reportId; 81 } 82 83 84 89 public void setReportId(Integer v) 90 { 91 92 if (!ObjectUtils.equals(this.reportId, v)) 93 { 94 this.reportId = v; 95 setModified(true); 96 } 97 98 99 } 100 101 106 public Integer getUserId() 107 { 108 return userId; 109 } 110 111 112 117 public void setUserId(Integer v) throws TorqueException 118 { 119 120 if (!ObjectUtils.equals(this.userId, v)) 121 { 122 this.userId = v; 123 setModified(true); 124 } 125 126 127 if (aScarabUser != null && !ObjectUtils.equals(aScarabUser.getUserId(), v)) 128 { 129 aScarabUser = null; 130 } 131 132 } 133 134 139 public Integer getModuleId() 140 { 141 return moduleId; 142 } 143 144 145 150 public void setModuleId(Integer v) throws TorqueException 151 { 152 153 if (!ObjectUtils.equals(this.moduleId, v)) 154 { 155 this.moduleId = v; 156 setModified(true); 157 } 158 159 160 if (aModule != null && !ObjectUtils.equals(aModule.getModuleId(), v)) 161 { 162 aModule = null; 163 } 164 165 } 166 167 172 public Integer getIssueTypeId() 173 { 174 return issueTypeId; 175 } 176 177 178 183 public void setIssueTypeId(Integer v) throws TorqueException 184 { 185 186 if (!ObjectUtils.equals(this.issueTypeId, v)) 187 { 188 this.issueTypeId = v; 189 setModified(true); 190 } 191 192 193 if (aIssueType != null && !ObjectUtils.equals(aIssueType.getIssueTypeId(), v)) 194 { 195 aIssueType = null; 196 } 197 198 } 199 200 205 public String getName() 206 { 207 return name; 208 } 209 210 211 216 public void setName(String v) 217 { 218 219 if (!ObjectUtils.equals(this.name, v)) 220 { 221 this.name = v; 222 setModified(true); 223 } 224 225 226 } 227 228 233 public String getDescription() 234 { 235 return description; 236 } 237 238 239 244 public void setDescription(String v) 245 { 246 247 if (!ObjectUtils.equals(this.description, v)) 248 { 249 this.description = v; 250 setModified(true); 251 } 252 253 254 } 255 256 261 public String getQueryString() 262 { 263 return queryString; 264 } 265 266 267 272 public void setQueryString(String v) 273 { 274 275 if (!ObjectUtils.equals(this.queryString, v)) 276 { 277 this.queryString = v; 278 setModified(true); 279 } 280 281 282 } 283 284 289 public Integer getScopeId() 290 { 291 return scopeId; 292 } 293 294 295 300 public void setScopeId(Integer v) throws TorqueException 301 { 302 303 if (!ObjectUtils.equals(this.scopeId, v)) 304 { 305 this.scopeId = v; 306 setModified(true); 307 } 308 309 310 if (aScope != null && !ObjectUtils.equals(aScope.getScopeId(), v)) 311 { 312 aScope = null; 313 } 314 315 } 316 317 322 public boolean getDeleted() 323 { 324 return deleted; 325 } 326 327 328 333 public void setDeleted(boolean v) 334 { 335 336 if (this.deleted != v) 337 { 338 this.deleted = v; 339 setModified(true); 340 } 341 342 343 } 344 345 350 public Date getCreatedDate() 351 { 352 return createdDate; 353 } 354 355 356 361 public void setCreatedDate(Date v) 362 { 363 364 if (!ObjectUtils.equals(this.createdDate, v)) 365 { 366 this.createdDate = v; 367 setModified(true); 368 } 369 370 371 } 372 373 374 375 376 private IssueType aIssueType; 377 378 384 public void setIssueType(IssueType v) throws TorqueException 385 { 386 if (v == null) 387 { 388 setIssueTypeId((Integer ) null); 389 } 390 else 391 { 392 setIssueTypeId(v.getIssueTypeId()); 393 } 394 aIssueType = v; 395 } 396 397 398 404 public IssueType getIssueType() throws TorqueException 405 { 406 if ( !ObjectUtils.equals(getIssueTypeId(), null) ) 407 { 408 return IssueTypeManager.getInstance(SimpleKey.keyFor(getIssueTypeId())); 409 } 410 return aIssueType; 411 } 412 413 419 public void setIssueTypeKey(ObjectKey key) throws TorqueException 420 { 421 422 setIssueTypeId(new Integer (((NumberKey) key).intValue())); 423 } 424 425 426 427 private ScarabUser aScarabUser; 428 429 435 public void setScarabUser(ScarabUser v) throws TorqueException 436 { 437 if (v == null) 438 { 439 setUserId((Integer ) null); 440 } 441 else 442 { 443 setUserId(v.getUserId()); 444 } 445 aScarabUser = v; 446 } 447 448 449 455 public ScarabUser getScarabUser() throws TorqueException 456 { 457 if ( !ObjectUtils.equals(getUserId(), null) ) 458 { 459 return ScarabUserManager.getInstance(SimpleKey.keyFor(getUserId())); 460 } 461 return aScarabUser; 462 } 463 464 470 public void setScarabUserKey(ObjectKey key) throws TorqueException 471 { 472 473 setUserId(new Integer (((NumberKey) key).intValue())); 474 } 475 476 477 478 private Module aModule; 479 480 486 public void setModule(Module v) throws TorqueException 487 { 488 if (v == null) 489 { 490 setModuleId((Integer ) null); 491 } 492 else 493 { 494 setModuleId(v.getModuleId()); 495 } 496 aModule = v; 497 } 498 499 500 506 public Module getModule() throws TorqueException 507 { 508 if ( !ObjectUtils.equals(getModuleId(), null) ) 509 { 510 return ModuleManager.getInstance(SimpleKey.keyFor(getModuleId())); 511 } 512 return aModule; 513 } 514 515 521 public void setModuleKey(ObjectKey key) throws TorqueException 522 { 523 524 setModuleId(new Integer (((NumberKey) key).intValue())); 525 } 526 527 528 529 private Scope aScope; 530 531 537 public void setScope(Scope v) throws TorqueException 538 { 539 if (v == null) 540 { 541 setScopeId((Integer ) null); 542 } 543 else 544 { 545 setScopeId(v.getScopeId()); 546 } 547 aScope = v; 548 } 549 550 551 557 public Scope getScope() throws TorqueException 558 { 559 if ( !ObjectUtils.equals(getScopeId(), null) ) 560 { 561 return ScopeManager.getInstance(SimpleKey.keyFor(getScopeId())); 562 } 563 return aScope; 564 } 565 566 572 public void setScopeKey(ObjectKey key) throws TorqueException 573 { 574 575 setScopeId(new Integer (((NumberKey) key).intValue())); 576 } 577 578 579 private static List fieldNames = null; 580 581 586 public static synchronized List getFieldNames() 587 { 588 if (fieldNames == null) 589 { 590 fieldNames = new ArrayList (); 591 fieldNames.add("ReportId"); 592 fieldNames.add("UserId"); 593 fieldNames.add("ModuleId"); 594 fieldNames.add("IssueTypeId"); 595 fieldNames.add("Name"); 596 fieldNames.add("Description"); 597 fieldNames.add("QueryString"); 598 fieldNames.add("ScopeId"); 599 fieldNames.add("Deleted"); 600 fieldNames.add("CreatedDate"); 601 fieldNames = Collections.unmodifiableList(fieldNames); 602 } 603 return fieldNames; 604 } 605 606 612 public Object getByName(String name) 613 { 614 if (name.equals("ReportId")) 615 { 616 return getReportId(); 617 } 618 if (name.equals("UserId")) 619 { 620 return getUserId(); 621 } 622 if (name.equals("ModuleId")) 623 { 624 return getModuleId(); 625 } 626 if (name.equals("IssueTypeId")) 627 { 628 return getIssueTypeId(); 629 } 630 if (name.equals("Name")) 631 { 632 return getName(); 633 } 634 if (name.equals("Description")) 635 { 636 return getDescription(); 637 } 638 if (name.equals("QueryString")) 639 { 640 return getQueryString(); 641 } 642 if (name.equals("ScopeId")) 643 { 644 return getScopeId(); 645 } 646 if (name.equals("Deleted")) 647 { 648 return Boolean.valueOf(getDeleted()); 649 } 650 if (name.equals("CreatedDate")) 651 { 652 return getCreatedDate(); 653 } 654 return null; 655 } 656 657 665 public Object getByPeerName(String name) 666 { 667 if (name.equals(ReportPeer.REPORT_ID)) 668 { 669 return getReportId(); 670 } 671 if (name.equals(ReportPeer.USER_ID)) 672 { 673 return getUserId(); 674 } 675 if (name.equals(ReportPeer.MODULE_ID)) 676 { 677 return getModuleId(); 678 } 679 if (name.equals(ReportPeer.ISSUE_TYPE_ID)) 680 { 681 return getIssueTypeId(); 682 } 683 if (name.equals(ReportPeer.NAME)) 684 { 685 return getName(); 686 } 687 if (name.equals(ReportPeer.DESCRIPTION)) 688 { 689 return getDescription(); 690 } 691 if (name.equals(ReportPeer.QUERY_STRING)) 692 { 693 return getQueryString(); 694 } 695 if (name.equals(ReportPeer.SCOPE_ID)) 696 { 697 return getScopeId(); 698 } 699 if (name.equals(ReportPeer.DELETED)) 700 { 701 return Boolean.valueOf(getDeleted()); 702 } 703 if (name.equals(ReportPeer.CREATED_DATE)) 704 { 705 return getCreatedDate(); 706 } 707 return null; 708 } 709 710 717 public Object getByPosition(int pos) 718 { 719 if (pos == 0) 720 { 721 return getReportId(); 722 } 723 if (pos == 1) 724 { 725 return getUserId(); 726 } 727 if (pos == 2) 728 { 729 return getModuleId(); 730 } 731 if (pos == 3) 732 { 733 return getIssueTypeId(); 734 } 735 if (pos == 4) 736 { 737 return getName(); 738 } 739 if (pos == 5) 740 { 741 return getDescription(); 742 } 743 if (pos == 6) 744 { 745 return getQueryString(); 746 } 747 if (pos == 7) 748 { 749 return getScopeId(); 750 } 751 if (pos == 8) 752 { 753 return Boolean.valueOf(getDeleted()); 754 } 755 if (pos == 9) 756 { 757 return getCreatedDate(); 758 } 759 return null; 760 } 761 762 768 public void save() throws Exception 769 { 770 save(ReportPeer.getMapBuilder() 771 .getDatabaseMap().getName()); 772 } 773 774 784 public void save(String dbName) throws TorqueException 785 { 786 Connection con = null; 787 try 788 { 789 con = Transaction.begin(dbName); 790 save(con); 791 Transaction.commit(con); 792 } 793 catch(TorqueException e) 794 { 795 Transaction.safeRollback(con); 796 throw e; 797 } 798 } 799 800 802 private boolean alreadyInSave = false; 803 813 public void save(Connection con) throws TorqueException 814 { 815 if (!alreadyInSave) 816 { 817 alreadyInSave = true; 818 819 820 821 if (isModified()) 823 { 824 if (isNew()) 825 { 826 ReportPeer.doInsert((Report)this, con); 827 setNew(false); 828 } 829 else 830 { 831 ReportPeer.doUpdate((Report)this, con); 832 } 833 834 if (isCacheOnSave()) 835 { 836 ReportManager.putInstance(this); 837 } 838 } 839 840 alreadyInSave = false; 841 } 842 } 843 844 848 protected boolean isCacheOnSave() 849 { 850 return true; 851 } 852 853 854 859 public void setPrimaryKey(ObjectKey reportId) 860 { 861 setReportId(new Integer (((NumberKey)reportId).intValue())); 862 } 863 864 869 public void setPrimaryKey(String key) 870 { 871 setReportId(new Integer (key)); 872 } 873 874 875 879 public ObjectKey getPrimaryKey() 880 { 881 return SimpleKey.keyFor(getReportId()); 882 } 883 884 888 public String getQueryKey() 889 { 890 if (getPrimaryKey() == null) 891 { 892 return ""; 893 } 894 else 895 { 896 return getPrimaryKey().toString(); 897 } 898 } 899 900 904 public void setQueryKey(String key) 905 throws TorqueException 906 { 907 setPrimaryKey(key); 908 } 909 910 916 public Report copy() throws TorqueException 917 { 918 Report copyObj = new Report(); 919 copyObj.setReportId(reportId); 920 copyObj.setUserId(userId); 921 copyObj.setModuleId(moduleId); 922 copyObj.setIssueTypeId(issueTypeId); 923 copyObj.setName(name); 924 copyObj.setDescription(description); 925 copyObj.setQueryString(queryString); 926 copyObj.setScopeId(scopeId); 927 copyObj.setDeleted(deleted); 928 copyObj.setCreatedDate(createdDate); 929 930 copyObj.setReportId((Integer )null); 931 932 return copyObj; 933 } 934 935 941 public ReportPeer getPeer() 942 { 943 return peer; 944 } 945 946 public String toString() 947 { 948 StringBuffer str = new StringBuffer (); 949 str.append("Report:\n"); 950 str.append("ReportId = ") 951 .append(getReportId()) 952 .append("\n"); 953 str.append("UserId = ") 954 .append(getUserId()) 955 .append("\n"); 956 str.append("ModuleId = ") 957 .append(getModuleId()) 958 .append("\n"); 959 str.append("IssueTypeId = ") 960 .append(getIssueTypeId()) 961 .append("\n"); 962 str.append("Name = ") 963 .append(getName()) 964 .append("\n"); 965 str.append("Description = ") 966 .append(getDescription()) 967 .append("\n"); 968 str.append("QueryString = ") 969 .append(getQueryString()) 970 .append("\n"); 971 str.append("ScopeId = ") 972 .append(getScopeId()) 973 .append("\n"); 974 str.append("Deleted = ") 975 .append(getDeleted()) 976 .append("\n"); 977 str.append("CreatedDate = ") 978 .append(getCreatedDate()) 979 .append("\n"); 980 return(str.toString()); 981 } 982 } 983 | Popular Tags |