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 30 public abstract class BaseOptionRelationship extends BaseObject 31 implements org.apache.fulcrum.intake.Retrievable 32 { 33 34 private static final OptionRelationshipPeer peer = 35 new OptionRelationshipPeer(); 36 37 38 39 private Integer relationshipId; 40 41 42 private String name; 43 44 45 50 public Integer getRelationshipId() 51 { 52 return relationshipId; 53 } 54 55 56 61 public void setRelationshipId(Integer v) throws TorqueException 62 { 63 64 if (!ObjectUtils.equals(this.relationshipId, v)) 65 { 66 this.relationshipId = v; 67 setModified(true); 68 } 69 70 71 72 if (collROptionOptions != null) 74 { 75 for (int i = 0; i < collROptionOptions.size(); i++) 76 { 77 ((ROptionOption) collROptionOptions.get(i)) 78 .setRelationshipId(v); 79 } 80 } 81 } 82 83 88 public String getName() 89 { 90 return name; 91 } 92 93 94 99 public void setName(String v) 100 { 101 102 if (!ObjectUtils.equals(this.name, v)) 103 { 104 this.name = v; 105 setModified(true); 106 } 107 108 109 } 110 111 112 113 114 117 protected List collROptionOptions; 118 119 124 protected void initROptionOptions() 125 { 126 if (collROptionOptions == null) 127 { 128 collROptionOptions = new ArrayList (); 129 } 130 } 131 132 133 140 public void addROptionOption(ROptionOption l) throws TorqueException 141 { 142 getROptionOptions().add(l); 143 l.setOptionRelationship((OptionRelationship)this); 144 } 145 146 149 private Criteria lastROptionOptionsCriteria = null; 150 151 158 public List getROptionOptions() throws TorqueException 159 { 160 if (collROptionOptions == null) 161 { 162 collROptionOptions = getROptionOptions(new Criteria(10)); 163 } 164 return collROptionOptions; 165 } 166 167 178 public List getROptionOptions(Criteria criteria) throws TorqueException 179 { 180 if (collROptionOptions == null) 181 { 182 if (isNew()) 183 { 184 collROptionOptions = new ArrayList (); 185 } 186 else 187 { 188 criteria.add(ROptionOptionPeer.RELATIONSHIP_ID, getRelationshipId() ); 189 collROptionOptions = ROptionOptionPeer.doSelect(criteria); 190 } 191 } 192 else 193 { 194 if (!isNew()) 196 { 197 criteria.add(ROptionOptionPeer.RELATIONSHIP_ID, getRelationshipId() ); 201 if (!lastROptionOptionsCriteria.equals(criteria)) 202 { 203 collROptionOptions = ROptionOptionPeer.doSelect(criteria); 204 } 205 } 206 } 207 lastROptionOptionsCriteria = criteria; 208 209 return collROptionOptions; 210 } 211 212 220 public List getROptionOptions(Connection con) throws TorqueException 221 { 222 if (collROptionOptions == null) 223 { 224 collROptionOptions = getROptionOptions(new Criteria(10),con); 225 } 226 return collROptionOptions; 227 } 228 229 241 public List getROptionOptions(Criteria criteria,Connection con) throws TorqueException 242 { 243 if (collROptionOptions == null) 244 { 245 if (isNew()) 246 { 247 collROptionOptions = new ArrayList (); 248 } 249 else 250 { 251 criteria.add(ROptionOptionPeer.RELATIONSHIP_ID, getRelationshipId() ); 252 collROptionOptions = ROptionOptionPeer.doSelect(criteria,con); 253 } 254 } 255 else 256 { 257 if (!isNew()) 259 { 260 criteria.add(ROptionOptionPeer.RELATIONSHIP_ID, getRelationshipId() ); 264 if (!lastROptionOptionsCriteria.equals(criteria)) 265 { 266 collROptionOptions = ROptionOptionPeer.doSelect(criteria,con); 267 } 268 } 269 } 270 lastROptionOptionsCriteria = criteria; 271 272 return collROptionOptions; 273 } 274 275 276 277 278 279 280 281 282 283 284 285 296 protected List getROptionOptionsJoinAttributeOptionRelatedByOption1Id(Criteria criteria) 297 throws TorqueException 298 { 299 if (collROptionOptions == null) 300 { 301 if (isNew()) 302 { 303 collROptionOptions = new ArrayList (); 304 } 305 else 306 { 307 criteria.add(ROptionOptionPeer.RELATIONSHIP_ID, getRelationshipId() ); 308 collROptionOptions = ROptionOptionPeer.doSelectJoinAttributeOptionRelatedByOption1Id(criteria); 309 } 310 } 311 else 312 { 313 317 criteria.add(ROptionOptionPeer.RELATIONSHIP_ID, getRelationshipId() ); 318 if (!lastROptionOptionsCriteria.equals(criteria)) 319 { 320 collROptionOptions = ROptionOptionPeer.doSelectJoinAttributeOptionRelatedByOption1Id(criteria); 321 } 322 } 323 lastROptionOptionsCriteria = criteria; 324 325 return collROptionOptions; 326 } 327 328 329 330 331 332 333 334 335 336 347 protected List getROptionOptionsJoinAttributeOptionRelatedByOption2Id(Criteria criteria) 348 throws TorqueException 349 { 350 if (collROptionOptions == null) 351 { 352 if (isNew()) 353 { 354 collROptionOptions = new ArrayList (); 355 } 356 else 357 { 358 criteria.add(ROptionOptionPeer.RELATIONSHIP_ID, getRelationshipId() ); 359 collROptionOptions = ROptionOptionPeer.doSelectJoinAttributeOptionRelatedByOption2Id(criteria); 360 } 361 } 362 else 363 { 364 368 criteria.add(ROptionOptionPeer.RELATIONSHIP_ID, getRelationshipId() ); 369 if (!lastROptionOptionsCriteria.equals(criteria)) 370 { 371 collROptionOptions = ROptionOptionPeer.doSelectJoinAttributeOptionRelatedByOption2Id(criteria); 372 } 373 } 374 lastROptionOptionsCriteria = criteria; 375 376 return collROptionOptions; 377 } 378 379 380 381 382 383 384 385 386 387 398 protected List getROptionOptionsJoinOptionRelationship(Criteria criteria) 399 throws TorqueException 400 { 401 if (collROptionOptions == null) 402 { 403 if (isNew()) 404 { 405 collROptionOptions = new ArrayList (); 406 } 407 else 408 { 409 criteria.add(ROptionOptionPeer.RELATIONSHIP_ID, getRelationshipId() ); 410 collROptionOptions = ROptionOptionPeer.doSelectJoinOptionRelationship(criteria); 411 } 412 } 413 else 414 { 415 419 criteria.add(ROptionOptionPeer.RELATIONSHIP_ID, getRelationshipId() ); 420 if (!lastROptionOptionsCriteria.equals(criteria)) 421 { 422 collROptionOptions = ROptionOptionPeer.doSelectJoinOptionRelationship(criteria); 423 } 424 } 425 lastROptionOptionsCriteria = criteria; 426 427 return collROptionOptions; 428 } 429 430 431 432 433 private static List fieldNames = null; 434 435 440 public static synchronized List getFieldNames() 441 { 442 if (fieldNames == null) 443 { 444 fieldNames = new ArrayList (); 445 fieldNames.add("RelationshipId"); 446 fieldNames.add("Name"); 447 fieldNames = Collections.unmodifiableList(fieldNames); 448 } 449 return fieldNames; 450 } 451 452 458 public Object getByName(String name) 459 { 460 if (name.equals("RelationshipId")) 461 { 462 return getRelationshipId(); 463 } 464 if (name.equals("Name")) 465 { 466 return getName(); 467 } 468 return null; 469 } 470 471 479 public Object getByPeerName(String name) 480 { 481 if (name.equals(OptionRelationshipPeer.RELATIONSHIP_ID)) 482 { 483 return getRelationshipId(); 484 } 485 if (name.equals(OptionRelationshipPeer.RELATIONSHIP_NAME)) 486 { 487 return getName(); 488 } 489 return null; 490 } 491 492 499 public Object getByPosition(int pos) 500 { 501 if (pos == 0) 502 { 503 return getRelationshipId(); 504 } 505 if (pos == 1) 506 { 507 return getName(); 508 } 509 return null; 510 } 511 512 518 public void save() throws Exception 519 { 520 save(OptionRelationshipPeer.getMapBuilder() 521 .getDatabaseMap().getName()); 522 } 523 524 534 public void save(String dbName) throws TorqueException 535 { 536 Connection con = null; 537 try 538 { 539 con = Transaction.begin(dbName); 540 save(con); 541 Transaction.commit(con); 542 } 543 catch(TorqueException e) 544 { 545 Transaction.safeRollback(con); 546 throw e; 547 } 548 } 549 550 552 private boolean alreadyInSave = false; 553 563 public void save(Connection con) throws TorqueException 564 { 565 if (!alreadyInSave) 566 { 567 alreadyInSave = true; 568 569 570 571 if (isModified()) 573 { 574 if (isNew()) 575 { 576 OptionRelationshipPeer.doInsert((OptionRelationship)this, con); 577 setNew(false); 578 } 579 else 580 { 581 OptionRelationshipPeer.doUpdate((OptionRelationship)this, con); 582 } 583 584 if (isCacheOnSave()) 585 { 586 OptionRelationshipManager.putInstance(this); 587 } 588 } 589 590 591 if (collROptionOptions != null) 592 { 593 for (int i = 0; i < collROptionOptions.size(); i++) 594 { 595 ((ROptionOption)collROptionOptions.get(i)).save(con); 596 } 597 } 598 alreadyInSave = false; 599 } 600 } 601 602 606 protected boolean isCacheOnSave() 607 { 608 return true; 609 } 610 611 612 617 public void setPrimaryKey(ObjectKey relationshipId) 618 throws TorqueException { 619 setRelationshipId(new Integer (((NumberKey)relationshipId).intValue())); 620 } 621 622 627 public void setPrimaryKey(String key) throws TorqueException 628 { 629 setRelationshipId(new Integer (key)); 630 } 631 632 633 637 public ObjectKey getPrimaryKey() 638 { 639 return SimpleKey.keyFor(getRelationshipId()); 640 } 641 642 646 public String getQueryKey() 647 { 648 if (getPrimaryKey() == null) 649 { 650 return ""; 651 } 652 else 653 { 654 return getPrimaryKey().toString(); 655 } 656 } 657 658 662 public void setQueryKey(String key) 663 throws TorqueException 664 { 665 setPrimaryKey(key); 666 } 667 668 674 public OptionRelationship copy() throws TorqueException 675 { 676 OptionRelationship copyObj = new OptionRelationship(); 677 copyObj.setRelationshipId(relationshipId); 678 copyObj.setName(name); 679 680 copyObj.setRelationshipId((Integer )null); 681 682 683 684 List v = getROptionOptions(); 685 for (int i = 0; i < v.size(); i++) 686 { 687 ROptionOption obj = (ROptionOption) v.get(i); 688 copyObj.addROptionOption(obj.copy()); 689 } 690 return copyObj; 691 } 692 693 699 public OptionRelationshipPeer getPeer() 700 { 701 return peer; 702 } 703 704 public String toString() 705 { 706 StringBuffer str = new StringBuffer (); 707 str.append("OptionRelationship:\n"); 708 str.append("RelationshipId = ") 709 .append(getRelationshipId()) 710 .append("\n"); 711 str.append("Name = ") 712 .append(getName()) 713 .append("\n"); 714 return(str.toString()); 715 } 716 } 717 | Popular Tags |