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 28 29 33 public abstract class BaseROptionOption extends BaseObject 34 implements org.apache.fulcrum.intake.Retrievable 35 { 36 37 private static final ROptionOptionPeer peer = 38 new ROptionOptionPeer(); 39 40 41 42 private Integer option1Id; 43 44 45 private Integer option2Id; 46 47 48 private Integer relationshipId; 49 50 51 private int weight; 52 53 54 private int preferredOrder; 55 56 57 62 public Integer getOption1Id() 63 { 64 return option1Id; 65 } 66 67 68 73 public void setOption1Id(Integer v) throws TorqueException 74 { 75 76 if (!ObjectUtils.equals(this.option1Id, v)) 77 { 78 this.option1Id = v; 79 setModified(true); 80 } 81 82 83 if (aAttributeOptionRelatedByOption1Id != null && !ObjectUtils.equals(aAttributeOptionRelatedByOption1Id.getOptionId(), v)) 84 { 85 aAttributeOptionRelatedByOption1Id = null; 86 } 87 88 } 89 90 95 public Integer getOption2Id() 96 { 97 return option2Id; 98 } 99 100 101 106 public void setOption2Id(Integer v) throws TorqueException 107 { 108 109 if (!ObjectUtils.equals(this.option2Id, v)) 110 { 111 this.option2Id = v; 112 setModified(true); 113 } 114 115 116 if (aAttributeOptionRelatedByOption2Id != null && !ObjectUtils.equals(aAttributeOptionRelatedByOption2Id.getOptionId(), v)) 117 { 118 aAttributeOptionRelatedByOption2Id = null; 119 } 120 121 } 122 123 128 public Integer getRelationshipId() 129 { 130 return relationshipId; 131 } 132 133 134 139 public void setRelationshipId(Integer v) throws TorqueException 140 { 141 142 if (!ObjectUtils.equals(this.relationshipId, v)) 143 { 144 this.relationshipId = v; 145 setModified(true); 146 } 147 148 149 if (aOptionRelationship != null && !ObjectUtils.equals(aOptionRelationship.getRelationshipId(), v)) 150 { 151 aOptionRelationship = null; 152 } 153 154 } 155 156 161 public int getWeight() 162 { 163 return weight; 164 } 165 166 167 172 public void setWeight(int v) 173 { 174 175 if (this.weight != v) 176 { 177 this.weight = v; 178 setModified(true); 179 } 180 181 182 } 183 184 189 public int getPreferredOrder() 190 { 191 return preferredOrder; 192 } 193 194 195 200 public void setPreferredOrder(int v) 201 { 202 203 if (this.preferredOrder != v) 204 { 205 this.preferredOrder = v; 206 setModified(true); 207 } 208 209 210 } 211 212 213 214 215 private AttributeOption aAttributeOptionRelatedByOption1Id; 216 217 223 public void setAttributeOptionRelatedByOption1Id(AttributeOption v) throws TorqueException 224 { 225 if (v == null) 226 { 227 setOption1Id((Integer ) null); 228 } 229 else 230 { 231 setOption1Id(v.getOptionId()); 232 } 233 aAttributeOptionRelatedByOption1Id = v; 234 } 235 236 237 243 public AttributeOption getAttributeOptionRelatedByOption1Id() throws TorqueException 244 { 245 if ( !ObjectUtils.equals(getOption1Id(), null) ) 246 { 247 return AttributeOptionManager.getInstance(SimpleKey.keyFor(getOption1Id())); 248 } 249 return aAttributeOptionRelatedByOption1Id; 250 } 251 252 258 public void setAttributeOptionRelatedByOption1IdKey(ObjectKey key) throws TorqueException 259 { 260 261 setOption1Id(new Integer (((NumberKey) key).intValue())); 262 } 263 264 265 266 private AttributeOption aAttributeOptionRelatedByOption2Id; 267 268 274 public void setAttributeOptionRelatedByOption2Id(AttributeOption v) throws TorqueException 275 { 276 if (v == null) 277 { 278 setOption2Id((Integer ) null); 279 } 280 else 281 { 282 setOption2Id(v.getOptionId()); 283 } 284 aAttributeOptionRelatedByOption2Id = v; 285 } 286 287 288 294 public AttributeOption getAttributeOptionRelatedByOption2Id() throws TorqueException 295 { 296 if ( !ObjectUtils.equals(getOption2Id(), null) ) 297 { 298 return AttributeOptionManager.getInstance(SimpleKey.keyFor(getOption2Id())); 299 } 300 return aAttributeOptionRelatedByOption2Id; 301 } 302 303 309 public void setAttributeOptionRelatedByOption2IdKey(ObjectKey key) throws TorqueException 310 { 311 312 setOption2Id(new Integer (((NumberKey) key).intValue())); 313 } 314 315 316 317 private OptionRelationship aOptionRelationship; 318 319 325 public void setOptionRelationship(OptionRelationship v) throws TorqueException 326 { 327 if (v == null) 328 { 329 setRelationshipId((Integer ) null); 330 } 331 else 332 { 333 setRelationshipId(v.getRelationshipId()); 334 } 335 aOptionRelationship = v; 336 } 337 338 339 345 public OptionRelationship getOptionRelationship() throws TorqueException 346 { 347 if ( !ObjectUtils.equals(getRelationshipId(), null) ) 348 { 349 return OptionRelationshipManager.getInstance(SimpleKey.keyFor(getRelationshipId())); 350 } 351 return aOptionRelationship; 352 } 353 354 360 public void setOptionRelationshipKey(ObjectKey key) throws TorqueException 361 { 362 363 setRelationshipId(new Integer (((NumberKey) key).intValue())); 364 } 365 366 367 private static List fieldNames = null; 368 369 374 public static synchronized List getFieldNames() 375 { 376 if (fieldNames == null) 377 { 378 fieldNames = new ArrayList (); 379 fieldNames.add("Option1Id"); 380 fieldNames.add("Option2Id"); 381 fieldNames.add("RelationshipId"); 382 fieldNames.add("Weight"); 383 fieldNames.add("PreferredOrder"); 384 fieldNames = Collections.unmodifiableList(fieldNames); 385 } 386 return fieldNames; 387 } 388 389 395 public Object getByName(String name) 396 { 397 if (name.equals("Option1Id")) 398 { 399 return getOption1Id(); 400 } 401 if (name.equals("Option2Id")) 402 { 403 return getOption2Id(); 404 } 405 if (name.equals("RelationshipId")) 406 { 407 return getRelationshipId(); 408 } 409 if (name.equals("Weight")) 410 { 411 return new Integer (getWeight()); 412 } 413 if (name.equals("PreferredOrder")) 414 { 415 return new Integer (getPreferredOrder()); 416 } 417 return null; 418 } 419 420 428 public Object getByPeerName(String name) 429 { 430 if (name.equals(ROptionOptionPeer.OPTION1_ID)) 431 { 432 return getOption1Id(); 433 } 434 if (name.equals(ROptionOptionPeer.OPTION2_ID)) 435 { 436 return getOption2Id(); 437 } 438 if (name.equals(ROptionOptionPeer.RELATIONSHIP_ID)) 439 { 440 return getRelationshipId(); 441 } 442 if (name.equals(ROptionOptionPeer.WEIGHT)) 443 { 444 return new Integer (getWeight()); 445 } 446 if (name.equals(ROptionOptionPeer.PREFERRED_ORDER)) 447 { 448 return new Integer (getPreferredOrder()); 449 } 450 return null; 451 } 452 453 460 public Object getByPosition(int pos) 461 { 462 if (pos == 0) 463 { 464 return getOption1Id(); 465 } 466 if (pos == 1) 467 { 468 return getOption2Id(); 469 } 470 if (pos == 2) 471 { 472 return getRelationshipId(); 473 } 474 if (pos == 3) 475 { 476 return new Integer (getWeight()); 477 } 478 if (pos == 4) 479 { 480 return new Integer (getPreferredOrder()); 481 } 482 return null; 483 } 484 485 491 public void save() throws Exception 492 { 493 save(ROptionOptionPeer.getMapBuilder() 494 .getDatabaseMap().getName()); 495 } 496 497 507 public void save(String dbName) throws TorqueException 508 { 509 Connection con = null; 510 try 511 { 512 con = Transaction.begin(dbName); 513 save(con); 514 Transaction.commit(con); 515 } 516 catch(TorqueException e) 517 { 518 Transaction.safeRollback(con); 519 throw e; 520 } 521 } 522 523 525 private boolean alreadyInSave = false; 526 536 public void save(Connection con) throws TorqueException 537 { 538 if (!alreadyInSave) 539 { 540 alreadyInSave = true; 541 542 543 544 if (isModified()) 546 { 547 if (isNew()) 548 { 549 ROptionOptionPeer.doInsert((ROptionOption)this, con); 550 setNew(false); 551 } 552 else 553 { 554 ROptionOptionPeer.doUpdate((ROptionOption)this, con); 555 } 556 557 if (isCacheOnSave()) 558 { 559 ROptionOptionManager.putInstance(this); 560 } 561 } 562 563 alreadyInSave = false; 564 } 565 } 566 567 571 protected boolean isCacheOnSave() 572 { 573 return true; 574 } 575 576 577 578 private final SimpleKey[] pks = new SimpleKey[2]; 579 private final ComboKey comboPK = new ComboKey(pks); 580 581 586 public void setPrimaryKey(ObjectKey key) throws TorqueException 587 { 588 SimpleKey[] keys = (SimpleKey[]) key.getValue(); 589 SimpleKey tmpKey = null; 590 setOption1Id(new Integer (((NumberKey)keys[0]).intValue())); 591 setOption2Id(new Integer (((NumberKey)keys[1]).intValue())); 592 } 593 594 600 public void setPrimaryKey( Integer option1Id, Integer option2Id) 601 throws TorqueException 602 { 603 setOption1Id(option1Id); 604 setOption2Id(option2Id); 605 } 606 607 610 public void setPrimaryKey(String key) throws TorqueException 611 { 612 setPrimaryKey(new ComboKey(key)); 613 } 614 615 619 public ObjectKey getPrimaryKey() 620 { 621 pks[0] = SimpleKey.keyFor(getOption1Id()); 622 pks[1] = SimpleKey.keyFor(getOption2Id()); 623 return comboPK; 624 } 625 626 630 public String getQueryKey() 631 { 632 if (getPrimaryKey() == null) 633 { 634 return ""; 635 } 636 else 637 { 638 return getPrimaryKey().toString(); 639 } 640 } 641 642 646 public void setQueryKey(String key) 647 throws TorqueException 648 { 649 setPrimaryKey(key); 650 } 651 652 658 public ROptionOption copy() throws TorqueException 659 { 660 ROptionOption copyObj = new ROptionOption(); 661 copyObj.setOption1Id(option1Id); 662 copyObj.setOption2Id(option2Id); 663 copyObj.setRelationshipId(relationshipId); 664 copyObj.setWeight(weight); 665 copyObj.setPreferredOrder(preferredOrder); 666 667 copyObj.setOption1Id((Integer )null); 668 copyObj.setOption2Id((Integer )null); 669 670 return copyObj; 671 } 672 673 679 public ROptionOptionPeer getPeer() 680 { 681 return peer; 682 } 683 684 public String toString() 685 { 686 StringBuffer str = new StringBuffer (); 687 str.append("ROptionOption:\n"); 688 str.append("Option1Id = ") 689 .append(getOption1Id()) 690 .append("\n"); 691 str.append("Option2Id = ") 692 .append(getOption2Id()) 693 .append("\n"); 694 str.append("RelationshipId = ") 695 .append(getRelationshipId()) 696 .append("\n"); 697 str.append("Weight = ") 698 .append(getWeight()) 699 .append("\n"); 700 str.append("PreferredOrder = ") 701 .append(getPreferredOrder()) 702 .append("\n"); 703 return(str.toString()); 704 } 705 } 706 | Popular Tags |