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 BaseActivitySetType extends BaseObject 31 implements org.apache.fulcrum.intake.Retrievable 32 { 33 34 private static final ActivitySetTypePeer peer = 35 new ActivitySetTypePeer(); 36 37 38 39 private Integer typeId; 40 41 42 private String name; 43 44 45 50 public Integer getTypeId() 51 { 52 return typeId; 53 } 54 55 56 61 public void setTypeId(Integer v) throws TorqueException 62 { 63 64 if (!ObjectUtils.equals(this.typeId, v)) 65 { 66 this.typeId = v; 67 setModified(true); 68 } 69 70 71 72 if (collActivitySets != null) 74 { 75 for (int i = 0; i < collActivitySets.size(); i++) 76 { 77 ((ActivitySet) collActivitySets.get(i)) 78 .setTypeId(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 collActivitySets; 118 119 124 protected void initActivitySets() 125 { 126 if (collActivitySets == null) 127 { 128 collActivitySets = new ArrayList (); 129 } 130 } 131 132 133 140 public void addActivitySet(ActivitySet l) throws TorqueException 141 { 142 getActivitySets().add(l); 143 l.setActivitySetType((ActivitySetType)this); 144 } 145 146 149 private Criteria lastActivitySetsCriteria = null; 150 151 158 public List getActivitySets() throws TorqueException 159 { 160 if (collActivitySets == null) 161 { 162 collActivitySets = getActivitySets(new Criteria(10)); 163 } 164 return collActivitySets; 165 } 166 167 178 public List getActivitySets(Criteria criteria) throws TorqueException 179 { 180 if (collActivitySets == null) 181 { 182 if (isNew()) 183 { 184 collActivitySets = new ArrayList (); 185 } 186 else 187 { 188 criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() ); 189 collActivitySets = ActivitySetPeer.doSelect(criteria); 190 } 191 } 192 else 193 { 194 if (!isNew()) 196 { 197 criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() ); 201 if (!lastActivitySetsCriteria.equals(criteria)) 202 { 203 collActivitySets = ActivitySetPeer.doSelect(criteria); 204 } 205 } 206 } 207 lastActivitySetsCriteria = criteria; 208 209 return collActivitySets; 210 } 211 212 220 public List getActivitySets(Connection con) throws TorqueException 221 { 222 if (collActivitySets == null) 223 { 224 collActivitySets = getActivitySets(new Criteria(10),con); 225 } 226 return collActivitySets; 227 } 228 229 241 public List getActivitySets(Criteria criteria,Connection con) throws TorqueException 242 { 243 if (collActivitySets == null) 244 { 245 if (isNew()) 246 { 247 collActivitySets = new ArrayList (); 248 } 249 else 250 { 251 criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() ); 252 collActivitySets = ActivitySetPeer.doSelect(criteria,con); 253 } 254 } 255 else 256 { 257 if (!isNew()) 259 { 260 criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() ); 264 if (!lastActivitySetsCriteria.equals(criteria)) 265 { 266 collActivitySets = ActivitySetPeer.doSelect(criteria,con); 267 } 268 } 269 } 270 lastActivitySetsCriteria = criteria; 271 272 return collActivitySets; 273 } 274 275 276 277 278 279 280 281 282 283 284 285 296 protected List getActivitySetsJoinScarabUserImpl(Criteria criteria) 297 throws TorqueException 298 { 299 if (collActivitySets == null) 300 { 301 if (isNew()) 302 { 303 collActivitySets = new ArrayList (); 304 } 305 else 306 { 307 criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() ); 308 collActivitySets = ActivitySetPeer.doSelectJoinScarabUserImpl(criteria); 309 } 310 } 311 else 312 { 313 317 criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() ); 318 if (!lastActivitySetsCriteria.equals(criteria)) 319 { 320 collActivitySets = ActivitySetPeer.doSelectJoinScarabUserImpl(criteria); 321 } 322 } 323 lastActivitySetsCriteria = criteria; 324 325 return collActivitySets; 326 } 327 328 329 330 331 332 333 334 335 336 347 protected List getActivitySetsJoinActivitySetType(Criteria criteria) 348 throws TorqueException 349 { 350 if (collActivitySets == null) 351 { 352 if (isNew()) 353 { 354 collActivitySets = new ArrayList (); 355 } 356 else 357 { 358 criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() ); 359 collActivitySets = ActivitySetPeer.doSelectJoinActivitySetType(criteria); 360 } 361 } 362 else 363 { 364 368 criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() ); 369 if (!lastActivitySetsCriteria.equals(criteria)) 370 { 371 collActivitySets = ActivitySetPeer.doSelectJoinActivitySetType(criteria); 372 } 373 } 374 lastActivitySetsCriteria = criteria; 375 376 return collActivitySets; 377 } 378 379 380 381 382 383 384 385 386 387 398 protected List getActivitySetsJoinAttachment(Criteria criteria) 399 throws TorqueException 400 { 401 if (collActivitySets == null) 402 { 403 if (isNew()) 404 { 405 collActivitySets = new ArrayList (); 406 } 407 else 408 { 409 criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() ); 410 collActivitySets = ActivitySetPeer.doSelectJoinAttachment(criteria); 411 } 412 } 413 else 414 { 415 419 criteria.add(ActivitySetPeer.TYPE_ID, getTypeId() ); 420 if (!lastActivitySetsCriteria.equals(criteria)) 421 { 422 collActivitySets = ActivitySetPeer.doSelectJoinAttachment(criteria); 423 } 424 } 425 lastActivitySetsCriteria = criteria; 426 427 return collActivitySets; 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("TypeId"); 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("TypeId")) 461 { 462 return getTypeId(); 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(ActivitySetTypePeer.TYPE_ID)) 482 { 483 return getTypeId(); 484 } 485 if (name.equals(ActivitySetTypePeer.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 getTypeId(); 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(ActivitySetTypePeer.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 ActivitySetTypePeer.doInsert((ActivitySetType)this, con); 577 setNew(false); 578 } 579 else 580 { 581 ActivitySetTypePeer.doUpdate((ActivitySetType)this, con); 582 } 583 584 if (isCacheOnSave()) 585 { 586 ActivitySetTypeManager.putInstance(this); 587 } 588 } 589 590 591 if (collActivitySets != null) 592 { 593 for (int i = 0; i < collActivitySets.size(); i++) 594 { 595 ((ActivitySet)collActivitySets.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 typeId) 618 throws TorqueException { 619 setTypeId(new Integer (((NumberKey)typeId).intValue())); 620 } 621 622 627 public void setPrimaryKey(String key) throws TorqueException 628 { 629 setTypeId(new Integer (key)); 630 } 631 632 633 637 public ObjectKey getPrimaryKey() 638 { 639 return SimpleKey.keyFor(getTypeId()); 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 ActivitySetType copy() throws TorqueException 675 { 676 ActivitySetType copyObj = new ActivitySetType(); 677 copyObj.setTypeId(typeId); 678 copyObj.setName(name); 679 680 copyObj.setTypeId((Integer )null); 681 682 683 684 List v = getActivitySets(); 685 for (int i = 0; i < v.size(); i++) 686 { 687 ActivitySet obj = (ActivitySet) v.get(i); 688 copyObj.addActivitySet(obj.copy()); 689 } 690 return copyObj; 691 } 692 693 699 public ActivitySetTypePeer getPeer() 700 { 701 return peer; 702 } 703 704 public String toString() 705 { 706 StringBuffer str = new StringBuffer (); 707 str.append("ActivitySetType:\n"); 708 str.append("TypeId = ") 709 .append(getTypeId()) 710 .append("\n"); 711 str.append("Name = ") 712 .append(getName()) 713 .append("\n"); 714 return(str.toString()); 715 } 716 } 717 | Popular Tags |