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 31 public abstract class BaseAttributeType extends BaseObject 32 implements org.apache.fulcrum.intake.Retrievable 33 { 34 35 private static final AttributeTypePeer peer = 36 new AttributeTypePeer(); 37 38 39 40 private Integer attributeTypeId; 41 42 43 private Integer classId; 44 45 46 private String name; 47 48 49 private String javaClassName; 50 51 52 private String validationKey; 53 54 55 60 public Integer getAttributeTypeId() 61 { 62 return attributeTypeId; 63 } 64 65 66 71 public void setAttributeTypeId(Integer v) throws TorqueException 72 { 73 74 if (!ObjectUtils.equals(this.attributeTypeId, v)) 75 { 76 this.attributeTypeId = v; 77 setModified(true); 78 } 79 80 81 82 if (collAttributes != null) 84 { 85 for (int i = 0; i < collAttributes.size(); i++) 86 { 87 ((Attribute) collAttributes.get(i)) 88 .setTypeId(v); 89 } 90 } 91 } 92 93 98 public Integer getClassId() 99 { 100 return classId; 101 } 102 103 104 109 public void setClassId(Integer v) throws TorqueException 110 { 111 112 if (!ObjectUtils.equals(this.classId, v)) 113 { 114 this.classId = v; 115 setModified(true); 116 } 117 118 119 if (aAttributeClass != null && !ObjectUtils.equals(aAttributeClass.getAttributeClassId(), v)) 120 { 121 aAttributeClass = null; 122 } 123 124 } 125 126 131 public String getName() 132 { 133 return name; 134 } 135 136 137 142 public void setName(String v) 143 { 144 145 if (!ObjectUtils.equals(this.name, v)) 146 { 147 this.name = v; 148 setModified(true); 149 } 150 151 152 } 153 154 159 public String getJavaClassName() 160 { 161 return javaClassName; 162 } 163 164 165 170 public void setJavaClassName(String v) 171 { 172 173 if (!ObjectUtils.equals(this.javaClassName, v)) 174 { 175 this.javaClassName = v; 176 setModified(true); 177 } 178 179 180 } 181 182 187 public String getValidationKey() 188 { 189 return validationKey; 190 } 191 192 193 198 public void setValidationKey(String v) 199 { 200 201 if (!ObjectUtils.equals(this.validationKey, v)) 202 { 203 this.validationKey = v; 204 setModified(true); 205 } 206 207 208 } 209 210 211 212 213 private AttributeClass aAttributeClass; 214 215 221 public void setAttributeClass(AttributeClass v) throws TorqueException 222 { 223 if (v == null) 224 { 225 setClassId((Integer ) null); 226 } 227 else 228 { 229 setClassId(v.getAttributeClassId()); 230 } 231 aAttributeClass = v; 232 } 233 234 235 241 public AttributeClass getAttributeClass() throws TorqueException 242 { 243 if ( !ObjectUtils.equals(getClassId(), null) ) 244 { 245 return AttributeClassManager.getInstance(SimpleKey.keyFor(getClassId())); 246 } 247 return aAttributeClass; 248 } 249 250 256 public void setAttributeClassKey(ObjectKey key) throws TorqueException 257 { 258 259 setClassId(new Integer (((NumberKey) key).intValue())); 260 } 261 262 263 264 267 protected List collAttributes; 268 269 274 protected void initAttributes() 275 { 276 if (collAttributes == null) 277 { 278 collAttributes = new ArrayList (); 279 } 280 } 281 282 283 290 public void addAttribute(Attribute l) throws TorqueException 291 { 292 getAttributes().add(l); 293 l.setAttributeType((AttributeType)this); 294 } 295 296 299 private Criteria lastAttributesCriteria = null; 300 301 308 public List getAttributes() throws TorqueException 309 { 310 if (collAttributes == null) 311 { 312 collAttributes = getAttributes(new Criteria(10)); 313 } 314 return collAttributes; 315 } 316 317 328 public List getAttributes(Criteria criteria) throws TorqueException 329 { 330 if (collAttributes == null) 331 { 332 if (isNew()) 333 { 334 collAttributes = new ArrayList (); 335 } 336 else 337 { 338 criteria.add(AttributePeer.ATTRIBUTE_TYPE_ID, getAttributeTypeId() ); 339 collAttributes = AttributePeer.doSelect(criteria); 340 } 341 } 342 else 343 { 344 if (!isNew()) 346 { 347 criteria.add(AttributePeer.ATTRIBUTE_TYPE_ID, getAttributeTypeId() ); 351 if (!lastAttributesCriteria.equals(criteria)) 352 { 353 collAttributes = AttributePeer.doSelect(criteria); 354 } 355 } 356 } 357 lastAttributesCriteria = criteria; 358 359 return collAttributes; 360 } 361 362 370 public List getAttributes(Connection con) throws TorqueException 371 { 372 if (collAttributes == null) 373 { 374 collAttributes = getAttributes(new Criteria(10),con); 375 } 376 return collAttributes; 377 } 378 379 391 public List getAttributes(Criteria criteria,Connection con) throws TorqueException 392 { 393 if (collAttributes == null) 394 { 395 if (isNew()) 396 { 397 collAttributes = new ArrayList (); 398 } 399 else 400 { 401 criteria.add(AttributePeer.ATTRIBUTE_TYPE_ID, getAttributeTypeId() ); 402 collAttributes = AttributePeer.doSelect(criteria,con); 403 } 404 } 405 else 406 { 407 if (!isNew()) 409 { 410 criteria.add(AttributePeer.ATTRIBUTE_TYPE_ID, getAttributeTypeId() ); 414 if (!lastAttributesCriteria.equals(criteria)) 415 { 416 collAttributes = AttributePeer.doSelect(criteria,con); 417 } 418 } 419 } 420 lastAttributesCriteria = criteria; 421 422 return collAttributes; 423 } 424 425 426 427 428 429 430 431 432 433 434 435 446 protected List getAttributesJoinAttributeType(Criteria criteria) 447 throws TorqueException 448 { 449 if (collAttributes == null) 450 { 451 if (isNew()) 452 { 453 collAttributes = new ArrayList (); 454 } 455 else 456 { 457 criteria.add(AttributePeer.ATTRIBUTE_TYPE_ID, getAttributeTypeId() ); 458 collAttributes = AttributePeer.doSelectJoinAttributeType(criteria); 459 } 460 } 461 else 462 { 463 467 criteria.add(AttributePeer.ATTRIBUTE_TYPE_ID, getAttributeTypeId() ); 468 if (!lastAttributesCriteria.equals(criteria)) 469 { 470 collAttributes = AttributePeer.doSelectJoinAttributeType(criteria); 471 } 472 } 473 lastAttributesCriteria = criteria; 474 475 return collAttributes; 476 } 477 478 479 480 481 482 483 484 485 486 497 protected List getAttributesJoinAttributeOption(Criteria criteria) 498 throws TorqueException 499 { 500 if (collAttributes == null) 501 { 502 if (isNew()) 503 { 504 collAttributes = new ArrayList (); 505 } 506 else 507 { 508 criteria.add(AttributePeer.ATTRIBUTE_TYPE_ID, getAttributeTypeId() ); 509 collAttributes = AttributePeer.doSelectJoinAttributeOption(criteria); 510 } 511 } 512 else 513 { 514 518 criteria.add(AttributePeer.ATTRIBUTE_TYPE_ID, getAttributeTypeId() ); 519 if (!lastAttributesCriteria.equals(criteria)) 520 { 521 collAttributes = AttributePeer.doSelectJoinAttributeOption(criteria); 522 } 523 } 524 lastAttributesCriteria = criteria; 525 526 return collAttributes; 527 } 528 529 530 531 532 533 534 535 536 537 548 protected List getAttributesJoinScarabUserImpl(Criteria criteria) 549 throws TorqueException 550 { 551 if (collAttributes == null) 552 { 553 if (isNew()) 554 { 555 collAttributes = new ArrayList (); 556 } 557 else 558 { 559 criteria.add(AttributePeer.ATTRIBUTE_TYPE_ID, getAttributeTypeId() ); 560 collAttributes = AttributePeer.doSelectJoinScarabUserImpl(criteria); 561 } 562 } 563 else 564 { 565 569 criteria.add(AttributePeer.ATTRIBUTE_TYPE_ID, getAttributeTypeId() ); 570 if (!lastAttributesCriteria.equals(criteria)) 571 { 572 collAttributes = AttributePeer.doSelectJoinScarabUserImpl(criteria); 573 } 574 } 575 lastAttributesCriteria = criteria; 576 577 return collAttributes; 578 } 579 580 581 582 583 private static List fieldNames = null; 584 585 590 public static synchronized List getFieldNames() 591 { 592 if (fieldNames == null) 593 { 594 fieldNames = new ArrayList (); 595 fieldNames.add("AttributeTypeId"); 596 fieldNames.add("ClassId"); 597 fieldNames.add("Name"); 598 fieldNames.add("JavaClassName"); 599 fieldNames.add("ValidationKey"); 600 fieldNames = Collections.unmodifiableList(fieldNames); 601 } 602 return fieldNames; 603 } 604 605 611 public Object getByName(String name) 612 { 613 if (name.equals("AttributeTypeId")) 614 { 615 return getAttributeTypeId(); 616 } 617 if (name.equals("ClassId")) 618 { 619 return getClassId(); 620 } 621 if (name.equals("Name")) 622 { 623 return getName(); 624 } 625 if (name.equals("JavaClassName")) 626 { 627 return getJavaClassName(); 628 } 629 if (name.equals("ValidationKey")) 630 { 631 return getValidationKey(); 632 } 633 return null; 634 } 635 636 644 public Object getByPeerName(String name) 645 { 646 if (name.equals(AttributeTypePeer.ATTRIBUTE_TYPE_ID)) 647 { 648 return getAttributeTypeId(); 649 } 650 if (name.equals(AttributeTypePeer.ATTRIBUTE_CLASS_ID)) 651 { 652 return getClassId(); 653 } 654 if (name.equals(AttributeTypePeer.ATTRIBUTE_TYPE_NAME)) 655 { 656 return getName(); 657 } 658 if (name.equals(AttributeTypePeer.JAVA_CLASS_NAME)) 659 { 660 return getJavaClassName(); 661 } 662 if (name.equals(AttributeTypePeer.VALIDATION_KEY)) 663 { 664 return getValidationKey(); 665 } 666 return null; 667 } 668 669 676 public Object getByPosition(int pos) 677 { 678 if (pos == 0) 679 { 680 return getAttributeTypeId(); 681 } 682 if (pos == 1) 683 { 684 return getClassId(); 685 } 686 if (pos == 2) 687 { 688 return getName(); 689 } 690 if (pos == 3) 691 { 692 return getJavaClassName(); 693 } 694 if (pos == 4) 695 { 696 return getValidationKey(); 697 } 698 return null; 699 } 700 701 707 public void save() throws Exception 708 { 709 save(AttributeTypePeer.getMapBuilder() 710 .getDatabaseMap().getName()); 711 } 712 713 723 public void save(String dbName) throws TorqueException 724 { 725 Connection con = null; 726 try 727 { 728 con = Transaction.begin(dbName); 729 save(con); 730 Transaction.commit(con); 731 } 732 catch(TorqueException e) 733 { 734 Transaction.safeRollback(con); 735 throw e; 736 } 737 } 738 739 741 private boolean alreadyInSave = false; 742 752 public void save(Connection con) throws TorqueException 753 { 754 if (!alreadyInSave) 755 { 756 alreadyInSave = true; 757 758 759 760 if (isModified()) 762 { 763 if (isNew()) 764 { 765 AttributeTypePeer.doInsert((AttributeType)this, con); 766 setNew(false); 767 } 768 else 769 { 770 AttributeTypePeer.doUpdate((AttributeType)this, con); 771 } 772 773 if (isCacheOnSave()) 774 { 775 AttributeTypeManager.putInstance(this); 776 } 777 } 778 779 780 if (collAttributes != null) 781 { 782 for (int i = 0; i < collAttributes.size(); i++) 783 { 784 ((Attribute)collAttributes.get(i)).save(con); 785 } 786 } 787 alreadyInSave = false; 788 } 789 } 790 791 795 protected boolean isCacheOnSave() 796 { 797 return true; 798 } 799 800 801 806 public void setPrimaryKey(ObjectKey attributeTypeId) 807 throws TorqueException { 808 setAttributeTypeId(new Integer (((NumberKey)attributeTypeId).intValue())); 809 } 810 811 816 public void setPrimaryKey(String key) throws TorqueException 817 { 818 setAttributeTypeId(new Integer (key)); 819 } 820 821 822 826 public ObjectKey getPrimaryKey() 827 { 828 return SimpleKey.keyFor(getAttributeTypeId()); 829 } 830 831 835 public String getQueryKey() 836 { 837 if (getPrimaryKey() == null) 838 { 839 return ""; 840 } 841 else 842 { 843 return getPrimaryKey().toString(); 844 } 845 } 846 847 851 public void setQueryKey(String key) 852 throws TorqueException 853 { 854 setPrimaryKey(key); 855 } 856 857 863 public AttributeType copy() throws TorqueException 864 { 865 AttributeType copyObj = new AttributeType(); 866 copyObj.setAttributeTypeId(attributeTypeId); 867 copyObj.setClassId(classId); 868 copyObj.setName(name); 869 copyObj.setJavaClassName(javaClassName); 870 copyObj.setValidationKey(validationKey); 871 872 copyObj.setAttributeTypeId((Integer )null); 873 874 875 876 List v = getAttributes(); 877 for (int i = 0; i < v.size(); i++) 878 { 879 Attribute obj = (Attribute) v.get(i); 880 copyObj.addAttribute(obj.copy()); 881 } 882 return copyObj; 883 } 884 885 891 public AttributeTypePeer getPeer() 892 { 893 return peer; 894 } 895 896 public String toString() 897 { 898 StringBuffer str = new StringBuffer (); 899 str.append("AttributeType:\n"); 900 str.append("AttributeTypeId = ") 901 .append(getAttributeTypeId()) 902 .append("\n"); 903 str.append("ClassId = ") 904 .append(getClassId()) 905 .append("\n"); 906 str.append("Name = ") 907 .append(getName()) 908 .append("\n"); 909 str.append("JavaClassName = ") 910 .append(getJavaClassName()) 911 .append("\n"); 912 str.append("ValidationKey = ") 913 .append(getValidationKey()) 914 .append("\n"); 915 return(str.toString()); 916 } 917 } 918 | Popular Tags |