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 BaseTurbineGroup extends BaseObject 35 implements org.apache.turbine.om.Retrievable 36 { 37 38 private static final TurbineGroupPeer peer = 39 new TurbineGroupPeer(); 40 41 42 43 private int groupId; 44 45 46 private String name; 47 48 49 54 public int getGroupId() 55 { 56 return groupId; 57 } 58 59 60 65 public void setGroupId(int v) throws TorqueException 66 { 67 68 if (this.groupId != v) 69 { 70 this.groupId = v; 71 setModified(true); 72 } 73 74 75 76 if (collTurbineUserGroupRoles != null) 78 { 79 for (int i = 0; i < collTurbineUserGroupRoles.size(); i++) 80 { 81 ((TurbineUserGroupRole) collTurbineUserGroupRoles.get(i)) 82 .setGroupId(v); 83 } 84 } 85 } 86 87 92 public String getName() 93 { 94 return name; 95 } 96 97 98 103 public void setName(String v) 104 { 105 106 if (!ObjectUtils.equals(this.name, v)) 107 { 108 this.name = v; 109 setModified(true); 110 } 111 112 113 } 114 115 116 117 118 121 protected List collTurbineUserGroupRoles; 122 123 128 protected void initTurbineUserGroupRoles() 129 { 130 if (collTurbineUserGroupRoles == null) 131 { 132 collTurbineUserGroupRoles = new ArrayList (); 133 } 134 } 135 136 143 public void addTurbineUserGroupRole(TurbineUserGroupRole l) throws TorqueException 144 { 145 getTurbineUserGroupRoles().add(l); 146 l.setTurbineGroup((TurbineGroup) this); 147 } 148 149 152 private Criteria lastTurbineUserGroupRolesCriteria = null; 153 154 161 public List getTurbineUserGroupRoles() throws TorqueException 162 { 163 if (collTurbineUserGroupRoles == null) 164 { 165 collTurbineUserGroupRoles = getTurbineUserGroupRoles(new Criteria(10)); 166 } 167 return collTurbineUserGroupRoles; 168 } 169 170 181 public List getTurbineUserGroupRoles(Criteria criteria) throws TorqueException 182 { 183 if (collTurbineUserGroupRoles == null) 184 { 185 if (isNew()) 186 { 187 collTurbineUserGroupRoles = new ArrayList (); 188 } 189 else 190 { 191 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId() ); 192 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelect(criteria); 193 } 194 } 195 else 196 { 197 if (!isNew()) 199 { 200 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId()); 204 if (!lastTurbineUserGroupRolesCriteria.equals(criteria)) 205 { 206 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelect(criteria); 207 } 208 } 209 } 210 lastTurbineUserGroupRolesCriteria = criteria; 211 212 return collTurbineUserGroupRoles; 213 } 214 215 223 public List getTurbineUserGroupRoles(Connection con) throws TorqueException 224 { 225 if (collTurbineUserGroupRoles == null) 226 { 227 collTurbineUserGroupRoles = getTurbineUserGroupRoles(new Criteria(10), con); 228 } 229 return collTurbineUserGroupRoles; 230 } 231 232 244 public List getTurbineUserGroupRoles(Criteria criteria, Connection con) 245 throws TorqueException 246 { 247 if (collTurbineUserGroupRoles == null) 248 { 249 if (isNew()) 250 { 251 collTurbineUserGroupRoles = new ArrayList (); 252 } 253 else 254 { 255 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId()); 256 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelect(criteria, con); 257 } 258 } 259 else 260 { 261 if (!isNew()) 263 { 264 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId()); 268 if (!lastTurbineUserGroupRolesCriteria.equals(criteria)) 269 { 270 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelect(criteria, con); 271 } 272 } 273 } 274 lastTurbineUserGroupRolesCriteria = criteria; 275 276 return collTurbineUserGroupRoles; 277 } 278 279 280 281 282 283 284 285 286 287 288 289 300 protected List getTurbineUserGroupRolesJoinTurbineUser(Criteria criteria) 301 throws TorqueException 302 { 303 if (collTurbineUserGroupRoles == null) 304 { 305 if (isNew()) 306 { 307 collTurbineUserGroupRoles = new ArrayList (); 308 } 309 else 310 { 311 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId()); 312 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineUser(criteria); 313 } 314 } 315 else 316 { 317 321 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId()); 322 if (!lastTurbineUserGroupRolesCriteria.equals(criteria)) 323 { 324 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineUser(criteria); 325 } 326 } 327 lastTurbineUserGroupRolesCriteria = criteria; 328 329 return collTurbineUserGroupRoles; 330 } 331 332 333 334 335 336 337 338 339 340 351 protected List getTurbineUserGroupRolesJoinTurbineGroup(Criteria criteria) 352 throws TorqueException 353 { 354 if (collTurbineUserGroupRoles == null) 355 { 356 if (isNew()) 357 { 358 collTurbineUserGroupRoles = new ArrayList (); 359 } 360 else 361 { 362 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId()); 363 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineGroup(criteria); 364 } 365 } 366 else 367 { 368 372 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId()); 373 if (!lastTurbineUserGroupRolesCriteria.equals(criteria)) 374 { 375 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineGroup(criteria); 376 } 377 } 378 lastTurbineUserGroupRolesCriteria = criteria; 379 380 return collTurbineUserGroupRoles; 381 } 382 383 384 385 386 387 388 389 390 391 402 protected List getTurbineUserGroupRolesJoinTurbineRole(Criteria criteria) 403 throws TorqueException 404 { 405 if (collTurbineUserGroupRoles == null) 406 { 407 if (isNew()) 408 { 409 collTurbineUserGroupRoles = new ArrayList (); 410 } 411 else 412 { 413 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId()); 414 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineRole(criteria); 415 } 416 } 417 else 418 { 419 423 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, getGroupId()); 424 if (!lastTurbineUserGroupRolesCriteria.equals(criteria)) 425 { 426 collTurbineUserGroupRoles = TurbineUserGroupRolePeer.doSelectJoinTurbineRole(criteria); 427 } 428 } 429 lastTurbineUserGroupRolesCriteria = criteria; 430 431 return collTurbineUserGroupRoles; 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("GroupId"); 450 fieldNames.add("Name"); 451 fieldNames = Collections.unmodifiableList(fieldNames); 452 } 453 return fieldNames; 454 } 455 456 462 public Object getByName(String name) 463 { 464 if (name.equals("GroupId")) 465 { 466 return new Integer (getGroupId()); 467 } 468 if (name.equals("Name")) 469 { 470 return getName(); 471 } 472 return null; 473 } 474 475 483 public Object getByPeerName(String name) 484 { 485 if (name.equals(TurbineGroupPeer.GROUP_ID)) 486 { 487 return new Integer (getGroupId()); 488 } 489 if (name.equals(TurbineGroupPeer.GROUP_NAME)) 490 { 491 return getName(); 492 } 493 return null; 494 } 495 496 503 public Object getByPosition(int pos) 504 { 505 if (pos == 0) 506 { 507 return new Integer (getGroupId()); 508 } 509 if (pos == 1) 510 { 511 return getName(); 512 } 513 return null; 514 } 515 516 522 public void save() throws Exception  523 { 524 save(TurbineGroupPeer.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 TurbineGroupPeer.doInsert((TurbineGroup) this, con); 581 setNew(false); 582 } 583 else 584 { 585 TurbineGroupPeer.doUpdate((TurbineGroup) this, con); 586 } 587 } 588 589 590 591 if (collTurbineUserGroupRoles != null) 592 { 593 for (int i = 0; i < collTurbineUserGroupRoles.size(); i++) 594 { 595 ((TurbineUserGroupRole) collTurbineUserGroupRoles.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 setGroupId(((NumberKey) key).intValue()); 612 } 613 614 619 public void setPrimaryKey(String key) throws TorqueException 620 { 621 setGroupId(Integer.parseInt(key)); 622 } 623 624 625 629 public ObjectKey getPrimaryKey() 630 { 631 return SimpleKey.keyFor(getGroupId()); 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 TurbineGroup copy() throws TorqueException 667 { 668 return copyInto(new TurbineGroup()); 669 } 670 671 protected TurbineGroup copyInto(TurbineGroup copyObj) throws TorqueException 672 { 673 copyObj.setGroupId(groupId); 674 copyObj.setName(name); 675 676 copyObj.setGroupId( 0); 677 678 679 680 List v = getTurbineUserGroupRoles(); 681 for (int i = 0; i < v.size(); i++) 682 { 683 TurbineUserGroupRole obj = (TurbineUserGroupRole) v.get(i); 684 copyObj.addTurbineUserGroupRole(obj.copy()); 685 } 686 return copyObj; 687 } 688 689 695 public TurbineGroupPeer getPeer() 696 { 697 return peer; 698 } 699 700 public String toString() 701 { 702 StringBuffer str = new StringBuffer (); 703 str.append("TurbineGroup:\n"); 704 str.append("GroupId = ") 705 .append(getGroupId()) 706 .append("\n"); 707 str.append("Name = ") 708 .append(getName()) 709 .append("\n"); 710 return(str.toString()); 711 } 712 } 713
| Popular Tags
|