1 package org.apache.jetspeed.om.security.turbine; 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.torque.TorqueException; 13 import org.apache.torque.om.BaseObject; 14 import org.apache.torque.om.ComboKey; 15 import org.apache.torque.om.DateKey; 16 import org.apache.torque.om.NumberKey; 17 import org.apache.torque.om.ObjectKey; 18 import org.apache.torque.om.SimpleKey; 19 import org.apache.torque.om.StringKey; 20 import org.apache.torque.om.Persistent; 21 import org.apache.torque.util.Criteria; 22 import org.apache.torque.util.Transaction; 23 24 25 26 27 28 36 public abstract class BaseTurbineUserGroupRole extends BaseObject 37 { 38 39 private static final TurbineUserGroupRolePeer peer = 40 new TurbineUserGroupRolePeer(); 41 42 43 44 private int userId; 45 46 47 private int groupId; 48 49 50 private int roleId; 51 52 53 57 public int getUserId() 58 { 59 return userId; 60 } 61 62 63 66 public void setUserId(int v ) throws TorqueException 67 { 68 69 if (this.userId != v) 70 { 71 this.userId = v; 72 setModified(true); 73 } 74 75 76 if (aTurbineUser != null && !(aTurbineUser.getUserId() == v)) 77 { 78 aTurbineUser = null; 79 } 80 81 } 82 83 84 88 public int getGroupId() 89 { 90 return groupId; 91 } 92 93 94 97 public void setGroupId(int v ) throws TorqueException 98 { 99 100 if (this.groupId != v) 101 { 102 this.groupId = v; 103 setModified(true); 104 } 105 106 107 if (aTurbineGroup != null && !(aTurbineGroup.getGroupId() == v)) 108 { 109 aTurbineGroup = null; 110 } 111 112 } 113 114 115 119 public int getRoleId() 120 { 121 return roleId; 122 } 123 124 125 128 public void setRoleId(int v ) throws TorqueException 129 { 130 131 if (this.roleId != v) 132 { 133 this.roleId = v; 134 setModified(true); 135 } 136 137 138 if (aTurbineRole != null && !(aTurbineRole.getRoleId() == v)) 139 { 140 aTurbineRole = null; 141 } 142 143 } 144 145 146 147 148 149 private TurbineUser aTurbineUser; 150 151 156 public void setTurbineUser(TurbineUser v) throws TorqueException 157 { 158 if (v == null) 159 { 160 setUserId(0); 161 } 162 else 163 { 164 setUserId(v.getUserId()); 165 } 166 aTurbineUser = v; 167 } 168 169 170 public TurbineUser getTurbineUser() throws TorqueException 171 { 172 if ( getUserId()>0 ) 173 { 174 return TurbineUserManager.getInstance(SimpleKey.keyFor(getUserId())); 175 } 176 return aTurbineUser; 177 } 178 179 185 public void setTurbineUserKey(ObjectKey key) throws TorqueException 186 { 187 188 setUserId(((NumberKey) key).intValue()); 189 } 190 191 192 193 194 private TurbineGroup aTurbineGroup; 195 196 201 public void setTurbineGroup(TurbineGroup v) throws TorqueException 202 { 203 if (v == null) 204 { 205 setGroupId(0); 206 } 207 else 208 { 209 setGroupId(v.getGroupId()); 210 } 211 aTurbineGroup = v; 212 } 213 214 215 public TurbineGroup getTurbineGroup() throws TorqueException 216 { 217 if ( getGroupId()>0 ) 218 { 219 return TurbineGroupManager.getInstance(SimpleKey.keyFor(getGroupId())); 220 } 221 return aTurbineGroup; 222 } 223 224 230 public void setTurbineGroupKey(ObjectKey key) throws TorqueException 231 { 232 233 setGroupId(((NumberKey) key).intValue()); 234 } 235 236 237 238 239 private TurbineRole aTurbineRole; 240 241 246 public void setTurbineRole(TurbineRole v) throws TorqueException 247 { 248 if (v == null) 249 { 250 setRoleId(0); 251 } 252 else 253 { 254 setRoleId(v.getRoleId()); 255 } 256 aTurbineRole = v; 257 } 258 259 260 public TurbineRole getTurbineRole() throws TorqueException 261 { 262 if ( getRoleId()>0 ) 263 { 264 return TurbineRoleManager.getInstance(SimpleKey.keyFor(getRoleId())); 265 } 266 return aTurbineRole; 267 } 268 269 275 public void setTurbineRoleKey(ObjectKey key) throws TorqueException 276 { 277 278 setRoleId(((NumberKey) key).intValue()); 279 } 280 281 282 283 private static List fieldNames = null; 284 285 288 public static synchronized List getFieldNames() 289 { 290 if (fieldNames == null) 291 { 292 fieldNames = new ArrayList (); 293 fieldNames.add("UserId"); 294 fieldNames.add("GroupId"); 295 fieldNames.add("RoleId"); 296 fieldNames = Collections.unmodifiableList(fieldNames); 297 } 298 return fieldNames; 299 } 300 301 305 public Object getByName(String name) 306 { 307 if (name.equals("UserId")) 308 { 309 return new Integer (getUserId()); 310 } 311 if (name.equals("GroupId")) 312 { 313 return new Integer (getGroupId()); 314 } 315 if (name.equals("RoleId")) 316 { 317 return new Integer (getRoleId()); 318 } 319 return null; 320 } 321 322 327 public Object getByPeerName(String name) 328 { 329 if (name.equals(TurbineUserGroupRolePeer.USER_ID )) 330 { 331 return new Integer (getUserId()); 332 } 333 if (name.equals(TurbineUserGroupRolePeer.GROUP_ID )) 334 { 335 return new Integer (getGroupId()); 336 } 337 if (name.equals(TurbineUserGroupRolePeer.ROLE_ID )) 338 { 339 return new Integer (getRoleId()); 340 } 341 return null; 342 } 343 344 348 public Object getByPosition(int pos) 349 { 350 if ( pos == 0 ) 351 { 352 return new Integer (getUserId()); 353 } 354 if ( pos == 1 ) 355 { 356 return new Integer (getGroupId()); 357 } 358 if ( pos == 2 ) 359 { 360 return new Integer (getRoleId()); 361 } 362 return null; 363 } 364 365 369 public void save() throws Exception 370 { 371 save(TurbineUserGroupRolePeer.getMapBuilder() 372 .getDatabaseMap().getName()); 373 } 374 375 382 public void save(String dbName) throws TorqueException 383 { 384 Connection con = null; 385 try 386 { 387 con = Transaction.begin(dbName); 388 save(con); 389 Transaction.commit(con); 390 } 391 catch(TorqueException e) 392 { 393 Transaction.safeRollback(con); 394 throw e; 395 } 396 } 397 398 400 private boolean alreadyInSave = false; 401 408 public void save(Connection con) throws TorqueException 409 { 410 if (!alreadyInSave) 411 { 412 alreadyInSave = true; 413 414 415 416 if (isModified()) 418 { 419 if (isNew()) 420 { 421 TurbineUserGroupRolePeer.doInsert((TurbineUserGroupRole)this, con); 422 setNew(false); 423 } 424 else 425 { 426 TurbineUserGroupRolePeer.doUpdate((TurbineUserGroupRole)this, con); 427 } 428 429 if (isCacheOnSave()) 430 { 431 TurbineUserGroupRoleManager.putInstance(this); 432 } 433 } 434 435 alreadyInSave = false; 436 } 437 } 438 439 443 protected boolean isCacheOnSave() 444 { 445 return true; 446 } 447 448 449 450 private final SimpleKey[] pks = new SimpleKey[3]; 451 private final ComboKey comboPK = new ComboKey(pks); 452 455 public void setPrimaryKey(ObjectKey key) throws TorqueException 456 { 457 SimpleKey[] keys = (SimpleKey[]) key.getValue(); 458 SimpleKey tmpKey = null; 459 setUserId(((NumberKey)keys[0]).intValue()); 460 setGroupId(((NumberKey)keys[1]).intValue()); 461 setRoleId(((NumberKey)keys[2]).intValue()); 462 } 463 464 471 public void setPrimaryKey( int userId, int groupId, int roleId) 472 throws TorqueException 473 { 474 setUserId(userId); 475 setGroupId(groupId); 476 setRoleId(roleId); 477 } 478 479 482 public void setPrimaryKey(String key) throws TorqueException 483 { 484 setPrimaryKey(new ComboKey(key)); 485 } 486 487 491 public ObjectKey getPrimaryKey() 492 { 493 pks[0] = SimpleKey.keyFor(getUserId()); 494 pks[1] = SimpleKey.keyFor(getGroupId()); 495 pks[2] = SimpleKey.keyFor(getRoleId()); 496 return comboPK; 497 } 498 499 500 505 public TurbineUserGroupRole copy() throws TorqueException 506 { 507 TurbineUserGroupRole copyObj = new TurbineUserGroupRole(); 508 copyObj.setUserId(userId); 509 copyObj.setGroupId(groupId); 510 copyObj.setRoleId(roleId); 511 512 copyObj.setUserId(0); 513 copyObj.setGroupId(0); 514 copyObj.setRoleId(0); 515 516 return copyObj; 517 } 518 519 525 public TurbineUserGroupRolePeer getPeer() 526 { 527 return peer; 528 } 529 } 530 | Popular Tags |