1 package org.campware.cream.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.turbine.om.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 31 32 40 public abstract class BaseSorderItem extends BaseObject 41 implements org.apache.turbine.om.Retrievable 42 { 43 44 private static final SorderItemPeer peer = 45 new SorderItemPeer(); 46 47 48 49 private int sorderItemId; 50 51 52 private int sorderId = 1000; 53 54 55 private int customerId = 1000; 56 57 58 private int recipientId = 1000; 59 60 61 private int projectId = 1000; 62 63 64 private int productId = 1000; 65 66 67 private String description; 68 69 70 private BigDecimal unitPrice= new BigDecimal (0); 71 72 73 private int currencyId = 1000; 74 75 76 private int quantity = 1; 77 78 79 private BigDecimal itemCurrTotal= new BigDecimal (0); 80 81 82 87 public int getSorderItemId() 88 { 89 return sorderItemId; 90 } 91 92 93 98 public void setSorderItemId(int v) 99 { 100 101 if (this.sorderItemId != v) 102 { 103 this.sorderItemId = v; 104 setModified(true); 105 } 106 107 108 } 109 110 115 public int getSorderId() 116 { 117 return sorderId; 118 } 119 120 121 126 public void setSorderId(int v) throws TorqueException 127 { 128 129 if (this.sorderId != v) 130 { 131 this.sorderId = v; 132 setModified(true); 133 } 134 135 136 if (aSorder != null && !(aSorder.getSorderId() == v)) 137 { 138 aSorder = null; 139 } 140 141 } 142 143 148 public int getCustomerId() 149 { 150 return customerId; 151 } 152 153 154 159 public void setCustomerId(int v) throws TorqueException 160 { 161 162 if (this.customerId != v) 163 { 164 this.customerId = v; 165 setModified(true); 166 } 167 168 169 if (aCustomerRelatedByCustomerId != null && !(aCustomerRelatedByCustomerId.getCustomerId() == v)) 170 { 171 aCustomerRelatedByCustomerId = null; 172 } 173 174 } 175 176 181 public int getRecipientId() 182 { 183 return recipientId; 184 } 185 186 187 192 public void setRecipientId(int v) throws TorqueException 193 { 194 195 if (this.recipientId != v) 196 { 197 this.recipientId = v; 198 setModified(true); 199 } 200 201 202 if (aCustomerRelatedByRecipientId != null && !(aCustomerRelatedByRecipientId.getCustomerId() == v)) 203 { 204 aCustomerRelatedByRecipientId = null; 205 } 206 207 } 208 209 214 public int getProjectId() 215 { 216 return projectId; 217 } 218 219 220 225 public void setProjectId(int v) throws TorqueException 226 { 227 228 if (this.projectId != v) 229 { 230 this.projectId = v; 231 setModified(true); 232 } 233 234 235 if (aProject != null && !(aProject.getProjectId() == v)) 236 { 237 aProject = null; 238 } 239 240 } 241 242 247 public int getProductId() 248 { 249 return productId; 250 } 251 252 253 258 public void setProductId(int v) throws TorqueException 259 { 260 261 if (this.productId != v) 262 { 263 this.productId = v; 264 setModified(true); 265 } 266 267 268 if (aProduct != null && !(aProduct.getProductId() == v)) 269 { 270 aProduct = null; 271 } 272 273 } 274 275 280 public String getDescription() 281 { 282 return description; 283 } 284 285 286 291 public void setDescription(String v) 292 { 293 294 if (!ObjectUtils.equals(this.description, v)) 295 { 296 this.description = v; 297 setModified(true); 298 } 299 300 301 } 302 303 308 public BigDecimal getUnitPrice() 309 { 310 return unitPrice; 311 } 312 313 314 319 public void setUnitPrice(BigDecimal v) 320 { 321 322 if (!ObjectUtils.equals(this.unitPrice, v)) 323 { 324 this.unitPrice = v; 325 setModified(true); 326 } 327 328 329 } 330 331 336 public int getCurrencyId() 337 { 338 return currencyId; 339 } 340 341 342 347 public void setCurrencyId(int v) throws TorqueException 348 { 349 350 if (this.currencyId != v) 351 { 352 this.currencyId = v; 353 setModified(true); 354 } 355 356 357 if (aCurrency != null && !(aCurrency.getCurrencyId() == v)) 358 { 359 aCurrency = null; 360 } 361 362 } 363 364 369 public int getQuantity() 370 { 371 return quantity; 372 } 373 374 375 380 public void setQuantity(int v) 381 { 382 383 if (this.quantity != v) 384 { 385 this.quantity = v; 386 setModified(true); 387 } 388 389 390 } 391 392 397 public BigDecimal getItemCurrTotal() 398 { 399 return itemCurrTotal; 400 } 401 402 403 408 public void setItemCurrTotal(BigDecimal v) 409 { 410 411 if (!ObjectUtils.equals(this.itemCurrTotal, v)) 412 { 413 this.itemCurrTotal = v; 414 setModified(true); 415 } 416 417 418 } 419 420 421 422 423 424 private Sorder aSorder; 425 426 432 public void setSorder(Sorder v) throws TorqueException 433 { 434 if (v == null) 435 { 436 setSorderId( 1000); 437 } 438 else 439 { 440 setSorderId(v.getSorderId()); 441 } 442 aSorder = v; 443 } 444 445 446 452 public Sorder getSorder() throws TorqueException 453 { 454 if (aSorder == null && (this.sorderId != 0)) 455 { 456 aSorder = SorderPeer.retrieveByPK(SimpleKey.keyFor(this.sorderId)); 457 458 467 } 468 return aSorder; 469 } 470 471 477 public void setSorderKey(ObjectKey key) throws TorqueException 478 { 479 480 setSorderId(((NumberKey) key).intValue()); 481 } 482 483 484 485 486 private Product aProduct; 487 488 494 public void setProduct(Product v) throws TorqueException 495 { 496 if (v == null) 497 { 498 setProductId( 1000); 499 } 500 else 501 { 502 setProductId(v.getProductId()); 503 } 504 aProduct = v; 505 } 506 507 508 514 public Product getProduct() throws TorqueException 515 { 516 if (aProduct == null && (this.productId != 0)) 517 { 518 aProduct = ProductPeer.retrieveByPK(SimpleKey.keyFor(this.productId)); 519 520 529 } 530 return aProduct; 531 } 532 533 539 public void setProductKey(ObjectKey key) throws TorqueException 540 { 541 542 setProductId(((NumberKey) key).intValue()); 543 } 544 545 546 547 548 private Customer aCustomerRelatedByCustomerId; 549 550 556 public void setCustomerRelatedByCustomerId(Customer v) throws TorqueException 557 { 558 if (v == null) 559 { 560 setCustomerId( 1000); 561 } 562 else 563 { 564 setCustomerId(v.getCustomerId()); 565 } 566 aCustomerRelatedByCustomerId = v; 567 } 568 569 570 576 public Customer getCustomerRelatedByCustomerId() throws TorqueException 577 { 578 if (aCustomerRelatedByCustomerId == null && (this.customerId != 0)) 579 { 580 aCustomerRelatedByCustomerId = CustomerPeer.retrieveByPK(SimpleKey.keyFor(this.customerId)); 581 582 591 } 592 return aCustomerRelatedByCustomerId; 593 } 594 595 601 public void setCustomerRelatedByCustomerIdKey(ObjectKey key) throws TorqueException 602 { 603 604 setCustomerId(((NumberKey) key).intValue()); 605 } 606 607 608 609 610 private Customer aCustomerRelatedByRecipientId; 611 612 618 public void setCustomerRelatedByRecipientId(Customer v) throws TorqueException 619 { 620 if (v == null) 621 { 622 setRecipientId( 1000); 623 } 624 else 625 { 626 setRecipientId(v.getCustomerId()); 627 } 628 aCustomerRelatedByRecipientId = v; 629 } 630 631 632 638 public Customer getCustomerRelatedByRecipientId() throws TorqueException 639 { 640 if (aCustomerRelatedByRecipientId == null && (this.recipientId != 0)) 641 { 642 aCustomerRelatedByRecipientId = CustomerPeer.retrieveByPK(SimpleKey.keyFor(this.recipientId)); 643 644 653 } 654 return aCustomerRelatedByRecipientId; 655 } 656 657 663 public void setCustomerRelatedByRecipientIdKey(ObjectKey key) throws TorqueException 664 { 665 666 setRecipientId(((NumberKey) key).intValue()); 667 } 668 669 670 671 672 private Project aProject; 673 674 680 public void setProject(Project v) throws TorqueException 681 { 682 if (v == null) 683 { 684 setProjectId( 1000); 685 } 686 else 687 { 688 setProjectId(v.getProjectId()); 689 } 690 aProject = v; 691 } 692 693 694 700 public Project getProject() throws TorqueException 701 { 702 if (aProject == null && (this.projectId != 0)) 703 { 704 aProject = ProjectPeer.retrieveByPK(SimpleKey.keyFor(this.projectId)); 705 706 715 } 716 return aProject; 717 } 718 719 725 public void setProjectKey(ObjectKey key) throws TorqueException 726 { 727 728 setProjectId(((NumberKey) key).intValue()); 729 } 730 731 732 733 734 private Currency aCurrency; 735 736 742 public void setCurrency(Currency v) throws TorqueException 743 { 744 if (v == null) 745 { 746 setCurrencyId( 1000); 747 } 748 else 749 { 750 setCurrencyId(v.getCurrencyId()); 751 } 752 aCurrency = v; 753 } 754 755 756 762 public Currency getCurrency() throws TorqueException 763 { 764 if (aCurrency == null && (this.currencyId != 0)) 765 { 766 aCurrency = CurrencyPeer.retrieveByPK(SimpleKey.keyFor(this.currencyId)); 767 768 777 } 778 return aCurrency; 779 } 780 781 787 public void setCurrencyKey(ObjectKey key) throws TorqueException 788 { 789 790 setCurrencyId(((NumberKey) key).intValue()); 791 } 792 793 794 private static List fieldNames = null; 795 796 801 public static synchronized List getFieldNames() 802 { 803 if (fieldNames == null) 804 { 805 fieldNames = new ArrayList (); 806 fieldNames.add("SorderItemId"); 807 fieldNames.add("SorderId"); 808 fieldNames.add("CustomerId"); 809 fieldNames.add("RecipientId"); 810 fieldNames.add("ProjectId"); 811 fieldNames.add("ProductId"); 812 fieldNames.add("Description"); 813 fieldNames.add("UnitPrice"); 814 fieldNames.add("CurrencyId"); 815 fieldNames.add("Quantity"); 816 fieldNames.add("ItemCurrTotal"); 817 fieldNames = Collections.unmodifiableList(fieldNames); 818 } 819 return fieldNames; 820 } 821 822 828 public Object getByName(String name) 829 { 830 if (name.equals("SorderItemId")) 831 { 832 return new Integer (getSorderItemId()); 833 } 834 if (name.equals("SorderId")) 835 { 836 return new Integer (getSorderId()); 837 } 838 if (name.equals("CustomerId")) 839 { 840 return new Integer (getCustomerId()); 841 } 842 if (name.equals("RecipientId")) 843 { 844 return new Integer (getRecipientId()); 845 } 846 if (name.equals("ProjectId")) 847 { 848 return new Integer (getProjectId()); 849 } 850 if (name.equals("ProductId")) 851 { 852 return new Integer (getProductId()); 853 } 854 if (name.equals("Description")) 855 { 856 return getDescription(); 857 } 858 if (name.equals("UnitPrice")) 859 { 860 return getUnitPrice(); 861 } 862 if (name.equals("CurrencyId")) 863 { 864 return new Integer (getCurrencyId()); 865 } 866 if (name.equals("Quantity")) 867 { 868 return new Integer (getQuantity()); 869 } 870 if (name.equals("ItemCurrTotal")) 871 { 872 return getItemCurrTotal(); 873 } 874 return null; 875 } 876 877 885 public Object getByPeerName(String name) 886 { 887 if (name.equals(SorderItemPeer.SORDER_ITEM_ID)) 888 { 889 return new Integer (getSorderItemId()); 890 } 891 if (name.equals(SorderItemPeer.SORDER_ID)) 892 { 893 return new Integer (getSorderId()); 894 } 895 if (name.equals(SorderItemPeer.CUSTOMER_ID)) 896 { 897 return new Integer (getCustomerId()); 898 } 899 if (name.equals(SorderItemPeer.RECIPIENT_ID)) 900 { 901 return new Integer (getRecipientId()); 902 } 903 if (name.equals(SorderItemPeer.PROJECT_ID)) 904 { 905 return new Integer (getProjectId()); 906 } 907 if (name.equals(SorderItemPeer.PRODUCT_ID)) 908 { 909 return new Integer (getProductId()); 910 } 911 if (name.equals(SorderItemPeer.DESCRIPTION)) 912 { 913 return getDescription(); 914 } 915 if (name.equals(SorderItemPeer.UNIT_PRICE)) 916 { 917 return getUnitPrice(); 918 } 919 if (name.equals(SorderItemPeer.CURRENCY_ID)) 920 { 921 return new Integer (getCurrencyId()); 922 } 923 if (name.equals(SorderItemPeer.QUANTITY)) 924 { 925 return new Integer (getQuantity()); 926 } 927 if (name.equals(SorderItemPeer.ITEM_CURR_TOTAL)) 928 { 929 return getItemCurrTotal(); 930 } 931 return null; 932 } 933 934 941 public Object getByPosition(int pos) 942 { 943 if (pos == 0) 944 { 945 return new Integer (getSorderItemId()); 946 } 947 if (pos == 1) 948 { 949 return new Integer (getSorderId()); 950 } 951 if (pos == 2) 952 { 953 return new Integer (getCustomerId()); 954 } 955 if (pos == 3) 956 { 957 return new Integer (getRecipientId()); 958 } 959 if (pos == 4) 960 { 961 return new Integer (getProjectId()); 962 } 963 if (pos == 5) 964 { 965 return new Integer (getProductId()); 966 } 967 if (pos == 6) 968 { 969 return getDescription(); 970 } 971 if (pos == 7) 972 { 973 return getUnitPrice(); 974 } 975 if (pos == 8) 976 { 977 return new Integer (getCurrencyId()); 978 } 979 if (pos == 9) 980 { 981 return new Integer (getQuantity()); 982 } 983 if (pos == 10) 984 { 985 return getItemCurrTotal(); 986 } 987 return null; 988 } 989 990 996 public void save() throws Exception  997 { 998 save(SorderItemPeer.getMapBuilder() 999 .getDatabaseMap().getName()); 1000 } 1001 1002 1012 public void save(String dbName) throws TorqueException 1013 { 1014 Connection con = null; 1015 try 1016 { 1017 con = Transaction.begin(dbName); 1018 save(con); 1019 Transaction.commit(con); 1020 } 1021 catch(TorqueException e) 1022 { 1023 Transaction.safeRollback(con); 1024 throw e; 1025 } 1026 } 1027 1028 1030 private boolean alreadyInSave = false; 1031 1041 public void save(Connection con) throws TorqueException 1042 { 1043 if (!alreadyInSave) 1044 { 1045 alreadyInSave = true; 1046 1047 1048 1049 if (isModified()) 1051 { 1052 if (isNew()) 1053 { 1054 SorderItemPeer.doInsert((SorderItem) this, con); 1055 setNew(false); 1056 } 1057 else 1058 { 1059 SorderItemPeer.doUpdate((SorderItem) this, con); 1060 } 1061 } 1062 1063 alreadyInSave = false; 1064 } 1065 } 1066 1067 1068 1073 public void setPrimaryKey(ObjectKey key) 1074 1075 { 1076 setSorderItemId(((NumberKey) key).intValue()); 1077 } 1078 1079 1084 public void setPrimaryKey(String key) 1085 { 1086 setSorderItemId(Integer.parseInt(key)); 1087 } 1088 1089 1090 1094 public ObjectKey getPrimaryKey() 1095 { 1096 return SimpleKey.keyFor(getSorderItemId()); 1097 } 1098 1099 1103 public String getQueryKey() 1104 { 1105 if (getPrimaryKey() == null) 1106 { 1107 return ""; 1108 } 1109 else 1110 { 1111 return getPrimaryKey().toString(); 1112 } 1113 } 1114 1115 1119 public void setQueryKey(String key) 1120 throws TorqueException 1121 { 1122 setPrimaryKey(key); 1123 } 1124 1125 1131 public SorderItem copy() throws TorqueException 1132 { 1133 return copyInto(new SorderItem()); 1134 } 1135 1136 protected SorderItem copyInto(SorderItem copyObj) throws TorqueException 1137 { 1138 copyObj.setSorderItemId(sorderItemId); 1139 copyObj.setSorderId(sorderId); 1140 copyObj.setCustomerId(customerId); 1141 copyObj.setRecipientId(recipientId); 1142 copyObj.setProjectId(projectId); 1143 copyObj.setProductId(productId); 1144 copyObj.setDescription(description); 1145 copyObj.setUnitPrice(unitPrice); 1146 copyObj.setCurrencyId(currencyId); 1147 copyObj.setQuantity(quantity); 1148 copyObj.setItemCurrTotal(itemCurrTotal); 1149 1150 copyObj.setSorderItemId( 0); 1151 1152 return copyObj; 1153 } 1154 1155 1161 public SorderItemPeer getPeer() 1162 { 1163 return peer; 1164 } 1165 1166 public String toString() 1167 { 1168 StringBuffer str = new StringBuffer (); 1169 str.append("SorderItem:\n"); 1170 str.append("SorderItemId = ") 1171 .append(getSorderItemId()) 1172 .append("\n"); 1173 str.append("SorderId = ") 1174 .append(getSorderId()) 1175 .append("\n"); 1176 str.append("CustomerId = ") 1177 .append(getCustomerId()) 1178 .append("\n"); 1179 str.append("RecipientId = ") 1180 .append(getRecipientId()) 1181 .append("\n"); 1182 str.append("ProjectId = ") 1183 .append(getProjectId()) 1184 .append("\n"); 1185 str.append("ProductId = ") 1186 .append(getProductId()) 1187 .append("\n"); 1188 str.append("Description = ") 1189 .append(getDescription()) 1190 .append("\n"); 1191 str.append("UnitPrice = ") 1192 .append(getUnitPrice()) 1193 .append("\n"); 1194 str.append("CurrencyId = ") 1195 .append(getCurrencyId()) 1196 .append("\n"); 1197 str.append("Quantity = ") 1198 .append(getQuantity()) 1199 .append("\n"); 1200 str.append("ItemCurrTotal = ") 1201 .append(getItemCurrTotal()) 1202 .append("\n"); 1203 return(str.toString()); 1204 } 1205} 1206
| Popular Tags
|