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 34 public abstract class BaseUom extends BaseObject 35 implements org.apache.turbine.om.Retrievable 36 { 37 38 private static final UomPeer peer = 39 new UomPeer(); 40 41 42 43 private int uomId; 44 45 46 private String uomName; 47 48 49 private String uomCode; 50 51 52 57 public int getUomId() 58 { 59 return uomId; 60 } 61 62 63 68 public void setUomId(int v) throws TorqueException 69 { 70 71 if (this.uomId != v) 72 { 73 this.uomId = v; 74 setModified(true); 75 } 76 77 78 79 if (collProducts != null) 81 { 82 for (int i = 0; i < collProducts.size(); i++) 83 { 84 ((Product) collProducts.get(i)) 85 .setUomId(v); 86 } 87 } 88 } 89 90 95 public String getUomName() 96 { 97 return uomName; 98 } 99 100 101 106 public void setUomName(String v) 107 { 108 109 if (!ObjectUtils.equals(this.uomName, v)) 110 { 111 this.uomName = v; 112 setModified(true); 113 } 114 115 116 } 117 118 123 public String getUomCode() 124 { 125 return uomCode; 126 } 127 128 129 134 public void setUomCode(String v) 135 { 136 137 if (!ObjectUtils.equals(this.uomCode, v)) 138 { 139 this.uomCode = v; 140 setModified(true); 141 } 142 143 144 } 145 146 147 148 149 152 protected List collProducts; 153 154 159 protected void initProducts() 160 { 161 if (collProducts == null) 162 { 163 collProducts = new ArrayList (); 164 } 165 } 166 167 174 public void addProduct(Product l) throws TorqueException 175 { 176 getProducts().add(l); 177 l.setUom((Uom) this); 178 } 179 180 183 private Criteria lastProductsCriteria = null; 184 185 192 public List getProducts() throws TorqueException 193 { 194 if (collProducts == null) 195 { 196 collProducts = getProducts(new Criteria(10)); 197 } 198 return collProducts; 199 } 200 201 212 public List getProducts(Criteria criteria) throws TorqueException 213 { 214 if (collProducts == null) 215 { 216 if (isNew()) 217 { 218 collProducts = new ArrayList (); 219 } 220 else 221 { 222 criteria.add(ProductPeer.UOM_ID, getUomId() ); 223 collProducts = ProductPeer.doSelect(criteria); 224 } 225 } 226 else 227 { 228 if (!isNew()) 230 { 231 criteria.add(ProductPeer.UOM_ID, getUomId()); 235 if (!lastProductsCriteria.equals(criteria)) 236 { 237 collProducts = ProductPeer.doSelect(criteria); 238 } 239 } 240 } 241 lastProductsCriteria = criteria; 242 243 return collProducts; 244 } 245 246 254 public List getProducts(Connection con) throws TorqueException 255 { 256 if (collProducts == null) 257 { 258 collProducts = getProducts(new Criteria(10), con); 259 } 260 return collProducts; 261 } 262 263 275 public List getProducts(Criteria criteria, Connection con) 276 throws TorqueException 277 { 278 if (collProducts == null) 279 { 280 if (isNew()) 281 { 282 collProducts = new ArrayList (); 283 } 284 else 285 { 286 criteria.add(ProductPeer.UOM_ID, getUomId()); 287 collProducts = ProductPeer.doSelect(criteria, con); 288 } 289 } 290 else 291 { 292 if (!isNew()) 294 { 295 criteria.add(ProductPeer.UOM_ID, getUomId()); 299 if (!lastProductsCriteria.equals(criteria)) 300 { 301 collProducts = ProductPeer.doSelect(criteria, con); 302 } 303 } 304 } 305 lastProductsCriteria = criteria; 306 307 return collProducts; 308 } 309 310 311 312 313 314 315 316 317 318 319 320 331 protected List getProductsJoinProductCategory(Criteria criteria) 332 throws TorqueException 333 { 334 if (collProducts == null) 335 { 336 if (isNew()) 337 { 338 collProducts = new ArrayList (); 339 } 340 else 341 { 342 criteria.add(ProductPeer.UOM_ID, getUomId()); 343 collProducts = ProductPeer.doSelectJoinProductCategory(criteria); 344 } 345 } 346 else 347 { 348 352 criteria.add(ProductPeer.UOM_ID, getUomId()); 353 if (!lastProductsCriteria.equals(criteria)) 354 { 355 collProducts = ProductPeer.doSelectJoinProductCategory(criteria); 356 } 357 } 358 lastProductsCriteria = criteria; 359 360 return collProducts; 361 } 362 363 364 365 366 367 368 369 370 371 382 protected List getProductsJoinUom(Criteria criteria) 383 throws TorqueException 384 { 385 if (collProducts == null) 386 { 387 if (isNew()) 388 { 389 collProducts = new ArrayList (); 390 } 391 else 392 { 393 criteria.add(ProductPeer.UOM_ID, getUomId()); 394 collProducts = ProductPeer.doSelectJoinUom(criteria); 395 } 396 } 397 else 398 { 399 403 criteria.add(ProductPeer.UOM_ID, getUomId()); 404 if (!lastProductsCriteria.equals(criteria)) 405 { 406 collProducts = ProductPeer.doSelectJoinUom(criteria); 407 } 408 } 409 lastProductsCriteria = criteria; 410 411 return collProducts; 412 } 413 414 415 416 417 418 419 420 421 422 433 protected List getProductsJoinVendor(Criteria criteria) 434 throws TorqueException 435 { 436 if (collProducts == null) 437 { 438 if (isNew()) 439 { 440 collProducts = new ArrayList (); 441 } 442 else 443 { 444 criteria.add(ProductPeer.UOM_ID, getUomId()); 445 collProducts = ProductPeer.doSelectJoinVendor(criteria); 446 } 447 } 448 else 449 { 450 454 criteria.add(ProductPeer.UOM_ID, getUomId()); 455 if (!lastProductsCriteria.equals(criteria)) 456 { 457 collProducts = ProductPeer.doSelectJoinVendor(criteria); 458 } 459 } 460 lastProductsCriteria = criteria; 461 462 return collProducts; 463 } 464 465 466 467 468 private static List fieldNames = null; 469 470 475 public static synchronized List getFieldNames() 476 { 477 if (fieldNames == null) 478 { 479 fieldNames = new ArrayList (); 480 fieldNames.add("UomId"); 481 fieldNames.add("UomName"); 482 fieldNames.add("UomCode"); 483 fieldNames = Collections.unmodifiableList(fieldNames); 484 } 485 return fieldNames; 486 } 487 488 494 public Object getByName(String name) 495 { 496 if (name.equals("UomId")) 497 { 498 return new Integer (getUomId()); 499 } 500 if (name.equals("UomName")) 501 { 502 return getUomName(); 503 } 504 if (name.equals("UomCode")) 505 { 506 return getUomCode(); 507 } 508 return null; 509 } 510 511 519 public Object getByPeerName(String name) 520 { 521 if (name.equals(UomPeer.UOM_ID)) 522 { 523 return new Integer (getUomId()); 524 } 525 if (name.equals(UomPeer.UOM_NAME)) 526 { 527 return getUomName(); 528 } 529 if (name.equals(UomPeer.UOM_CODE)) 530 { 531 return getUomCode(); 532 } 533 return null; 534 } 535 536 543 public Object getByPosition(int pos) 544 { 545 if (pos == 0) 546 { 547 return new Integer (getUomId()); 548 } 549 if (pos == 1) 550 { 551 return getUomName(); 552 } 553 if (pos == 2) 554 { 555 return getUomCode(); 556 } 557 return null; 558 } 559 560 566 public void save() throws Exception  567 { 568 save(UomPeer.getMapBuilder() 569 .getDatabaseMap().getName()); 570 } 571 572 582 public void save(String dbName) throws TorqueException 583 { 584 Connection con = null; 585 try 586 { 587 con = Transaction.begin(dbName); 588 save(con); 589 Transaction.commit(con); 590 } 591 catch(TorqueException e) 592 { 593 Transaction.safeRollback(con); 594 throw e; 595 } 596 } 597 598 600 private boolean alreadyInSave = false; 601 611 public void save(Connection con) throws TorqueException 612 { 613 if (!alreadyInSave) 614 { 615 alreadyInSave = true; 616 617 618 619 if (isModified()) 621 { 622 if (isNew()) 623 { 624 UomPeer.doInsert((Uom) this, con); 625 setNew(false); 626 } 627 else 628 { 629 UomPeer.doUpdate((Uom) this, con); 630 } 631 } 632 633 634 635 if (collProducts != null) 636 { 637 for (int i = 0; i < collProducts.size(); i++) 638 { 639 ((Product) collProducts.get(i)).save(con); 640 } 641 } 642 alreadyInSave = false; 643 } 644 } 645 646 647 652 public void setPrimaryKey(ObjectKey key) 653 throws TorqueException 654 { 655 setUomId(((NumberKey) key).intValue()); 656 } 657 658 663 public void setPrimaryKey(String key) throws TorqueException 664 { 665 setUomId(Integer.parseInt(key)); 666 } 667 668 669 673 public ObjectKey getPrimaryKey() 674 { 675 return SimpleKey.keyFor(getUomId()); 676 } 677 678 682 public String getQueryKey() 683 { 684 if (getPrimaryKey() == null) 685 { 686 return ""; 687 } 688 else 689 { 690 return getPrimaryKey().toString(); 691 } 692 } 693 694 698 public void setQueryKey(String key) 699 throws TorqueException 700 { 701 setPrimaryKey(key); 702 } 703 704 710 public Uom copy() throws TorqueException 711 { 712 return copyInto(new Uom()); 713 } 714 715 protected Uom copyInto(Uom copyObj) throws TorqueException 716 { 717 copyObj.setUomId(uomId); 718 copyObj.setUomName(uomName); 719 copyObj.setUomCode(uomCode); 720 721 copyObj.setUomId( 0); 722 723 724 725 List v = getProducts(); 726 for (int i = 0; i < v.size(); i++) 727 { 728 Product obj = (Product) v.get(i); 729 copyObj.addProduct(obj.copy()); 730 } 731 return copyObj; 732 } 733 734 740 public UomPeer getPeer() 741 { 742 return peer; 743 } 744 745 public String toString() 746 { 747 StringBuffer str = new StringBuffer (); 748 str.append("Uom:\n"); 749 str.append("UomId = ") 750 .append(getUomId()) 751 .append("\n"); 752 str.append("UomName = ") 753 .append(getUomName()) 754 .append("\n"); 755 str.append("UomCode = ") 756 .append(getUomCode()) 757 .append("\n"); 758 return(str.toString()); 759 } 760 } 761
| Popular Tags
|