1 package org.apache.fulcrum.security.impl.db.entity; 2 3 4 import java.math.BigDecimal ; 5 import java.sql.Connection ; 6 import java.util.ArrayList ; 7 import java.util.Date ; 8 import java.util.Collections ; 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 BaseTurbineUserGroupRole extends BaseObject 34 implements org.apache.fulcrum.intake.Retrievable 35 { 36 37 private static final TurbineUserGroupRolePeer peer = 38 new TurbineUserGroupRolePeer(); 39 40 41 42 private Integer userId; 43 44 45 private Integer groupId; 46 47 48 private Integer roleId; 49 50 51 56 public Integer getUserId() 57 { 58 return userId; 59 } 60 61 62 67 public void setUserId(Integer v) throws TorqueException 68 { 69 70 if (!ObjectUtils.equals(this.userId, v)) 71 { 72 this.userId = v; 73 setModified(true); 74 } 75 76 77 if (aTurbineUser != null && !ObjectUtils.equals(aTurbineUser.getUserId(), v)) 78 { 79 aTurbineUser = null; 80 } 81 82 } 83 84 89 public Integer getGroupId() 90 { 91 return groupId; 92 } 93 94 95 100 public void setGroupId(Integer v) throws TorqueException 101 { 102 103 if (!ObjectUtils.equals(this.groupId, v)) 104 { 105 this.groupId = v; 106 setModified(true); 107 } 108 109 110 if (aTurbineGroup != null && !ObjectUtils.equals(aTurbineGroup.getGroupId(), v)) 111 { 112 aTurbineGroup = null; 113 } 114 115 } 116 117 122 public Integer getRoleId() 123 { 124 return roleId; 125 } 126 127 128 133 public void setRoleId(Integer v) throws TorqueException 134 { 135 136 if (!ObjectUtils.equals(this.roleId, v)) 137 { 138 this.roleId = v; 139 setModified(true); 140 } 141 142 143 if (aTurbineRole != null && !ObjectUtils.equals(aTurbineRole.getRoleId(), v)) 144 { 145 aTurbineRole = null; 146 } 147 148 } 149 150 151 152 153 154 private TurbineUser aTurbineUser; 155 156 162 public void setTurbineUser(TurbineUser v) throws TorqueException 163 { 164 if (v == null) 165 { 166 setUserId((Integer ) null); 167 } 168 else 169 { 170 setUserId(v.getUserId()); 171 } 172 aTurbineUser = v; 173 } 174 175 176 182 public TurbineUser getTurbineUser() throws TorqueException 183 { 184 if (aTurbineUser == null && (!ObjectUtils.equals(this.userId, null))) 185 { 186 aTurbineUser = TurbineUserPeer.retrieveByPK(SimpleKey.keyFor(this.userId)); 187 188 197 } 198 return aTurbineUser; 199 } 200 201 207 public void setTurbineUserKey(ObjectKey key) throws TorqueException 208 { 209 210 setUserId(new Integer (((NumberKey) key).intValue())); 211 } 212 213 214 215 216 private TurbineGroup aTurbineGroup; 217 218 224 public void setTurbineGroup(TurbineGroup v) throws TorqueException 225 { 226 if (v == null) 227 { 228 setGroupId((Integer ) null); 229 } 230 else 231 { 232 setGroupId(v.getGroupId()); 233 } 234 aTurbineGroup = v; 235 } 236 237 238 244 public TurbineGroup getTurbineGroup() throws TorqueException 245 { 246 if (aTurbineGroup == null && (!ObjectUtils.equals(this.groupId, null))) 247 { 248 aTurbineGroup = TurbineGroupPeer.retrieveByPK(SimpleKey.keyFor(this.groupId)); 249 250 259 } 260 return aTurbineGroup; 261 } 262 263 269 public void setTurbineGroupKey(ObjectKey key) throws TorqueException 270 { 271 272 setGroupId(new Integer (((NumberKey) key).intValue())); 273 } 274 275 276 277 278 private TurbineRole aTurbineRole; 279 280 286 public void setTurbineRole(TurbineRole v) throws TorqueException 287 { 288 if (v == null) 289 { 290 setRoleId((Integer ) null); 291 } 292 else 293 { 294 setRoleId(v.getRoleId()); 295 } 296 aTurbineRole = v; 297 } 298 299 300 306 public TurbineRole getTurbineRole() throws TorqueException 307 { 308 if (aTurbineRole == null && (!ObjectUtils.equals(this.roleId, null))) 309 { 310 aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId)); 311 312 321 } 322 return aTurbineRole; 323 } 324 325 331 public void setTurbineRoleKey(ObjectKey key) throws TorqueException 332 { 333 334 setRoleId(new Integer (((NumberKey) key).intValue())); 335 } 336 337 338 private static List fieldNames = null; 339 340 345 public static synchronized List getFieldNames() 346 { 347 if (fieldNames == null) 348 { 349 fieldNames = new ArrayList (); 350 fieldNames.add("UserId"); 351 fieldNames.add("GroupId"); 352 fieldNames.add("RoleId"); 353 fieldNames = Collections.unmodifiableList(fieldNames); 354 } 355 return fieldNames; 356 } 357 358 364 public Object getByName(String name) 365 { 366 if (name.equals("UserId")) 367 { 368 return getUserId(); 369 } 370 if (name.equals("GroupId")) 371 { 372 return getGroupId(); 373 } 374 if (name.equals("RoleId")) 375 { 376 return getRoleId(); 377 } 378 return null; 379 } 380 381 389 public Object getByPeerName(String name) 390 { 391 if (name.equals(TurbineUserGroupRolePeer.USER_ID)) 392 { 393 return getUserId(); 394 } 395 if (name.equals(TurbineUserGroupRolePeer.GROUP_ID)) 396 { 397 return getGroupId(); 398 } 399 if (name.equals(TurbineUserGroupRolePeer.ROLE_ID)) 400 { 401 return getRoleId(); 402 } 403 return null; 404 } 405 406 413 public Object getByPosition(int pos) 414 { 415 if (pos == 0) 416 { 417 return getUserId(); 418 } 419 if (pos == 1) 420 { 421 return getGroupId(); 422 } 423 if (pos == 2) 424 { 425 return getRoleId(); 426 } 427 return null; 428 } 429 430 436 public void save() throws Exception 437 { 438 save(TurbineUserGroupRolePeer.getMapBuilder() 439 .getDatabaseMap().getName()); 440 } 441 442 452 public void save(String dbName) throws TorqueException 453 { 454 Connection con = null; 455 try 456 { 457 con = Transaction.begin(dbName); 458 save(con); 459 Transaction.commit(con); 460 } 461 catch(TorqueException e) 462 { 463 Transaction.safeRollback(con); 464 throw e; 465 } 466 } 467 468 470 private boolean alreadyInSave = false; 471 481 public void save(Connection con) throws TorqueException 482 { 483 if (!alreadyInSave) 484 { 485 alreadyInSave = true; 486 487 488 489 if (isModified()) 491 { 492 if (isNew()) 493 { 494 TurbineUserGroupRolePeer.doInsert((TurbineUserGroupRole) this, con); 495 setNew(false); 496 } 497 else 498 { 499 TurbineUserGroupRolePeer.doUpdate((TurbineUserGroupRole) this, con); 500 } 501 } 502 503 alreadyInSave = false; 504 } 505 } 506 507 508 509 510 private final SimpleKey[] pks = new SimpleKey[3]; 511 private final ComboKey comboPK = new ComboKey(pks); 512 513 518 public void setPrimaryKey(ObjectKey key) throws TorqueException 519 { 520 SimpleKey[] keys = (SimpleKey[]) key.getValue(); 521 SimpleKey tmpKey = null; 522 setUserId(new Integer (((NumberKey)keys[0]).intValue())); 523 setGroupId(new Integer (((NumberKey)keys[1]).intValue())); 524 setRoleId(new Integer (((NumberKey)keys[2]).intValue())); 525 } 526 527 534 public void setPrimaryKey( Integer userId, Integer groupId, Integer roleId) 535 throws TorqueException 536 { 537 setUserId(userId); 538 setGroupId(groupId); 539 setRoleId(roleId); 540 } 541 542 545 public void setPrimaryKey(String key) throws TorqueException 546 { 547 setPrimaryKey(new ComboKey(key)); 548 } 549 550 554 public ObjectKey getPrimaryKey() 555 { 556 pks[0] = SimpleKey.keyFor(getUserId()); 557 pks[1] = SimpleKey.keyFor(getGroupId()); 558 pks[2] = SimpleKey.keyFor(getRoleId()); 559 return comboPK; 560 } 561 562 563 567 public String getQueryKey() 568 { 569 if (getPrimaryKey() == null) 570 { 571 return ""; 572 } 573 else 574 { 575 return getPrimaryKey().toString(); 576 } 577 } 578 579 583 public void setQueryKey(String key) 584 throws TorqueException 585 { 586 setPrimaryKey(key); 587 } 588 589 595 public TurbineUserGroupRole copy() throws TorqueException 596 { 597 return copyInto(new TurbineUserGroupRole()); 598 } 599 600 protected TurbineUserGroupRole copyInto(TurbineUserGroupRole copyObj) throws TorqueException 601 { 602 copyObj.setUserId(userId); 603 copyObj.setGroupId(groupId); 604 copyObj.setRoleId(roleId); 605 606 copyObj.setUserId((Integer )null); 607 copyObj.setGroupId((Integer )null); 608 copyObj.setRoleId((Integer )null); 609 610 611 return copyObj; 612 } 613 614 620 public TurbineUserGroupRolePeer getPeer() 621 { 622 return peer; 623 } 624 625 public String toString() 626 { 627 StringBuffer str = new StringBuffer (); 628 str.append("TurbineUserGroupRole:\n"); 629 str.append("UserId = ") 630 .append(getUserId()) 631 .append("\n"); 632 str.append("GroupId = ") 633 .append(getGroupId()) 634 .append("\n"); 635 str.append("RoleId = ") 636 .append(getRoleId()) 637 .append("\n"); 638 return(str.toString()); 639 } 640 } 641 | Popular Tags |