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 BaseProductCategory extends BaseObject 35 implements org.apache.turbine.om.Retrievable 36 { 37 38 private static final ProductCategoryPeer peer = 39 new ProductCategoryPeer(); 40 41 42 43 private int productCatId; 44 45 46 private String productCatName; 47 48 49 54 public int getProductCatId() 55 { 56 return productCatId; 57 } 58 59 60 65 public void setProductCatId(int v) throws TorqueException 66 { 67 68 if (this.productCatId != v) 69 { 70 this.productCatId = v; 71 setModified(true); 72 } 73 74 75 76 if (collProducts != null) 78 { 79 for (int i = 0; i < collProducts.size(); i++) 80 { 81 ((Product) collProducts.get(i)) 82 .setProductCatId(v); 83 } 84 } 85 } 86 87 92 public String getProductCatName() 93 { 94 return productCatName; 95 } 96 97 98 103 public void setProductCatName(String v) 104 { 105 106 if (!ObjectUtils.equals(this.productCatName, v)) 107 { 108 this.productCatName = v; 109 setModified(true); 110 } 111 112 113 } 114 115 116 117 118 121 protected List collProducts; 122 123 128 protected void initProducts() 129 { 130 if (collProducts == null) 131 { 132 collProducts = new ArrayList (); 133 } 134 } 135 136 143 public void addProduct(Product l) throws TorqueException 144 { 145 getProducts().add(l); 146 l.setProductCategory((ProductCategory) this); 147 } 148 149 152 private Criteria lastProductsCriteria = null; 153 154 161 public List getProducts() throws TorqueException 162 { 163 if (collProducts == null) 164 { 165 collProducts = getProducts(new Criteria(10)); 166 } 167 return collProducts; 168 } 169 170 181 public List getProducts(Criteria criteria) throws TorqueException 182 { 183 if (collProducts == null) 184 { 185 if (isNew()) 186 { 187 collProducts = new ArrayList (); 188 } 189 else 190 { 191 criteria.add(ProductPeer.PRODUCT_CAT_ID, getProductCatId() ); 192 collProducts = ProductPeer.doSelect(criteria); 193 } 194 } 195 else 196 { 197 if (!isNew()) 199 { 200 criteria.add(ProductPeer.PRODUCT_CAT_ID, getProductCatId()); 204 if (!lastProductsCriteria.equals(criteria)) 205 { 206 collProducts = ProductPeer.doSelect(criteria); 207 } 208 } 209 } 210 lastProductsCriteria = criteria; 211 212 return collProducts; 213 } 214 215 223 public List getProducts(Connection con) throws TorqueException 224 { 225 if (collProducts == null) 226 { 227 collProducts = getProducts(new Criteria(10), con); 228 } 229 return collProducts; 230 } 231 232 244 public List getProducts(Criteria criteria, Connection con) 245 throws TorqueException 246 { 247 if (collProducts == null) 248 { 249 if (isNew()) 250 { 251 collProducts = new ArrayList (); 252 } 253 else 254 { 255 criteria.add(ProductPeer.PRODUCT_CAT_ID, getProductCatId()); 256 collProducts = ProductPeer.doSelect(criteria, con); 257 } 258 } 259 else 260 { 261 if (!isNew()) 263 { 264 criteria.add(ProductPeer.PRODUCT_CAT_ID, getProductCatId()); 268 if (!lastProductsCriteria.equals(criteria)) 269 { 270 collProducts = ProductPeer.doSelect(criteria, con); 271 } 272 } 273 } 274 lastProductsCriteria = criteria; 275 276 return collProducts; 277 } 278 279 280 281 282 283 284 285 286 287 288 289 300 protected List getProductsJoinProductCategory(Criteria criteria) 301 throws TorqueException 302 { 303 if (collProducts == null) 304 { 305 if (isNew()) 306 { 307 collProducts = new ArrayList (); 308 } 309 else 310 { 311 criteria.add(ProductPeer.PRODUCT_CAT_ID, getProductCatId()); 312 collProducts = ProductPeer.doSelectJoinProductCategory(criteria); 313 } 314 } 315 else 316 { 317 321 criteria.add(ProductPeer.PRODUCT_CAT_ID, getProductCatId()); 322 if (!lastProductsCriteria.equals(criteria)) 323 { 324 collProducts = ProductPeer.doSelectJoinProductCategory(criteria); 325 } 326 } 327 lastProductsCriteria = criteria; 328 329 return collProducts; 330 } 331 332 333 334 335 336 337 338 339 340 351 protected List getProductsJoinUom(Criteria criteria) 352 throws TorqueException 353 { 354 if (collProducts == null) 355 { 356 if (isNew()) 357 { 358 collProducts = new ArrayList (); 359 } 360 else 361 { 362 criteria.add(ProductPeer.PRODUCT_CAT_ID, getProductCatId()); 363 collProducts = ProductPeer.doSelectJoinUom(criteria); 364 } 365 } 366 else 367 { 368 372 criteria.add(ProductPeer.PRODUCT_CAT_ID, getProductCatId()); 373 if (!lastProductsCriteria.equals(criteria)) 374 { 375 collProducts = ProductPeer.doSelectJoinUom(criteria); 376 } 377 } 378 lastProductsCriteria = criteria; 379 380 return collProducts; 381 } 382 383 384 385 386 387 388 389 390 391 402 protected List getProductsJoinVendor(Criteria criteria) 403 throws TorqueException 404 { 405 if (collProducts == null) 406 { 407 if (isNew()) 408 { 409 collProducts = new ArrayList (); 410 } 411 else 412 { 413 criteria.add(ProductPeer.PRODUCT_CAT_ID, getProductCatId()); 414 collProducts = ProductPeer.doSelectJoinVendor(criteria); 415 } 416 } 417 else 418 { 419 423 criteria.add(ProductPeer.PRODUCT_CAT_ID, getProductCatId()); 424 if (!lastProductsCriteria.equals(criteria)) 425 { 426 collProducts = ProductPeer.doSelectJoinVendor(criteria); 427 } 428 } 429 lastProductsCriteria = criteria; 430 431 return collProducts; 432 } 433 434 435 436 437 private static List fieldNames = null; 438 439 444 public static synchronized List getFieldNames() 445 { 446 if (fieldNames == null) 447 { 448 fieldNames = new ArrayList (); 449 fieldNames.add("ProductCatId"); 450 fieldNames.add("ProductCatName"); 451 fieldNames = Collections.unmodifiableList(fieldNames); 452 } 453 return fieldNames; 454 } 455 456 462 public Object getByName(String name) 463 { 464 if (name.equals("ProductCatId")) 465 { 466 return new Integer (getProductCatId()); 467 } 468 if (name.equals("ProductCatName")) 469 { 470 return getProductCatName(); 471 } 472 return null; 473 } 474 475 483 public Object getByPeerName(String name) 484 { 485 if (name.equals(ProductCategoryPeer.PRODUCT_CAT_ID)) 486 { 487 return new Integer (getProductCatId()); 488 } 489 if (name.equals(ProductCategoryPeer.PRODUCT_CAT_NAME)) 490 { 491 return getProductCatName(); 492 } 493 return null; 494 } 495 496 503 public Object getByPosition(int pos) 504 { 505 if (pos == 0) 506 { 507 return new Integer (getProductCatId()); 508 } 509 if (pos == 1) 510 { 511 return getProductCatName(); 512 } 513 return null; 514 } 515 516 522 public void save() throws Exception  523 { 524 save(ProductCategoryPeer.getMapBuilder() 525 .getDatabaseMap().getName()); 526 } 527 528 538 public void save(String dbName) throws TorqueException 539 { 540 Connection con = null; 541 try 542 { 543 con = Transaction.begin(dbName); 544 save(con); 545 Transaction.commit(con); 546 } 547 catch(TorqueException e) 548 { 549 Transaction.safeRollback(con); 550 throw e; 551 } 552 } 553 554 556 private boolean alreadyInSave = false; 557 567 public void save(Connection con) throws TorqueException 568 { 569 if (!alreadyInSave) 570 { 571 alreadyInSave = true; 572 573 574 575 if (isModified()) 577 { 578 if (isNew()) 579 { 580 ProductCategoryPeer.doInsert((ProductCategory) this, con); 581 setNew(false); 582 } 583 else 584 { 585 ProductCategoryPeer.doUpdate((ProductCategory) this, con); 586 } 587 } 588 589 590 591 if (collProducts != null) 592 { 593 for (int i = 0; i < collProducts.size(); i++) 594 { 595 ((Product) collProducts.get(i)).save(con); 596 } 597 } 598 alreadyInSave = false; 599 } 600 } 601 602 603 608 public void setPrimaryKey(ObjectKey key) 609 throws TorqueException 610 { 611 setProductCatId(((NumberKey) key).intValue()); 612 } 613 614 619 public void setPrimaryKey(String key) throws TorqueException 620 { 621 setProductCatId(Integer.parseInt(key)); 622 } 623 624 625 629 public ObjectKey getPrimaryKey() 630 { 631 return SimpleKey.keyFor(getProductCatId()); 632 } 633 634 638 public String getQueryKey() 639 { 640 if (getPrimaryKey() == null) 641 { 642 return ""; 643 } 644 else 645 { 646 return getPrimaryKey().toString(); 647 } 648 } 649 650 654 public void setQueryKey(String key) 655 throws TorqueException 656 { 657 setPrimaryKey(key); 658 } 659 660 666 public ProductCategory copy() throws TorqueException 667 { 668 return copyInto(new ProductCategory()); 669 } 670 671 protected ProductCategory copyInto(ProductCategory copyObj) throws TorqueException 672 { 673 copyObj.setProductCatId(productCatId); 674 copyObj.setProductCatName(productCatName); 675 676 copyObj.setProductCatId( 0); 677 678 679 680 List v = getProducts(); 681 for (int i = 0; i < v.size(); i++) 682 { 683 Product obj = (Product) v.get(i); 684 copyObj.addProduct(obj.copy()); 685 } 686 return copyObj; 687 } 688 689 695 public ProductCategoryPeer getPeer() 696 { 697 return peer; 698 } 699 700 public String toString() 701 { 702 StringBuffer str = new StringBuffer (); 703 str.append("ProductCategory:\n"); 704 str.append("ProductCatId = ") 705 .append(getProductCatId()) 706 .append("\n"); 707 str.append("ProductCatName = ") 708 .append(getProductCatName()) 709 .append("\n"); 710 return(str.toString()); 711 } 712 } 713
| Popular Tags
|