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 BaseAttributeValue extends BaseObject 35 implements org.apache.fulcrum.intake.Retrievable 36 { 37 38 private static final AttributeValuePeer peer = 39 new AttributeValuePeer(); 40 41 42 43 private Long valueId; 44 45 46 private Long issueId; 47 48 49 private Integer attributeId; 50 51 52 private Integer numericValue; 53 54 55 private Integer optionId; 56 57 58 private Integer userId; 59 60 61 private String value; 62 63 64 private boolean deleted = false; 65 66 67 72 public Long getValueId() 73 { 74 return valueId; 75 } 76 77 78 83 public void setValueId(Long v) 84 { 85 86 if (!ObjectUtils.equals(this.valueId, v)) 87 { 88 this.valueId = v; 89 setModified(true); 90 } 91 92 93 } 94 95 100 public Long getIssueId() 101 { 102 return issueId; 103 } 104 105 106 111 public void setIssueId(Long v) throws TorqueException 112 { 113 114 if (!ObjectUtils.equals(this.issueId, v)) 115 { 116 this.issueId = v; 117 setModified(true); 118 } 119 120 121 if (aIssue != null && !ObjectUtils.equals(aIssue.getIssueId(), v)) 122 { 123 aIssue = null; 124 } 125 126 } 127 128 133 public Integer getAttributeId() 134 { 135 return attributeId; 136 } 137 138 139 144 public void setAttributeId(Integer v) throws TorqueException 145 { 146 147 if (!ObjectUtils.equals(this.attributeId, v)) 148 { 149 this.attributeId = v; 150 setModified(true); 151 } 152 153 154 if (aAttribute != null && !ObjectUtils.equals(aAttribute.getAttributeId(), v)) 155 { 156 aAttribute = null; 157 } 158 159 } 160 161 166 public Integer getNumericValue() 167 { 168 return numericValue; 169 } 170 171 172 177 public void setNumericValue(Integer v) 178 { 179 180 if (!ObjectUtils.equals(this.numericValue, v)) 181 { 182 this.numericValue = v; 183 setModified(true); 184 } 185 186 187 } 188 189 194 public Integer getOptionId() 195 { 196 return optionId; 197 } 198 199 200 205 public void setOptionId(Integer v) throws TorqueException 206 { 207 208 if (!ObjectUtils.equals(this.optionId, v)) 209 { 210 this.optionId = v; 211 setModified(true); 212 } 213 214 215 if (aAttributeOption != null && !ObjectUtils.equals(aAttributeOption.getOptionId(), v)) 216 { 217 aAttributeOption = null; 218 } 219 220 } 221 222 227 public Integer getUserId() 228 { 229 return userId; 230 } 231 232 233 238 public void setUserId(Integer v) throws TorqueException 239 { 240 241 if (!ObjectUtils.equals(this.userId, v)) 242 { 243 this.userId = v; 244 setModified(true); 245 } 246 247 248 if (aScarabUser != null && !ObjectUtils.equals(aScarabUser.getUserId(), v)) 249 { 250 aScarabUser = null; 251 } 252 253 } 254 255 260 public String getValue() 261 { 262 return value; 263 } 264 265 266 271 public void setValue(String v) 272 { 273 274 if (!ObjectUtils.equals(this.value, v)) 275 { 276 this.value = v; 277 setModified(true); 278 } 279 280 281 } 282 283 288 public boolean getDeleted() 289 { 290 return deleted; 291 } 292 293 294 299 public void setDeleted(boolean v) 300 { 301 302 if (this.deleted != v) 303 { 304 this.deleted = v; 305 setModified(true); 306 } 307 308 309 } 310 311 312 313 314 private Issue aIssue; 315 316 322 public void setIssue(Issue v) throws TorqueException 323 { 324 if (v == null) 325 { 326 setIssueId((Long ) null); 327 } 328 else 329 { 330 setIssueId(v.getIssueId()); 331 } 332 aIssue = v; 333 } 334 335 336 342 public Issue getIssue() throws TorqueException 343 { 344 if ( !ObjectUtils.equals(getIssueId(), null) ) 345 { 346 return IssueManager.getInstance(SimpleKey.keyFor(getIssueId())); 347 } 348 return aIssue; 349 } 350 351 357 public void setIssueKey(ObjectKey key) throws TorqueException 358 { 359 360 setIssueId(new Long (((NumberKey) key).longValue())); 361 } 362 363 364 365 private Attribute aAttribute; 366 367 373 public void setAttribute(Attribute v) throws TorqueException 374 { 375 if (v == null) 376 { 377 setAttributeId((Integer ) null); 378 } 379 else 380 { 381 setAttributeId(v.getAttributeId()); 382 } 383 aAttribute = v; 384 } 385 386 387 393 public Attribute getAttribute() throws TorqueException 394 { 395 if ( !ObjectUtils.equals(getAttributeId(), null) ) 396 { 397 return AttributeManager.getInstance(SimpleKey.keyFor(getAttributeId())); 398 } 399 return aAttribute; 400 } 401 402 408 public void setAttributeKey(ObjectKey key) throws TorqueException 409 { 410 411 setAttributeId(new Integer (((NumberKey) key).intValue())); 412 } 413 414 415 416 private AttributeOption aAttributeOption; 417 418 424 public void setAttributeOption(AttributeOption v) throws TorqueException 425 { 426 if (v == null) 427 { 428 setOptionId((Integer ) null); 429 } 430 else 431 { 432 setOptionId(v.getOptionId()); 433 } 434 aAttributeOption = v; 435 } 436 437 438 444 public AttributeOption getAttributeOption() throws TorqueException 445 { 446 if ( !ObjectUtils.equals(getOptionId(), null) ) 447 { 448 return AttributeOptionManager.getInstance(SimpleKey.keyFor(getOptionId())); 449 } 450 return aAttributeOption; 451 } 452 453 459 public void setAttributeOptionKey(ObjectKey key) throws TorqueException 460 { 461 462 setOptionId(new Integer (((NumberKey) key).intValue())); 463 } 464 465 466 467 private ScarabUser aScarabUser; 468 469 475 public void setScarabUser(ScarabUser v) throws TorqueException 476 { 477 if (v == null) 478 { 479 setUserId((Integer ) null); 480 } 481 else 482 { 483 setUserId(v.getUserId()); 484 } 485 aScarabUser = v; 486 } 487 488 489 495 public ScarabUser getScarabUser() throws TorqueException 496 { 497 if ( !ObjectUtils.equals(getUserId(), null) ) 498 { 499 return ScarabUserManager.getInstance(SimpleKey.keyFor(getUserId())); 500 } 501 return aScarabUser; 502 } 503 504 510 public void setScarabUserKey(ObjectKey key) throws TorqueException 511 { 512 513 setUserId(new Integer (((NumberKey) key).intValue())); 514 } 515 516 517 private static List fieldNames = null; 518 519 524 public static synchronized List getFieldNames() 525 { 526 if (fieldNames == null) 527 { 528 fieldNames = new ArrayList (); 529 fieldNames.add("ValueId"); 530 fieldNames.add("IssueId"); 531 fieldNames.add("AttributeId"); 532 fieldNames.add("NumericValue"); 533 fieldNames.add("OptionId"); 534 fieldNames.add("UserId"); 535 fieldNames.add("Value"); 536 fieldNames.add("Deleted"); 537 fieldNames = Collections.unmodifiableList(fieldNames); 538 } 539 return fieldNames; 540 } 541 542 548 public Object getByName(String name) 549 { 550 if (name.equals("ValueId")) 551 { 552 return getValueId(); 553 } 554 if (name.equals("IssueId")) 555 { 556 return getIssueId(); 557 } 558 if (name.equals("AttributeId")) 559 { 560 return getAttributeId(); 561 } 562 if (name.equals("NumericValue")) 563 { 564 return getNumericValue(); 565 } 566 if (name.equals("OptionId")) 567 { 568 return getOptionId(); 569 } 570 if (name.equals("UserId")) 571 { 572 return getUserId(); 573 } 574 if (name.equals("Value")) 575 { 576 return getValue(); 577 } 578 if (name.equals("Deleted")) 579 { 580 return Boolean.valueOf(getDeleted()); 581 } 582 return null; 583 } 584 585 593 public Object getByPeerName(String name) 594 { 595 if (name.equals(AttributeValuePeer.VALUE_ID)) 596 { 597 return getValueId(); 598 } 599 if (name.equals(AttributeValuePeer.ISSUE_ID)) 600 { 601 return getIssueId(); 602 } 603 if (name.equals(AttributeValuePeer.ATTRIBUTE_ID)) 604 { 605 return getAttributeId(); 606 } 607 if (name.equals(AttributeValuePeer.NUMERIC_VALUE)) 608 { 609 return getNumericValue(); 610 } 611 if (name.equals(AttributeValuePeer.OPTION_ID)) 612 { 613 return getOptionId(); 614 } 615 if (name.equals(AttributeValuePeer.USER_ID)) 616 { 617 return getUserId(); 618 } 619 if (name.equals(AttributeValuePeer.VALUE)) 620 { 621 return getValue(); 622 } 623 if (name.equals(AttributeValuePeer.DELETED)) 624 { 625 return Boolean.valueOf(getDeleted()); 626 } 627 return null; 628 } 629 630 637 public Object getByPosition(int pos) 638 { 639 if (pos == 0) 640 { 641 return getValueId(); 642 } 643 if (pos == 1) 644 { 645 return getIssueId(); 646 } 647 if (pos == 2) 648 { 649 return getAttributeId(); 650 } 651 if (pos == 3) 652 { 653 return getNumericValue(); 654 } 655 if (pos == 4) 656 { 657 return getOptionId(); 658 } 659 if (pos == 5) 660 { 661 return getUserId(); 662 } 663 if (pos == 6) 664 { 665 return getValue(); 666 } 667 if (pos == 7) 668 { 669 return Boolean.valueOf(getDeleted()); 670 } 671 return null; 672 } 673 674 680 public void save() throws Exception 681 { 682 save(AttributeValuePeer.getMapBuilder() 683 .getDatabaseMap().getName()); 684 } 685 686 696 public void save(String dbName) throws TorqueException 697 { 698 Connection con = null; 699 try 700 { 701 con = Transaction.begin(dbName); 702 save(con); 703 Transaction.commit(con); 704 } 705 catch(TorqueException e) 706 { 707 Transaction.safeRollback(con); 708 throw e; 709 } 710 } 711 712 714 private boolean alreadyInSave = false; 715 725 public void save(Connection con) throws TorqueException 726 { 727 if (!alreadyInSave) 728 { 729 alreadyInSave = true; 730 731 732 733 if (isModified()) 735 { 736 if (isNew()) 737 { 738 AttributeValuePeer.doInsert((AttributeValue)this, con); 739 setNew(false); 740 } 741 else 742 { 743 AttributeValuePeer.doUpdate((AttributeValue)this, con); 744 } 745 746 if (isCacheOnSave()) 747 { 748 AttributeValueManager.putInstance(this); 749 } 750 } 751 752 alreadyInSave = false; 753 } 754 } 755 756 760 protected boolean isCacheOnSave() 761 { 762 return true; 763 } 764 765 766 771 public void setPrimaryKey(ObjectKey valueId) 772 { 773 setValueId(new Long (((NumberKey)valueId).longValue())); 774 } 775 776 781 public void setPrimaryKey(String key) 782 { 783 setValueId(new Long (key)); 784 } 785 786 787 791 public ObjectKey getPrimaryKey() 792 { 793 return SimpleKey.keyFor(getValueId()); 794 } 795 796 800 public String getQueryKey() 801 { 802 if (getPrimaryKey() == null) 803 { 804 return ""; 805 } 806 else 807 { 808 return getPrimaryKey().toString(); 809 } 810 } 811 812 816 public void setQueryKey(String key) 817 throws TorqueException 818 { 819 setPrimaryKey(key); 820 } 821 822 828 public AttributeValue copyInto(AttributeValue copyObj) throws TorqueException 829 { 830 copyObj.setValueId(valueId); 831 copyObj.setIssueId(issueId); 832 copyObj.setAttributeId(attributeId); 833 copyObj.setNumericValue(numericValue); 834 copyObj.setOptionId(optionId); 835 copyObj.setUserId(userId); 836 copyObj.setValue(value); 837 copyObj.setDeleted(deleted); 838 839 copyObj.setValueId((Long )null); 840 841 return copyObj; 842 } 843 844 850 public AttributeValuePeer getPeer() 851 { 852 return peer; 853 } 854 855 public String toString() 856 { 857 StringBuffer str = new StringBuffer (); 858 str.append("AttributeValue:\n"); 859 str.append("ValueId = ") 860 .append(getValueId()) 861 .append("\n"); 862 str.append("IssueId = ") 863 .append(getIssueId()) 864 .append("\n"); 865 str.append("AttributeId = ") 866 .append(getAttributeId()) 867 .append("\n"); 868 str.append("NumericValue = ") 869 .append(getNumericValue()) 870 .append("\n"); 871 str.append("OptionId = ") 872 .append(getOptionId()) 873 .append("\n"); 874 str.append("UserId = ") 875 .append(getUserId()) 876 .append("\n"); 877 str.append("Value = ") 878 .append(getValue()) 879 .append("\n"); 880 str.append("Deleted = ") 881 .append(getDeleted()) 882 .append("\n"); 883 return(str.toString()); 884 } 885 } 886 | Popular Tags |