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 27 28 29 37 public abstract class BaseTurbineUserGroupRole extends BaseObject 38 implements org.apache.turbine.om.Retrievable 39 { 40 41 private static final TurbineUserGroupRolePeer peer = 42 new TurbineUserGroupRolePeer(); 43 44 45 46 private int userId; 47 48 49 private int groupId; 50 51 52 private int roleId; 53 54 55 60 public int getUserId() 61 { 62 return userId; 63 } 64 65 66 71 public void setUserId(int v) throws TorqueException 72 { 73 74 if (this.userId != v) 75 { 76 this.userId = v; 77 setModified(true); 78 } 79 80 81 if (aTurbineUser != null && !(aTurbineUser.getUserId() == v)) 82 { 83 aTurbineUser = null; 84 } 85 86 } 87 88 93 public int getGroupId() 94 { 95 return groupId; 96 } 97 98 99 104 public void setGroupId(int v) throws TorqueException 105 { 106 107 if (this.groupId != v) 108 { 109 this.groupId = v; 110 setModified(true); 111 } 112 113 114 if (aTurbineGroup != null && !(aTurbineGroup.getGroupId() == v)) 115 { 116 aTurbineGroup = null; 117 } 118 119 } 120 121 126 public int getRoleId() 127 { 128 return roleId; 129 } 130 131 132 137 public void setRoleId(int v) throws TorqueException 138 { 139 140 if (this.roleId != v) 141 { 142 this.roleId = v; 143 setModified(true); 144 } 145 146 147 if (aTurbineRole != null && !(aTurbineRole.getRoleId() == v)) 148 { 149 aTurbineRole = null; 150 } 151 152 } 153 154 155 156 157 158 private TurbineUser aTurbineUser; 159 160 166 public void setTurbineUser(TurbineUser v) throws TorqueException 167 { 168 if (v == null) 169 { 170 setUserId( 0); 171 } 172 else 173 { 174 setUserId(v.getUserId()); 175 } 176 aTurbineUser = v; 177 } 178 179 180 186 public TurbineUser getTurbineUser() throws TorqueException 187 { 188 if (aTurbineUser == null && (this.userId != 0)) 189 { 190 aTurbineUser = TurbineUserPeer.retrieveByPK(SimpleKey.keyFor(this.userId)); 191 192 201 } 202 return aTurbineUser; 203 } 204 205 211 public void setTurbineUserKey(ObjectKey key) throws TorqueException 212 { 213 214 setUserId(((NumberKey) key).intValue()); 215 } 216 217 218 219 220 private TurbineGroup aTurbineGroup; 221 222 228 public void setTurbineGroup(TurbineGroup v) throws TorqueException 229 { 230 if (v == null) 231 { 232 setGroupId( 0); 233 } 234 else 235 { 236 setGroupId(v.getGroupId()); 237 } 238 aTurbineGroup = v; 239 } 240 241 242 248 public TurbineGroup getTurbineGroup() throws TorqueException 249 { 250 if (aTurbineGroup == null && (this.groupId != 0)) 251 { 252 aTurbineGroup = TurbineGroupPeer.retrieveByPK(SimpleKey.keyFor(this.groupId)); 253 254 263 } 264 return aTurbineGroup; 265 } 266 267 273 public void setTurbineGroupKey(ObjectKey key) throws TorqueException 274 { 275 276 setGroupId(((NumberKey) key).intValue()); 277 } 278 279 280 281 282 private TurbineRole aTurbineRole; 283 284 290 public void setTurbineRole(TurbineRole v) throws TorqueException 291 { 292 if (v == null) 293 { 294 setRoleId( 0); 295 } 296 else 297 { 298 setRoleId(v.getRoleId()); 299 } 300 aTurbineRole = v; 301 } 302 303 304 310 public TurbineRole getTurbineRole() throws TorqueException 311 { 312 if (aTurbineRole == null && (this.roleId != 0)) 313 { 314 aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId)); 315 316 325 } 326 return aTurbineRole; 327 } 328 329 335 public void setTurbineRoleKey(ObjectKey key) throws TorqueException 336 { 337 338 setRoleId(((NumberKey) key).intValue()); 339 } 340 341 342 private static List fieldNames = null; 343 344 349 public static synchronized List getFieldNames() 350 { 351 if (fieldNames == null) 352 { 353 fieldNames = new ArrayList (); 354 fieldNames.add("UserId"); 355 fieldNames.add("GroupId"); 356 fieldNames.add("RoleId"); 357 fieldNames = Collections.unmodifiableList(fieldNames); 358 } 359 return fieldNames; 360 } 361 362 368 public Object getByName(String name) 369 { 370 if (name.equals("UserId")) 371 { 372 return new Integer (getUserId()); 373 } 374 if (name.equals("GroupId")) 375 { 376 return new Integer (getGroupId()); 377 } 378 if (name.equals("RoleId")) 379 { 380 return new Integer (getRoleId()); 381 } 382 return null; 383 } 384 385 393 public Object getByPeerName(String name) 394 { 395 if (name.equals(TurbineUserGroupRolePeer.USER_ID)) 396 { 397 return new Integer (getUserId()); 398 } 399 if (name.equals(TurbineUserGroupRolePeer.GROUP_ID)) 400 { 401 return new Integer (getGroupId()); 402 } 403 if (name.equals(TurbineUserGroupRolePeer.ROLE_ID)) 404 { 405 return new Integer (getRoleId()); 406 } 407 return null; 408 } 409 410 417 public Object getByPosition(int pos) 418 { 419 if (pos == 0) 420 { 421 return new Integer (getUserId()); 422 } 423 if (pos == 1) 424 { 425 return new Integer (getGroupId()); 426 } 427 if (pos == 2) 428 { 429 return new Integer (getRoleId()); 430 } 431 return null; 432 } 433 434 440 public void save() throws Exception  441 { 442 save(TurbineUserGroupRolePeer.getMapBuilder() 443 .getDatabaseMap().getName()); 444 } 445 446 456 public void save(String dbName) throws TorqueException 457 { 458 Connection con = null; 459 try 460 { 461 con = Transaction.begin(dbName); 462 save(con); 463 Transaction.commit(con); 464 } 465 catch(TorqueException e) 466 { 467 Transaction.safeRollback(con); 468 throw e; 469 } 470 } 471 472 474 private boolean alreadyInSave = false; 475 485 public void save(Connection con) throws TorqueException 486 { 487 if (!alreadyInSave) 488 { 489 alreadyInSave = true; 490 491 492 493 if (isModified()) 495 { 496 if (isNew()) 497 { 498 TurbineUserGroupRolePeer.doInsert((TurbineUserGroupRole) this, con); 499 setNew(false); 500 } 501 else 502 { 503 TurbineUserGroupRolePeer.doUpdate((TurbineUserGroupRole) this, con); 504 } 505 } 506 507 alreadyInSave = false; 508 } 509 } 510 511 512 513 private final SimpleKey[] pks = new SimpleKey[3]; 514 private final ComboKey comboPK = new ComboKey(pks); 515 516 521 public void setPrimaryKey(ObjectKey key) throws TorqueException 522 { 523 SimpleKey[] keys = (SimpleKey[]) key.getValue(); 524 SimpleKey tmpKey = null; 525 setUserId(((NumberKey)keys[0]).intValue()); 526 setGroupId(((NumberKey)keys[1]).intValue()); 527 setRoleId(((NumberKey)keys[2]).intValue()); 528 } 529 530 537 public void setPrimaryKey( int userId, int groupId, int roleId) 538 throws TorqueException 539 { 540 setUserId(userId); 541 setGroupId(groupId); 542 setRoleId(roleId); 543 } 544 545 548 public void setPrimaryKey(String key) throws TorqueException 549 { 550 setPrimaryKey(new ComboKey(key)); 551 } 552 553 557 public ObjectKey getPrimaryKey() 558 { 559 pks[0] = SimpleKey.keyFor(getUserId()); 560 pks[1] = SimpleKey.keyFor(getGroupId()); 561 pks[2] = SimpleKey.keyFor(getRoleId()); 562 return comboPK; 563 } 564 565 569 public String getQueryKey() 570 { 571 if (getPrimaryKey() == null) 572 { 573 return ""; 574 } 575 else 576 { 577 return getPrimaryKey().toString(); 578 } 579 } 580 581 585 public void setQueryKey(String key) 586 throws TorqueException 587 { 588 setPrimaryKey(key); 589 } 590 591 597 public TurbineUserGroupRole copy() throws TorqueException 598 { 599 return copyInto(new TurbineUserGroupRole()); 600 } 601 602 protected TurbineUserGroupRole copyInto(TurbineUserGroupRole copyObj) throws TorqueException 603 { 604 copyObj.setUserId(userId); 605 copyObj.setGroupId(groupId); 606 copyObj.setRoleId(roleId); 607 608 copyObj.setUserId( 0); 609 copyObj.setGroupId( 0); 610 copyObj.setRoleId( 0); 611 612 return copyObj; 613 } 614 615 621 public TurbineUserGroupRolePeer getPeer() 622 { 623 return peer; 624 } 625 626 public String toString() 627 { 628 StringBuffer str = new StringBuffer (); 629 str.append("TurbineUserGroupRole:\n"); 630 str.append("UserId = ") 631 .append(getUserId()) 632 .append("\n"); 633 str.append("GroupId = ") 634 .append(getGroupId()) 635 .append("\n"); 636 str.append("RoleId = ") 637 .append(getRoleId()) 638 .append("\n"); 639 return(str.toString()); 640 } 641 } 642
| Popular Tags
|