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 32 public abstract class BaseTurbineRolePermission extends BaseObject 33 implements org.apache.fulcrum.intake.Retrievable 34 { 35 36 private static final TurbineRolePermissionPeer peer = 37 new TurbineRolePermissionPeer(); 38 39 40 41 private Integer roleId; 42 43 44 private Integer permissionId; 45 46 47 52 public Integer getRoleId() 53 { 54 return roleId; 55 } 56 57 58 63 public void setRoleId(Integer v) throws TorqueException 64 { 65 66 if (!ObjectUtils.equals(this.roleId, v)) 67 { 68 this.roleId = v; 69 setModified(true); 70 } 71 72 73 if (aTurbineRole != null && !ObjectUtils.equals(aTurbineRole.getRoleId(), v)) 74 { 75 aTurbineRole = null; 76 } 77 78 } 79 80 85 public Integer getPermissionId() 86 { 87 return permissionId; 88 } 89 90 91 96 public void setPermissionId(Integer v) throws TorqueException 97 { 98 99 if (!ObjectUtils.equals(this.permissionId, v)) 100 { 101 this.permissionId = v; 102 setModified(true); 103 } 104 105 106 if (aTurbinePermission != null && !ObjectUtils.equals(aTurbinePermission.getPermissionId(), v)) 107 { 108 aTurbinePermission = null; 109 } 110 111 } 112 113 114 115 116 117 private TurbineRole aTurbineRole; 118 119 125 public void setTurbineRole(TurbineRole v) throws TorqueException 126 { 127 if (v == null) 128 { 129 setRoleId((Integer ) null); 130 } 131 else 132 { 133 setRoleId(v.getRoleId()); 134 } 135 aTurbineRole = v; 136 } 137 138 139 145 public TurbineRole getTurbineRole() throws TorqueException 146 { 147 if (aTurbineRole == null && (!ObjectUtils.equals(this.roleId, null))) 148 { 149 aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId)); 150 151 160 } 161 return aTurbineRole; 162 } 163 164 170 public void setTurbineRoleKey(ObjectKey key) throws TorqueException 171 { 172 173 setRoleId(new Integer (((NumberKey) key).intValue())); 174 } 175 176 177 178 179 private TurbinePermission aTurbinePermission; 180 181 187 public void setTurbinePermission(TurbinePermission v) throws TorqueException 188 { 189 if (v == null) 190 { 191 setPermissionId((Integer ) null); 192 } 193 else 194 { 195 setPermissionId(v.getPermissionId()); 196 } 197 aTurbinePermission = v; 198 } 199 200 201 207 public TurbinePermission getTurbinePermission() throws TorqueException 208 { 209 if (aTurbinePermission == null && (!ObjectUtils.equals(this.permissionId, null))) 210 { 211 aTurbinePermission = TurbinePermissionPeer.retrieveByPK(SimpleKey.keyFor(this.permissionId)); 212 213 222 } 223 return aTurbinePermission; 224 } 225 226 232 public void setTurbinePermissionKey(ObjectKey key) throws TorqueException 233 { 234 235 setPermissionId(new Integer (((NumberKey) key).intValue())); 236 } 237 238 239 private static List fieldNames = null; 240 241 246 public static synchronized List getFieldNames() 247 { 248 if (fieldNames == null) 249 { 250 fieldNames = new ArrayList (); 251 fieldNames.add("RoleId"); 252 fieldNames.add("PermissionId"); 253 fieldNames = Collections.unmodifiableList(fieldNames); 254 } 255 return fieldNames; 256 } 257 258 264 public Object getByName(String name) 265 { 266 if (name.equals("RoleId")) 267 { 268 return getRoleId(); 269 } 270 if (name.equals("PermissionId")) 271 { 272 return getPermissionId(); 273 } 274 return null; 275 } 276 277 285 public Object getByPeerName(String name) 286 { 287 if (name.equals(TurbineRolePermissionPeer.ROLE_ID)) 288 { 289 return getRoleId(); 290 } 291 if (name.equals(TurbineRolePermissionPeer.PERMISSION_ID)) 292 { 293 return getPermissionId(); 294 } 295 return null; 296 } 297 298 305 public Object getByPosition(int pos) 306 { 307 if (pos == 0) 308 { 309 return getRoleId(); 310 } 311 if (pos == 1) 312 { 313 return getPermissionId(); 314 } 315 return null; 316 } 317 318 324 public void save() throws Exception 325 { 326 save(TurbineRolePermissionPeer.getMapBuilder() 327 .getDatabaseMap().getName()); 328 } 329 330 340 public void save(String dbName) throws TorqueException 341 { 342 Connection con = null; 343 try 344 { 345 con = Transaction.begin(dbName); 346 save(con); 347 Transaction.commit(con); 348 } 349 catch(TorqueException e) 350 { 351 Transaction.safeRollback(con); 352 throw e; 353 } 354 } 355 356 358 private boolean alreadyInSave = false; 359 369 public void save(Connection con) throws TorqueException 370 { 371 if (!alreadyInSave) 372 { 373 alreadyInSave = true; 374 375 376 377 if (isModified()) 379 { 380 if (isNew()) 381 { 382 TurbineRolePermissionPeer.doInsert((TurbineRolePermission) this, con); 383 setNew(false); 384 } 385 else 386 { 387 TurbineRolePermissionPeer.doUpdate((TurbineRolePermission) this, con); 388 } 389 } 390 391 alreadyInSave = false; 392 } 393 } 394 395 396 397 398 private final SimpleKey[] pks = new SimpleKey[2]; 399 private final ComboKey comboPK = new ComboKey(pks); 400 401 406 public void setPrimaryKey(ObjectKey key) throws TorqueException 407 { 408 SimpleKey[] keys = (SimpleKey[]) key.getValue(); 409 SimpleKey tmpKey = null; 410 setRoleId(new Integer (((NumberKey)keys[0]).intValue())); 411 setPermissionId(new Integer (((NumberKey)keys[1]).intValue())); 412 } 413 414 420 public void setPrimaryKey( Integer roleId, Integer permissionId) 421 throws TorqueException 422 { 423 setRoleId(roleId); 424 setPermissionId(permissionId); 425 } 426 427 430 public void setPrimaryKey(String key) throws TorqueException 431 { 432 setPrimaryKey(new ComboKey(key)); 433 } 434 435 439 public ObjectKey getPrimaryKey() 440 { 441 pks[0] = SimpleKey.keyFor(getRoleId()); 442 pks[1] = SimpleKey.keyFor(getPermissionId()); 443 return comboPK; 444 } 445 446 447 451 public String getQueryKey() 452 { 453 if (getPrimaryKey() == null) 454 { 455 return ""; 456 } 457 else 458 { 459 return getPrimaryKey().toString(); 460 } 461 } 462 463 467 public void setQueryKey(String key) 468 throws TorqueException 469 { 470 setPrimaryKey(key); 471 } 472 473 479 public TurbineRolePermission copy() throws TorqueException 480 { 481 return copyInto(new TurbineRolePermission()); 482 } 483 484 protected TurbineRolePermission copyInto(TurbineRolePermission copyObj) throws TorqueException 485 { 486 copyObj.setRoleId(roleId); 487 copyObj.setPermissionId(permissionId); 488 489 copyObj.setRoleId((Integer )null); 490 copyObj.setPermissionId((Integer )null); 491 492 493 return copyObj; 494 } 495 496 502 public TurbineRolePermissionPeer getPeer() 503 { 504 return peer; 505 } 506 507 public String toString() 508 { 509 StringBuffer str = new StringBuffer (); 510 str.append("TurbineRolePermission:\n"); 511 str.append("RoleId = ") 512 .append(getRoleId()) 513 .append("\n"); 514 str.append("PermissionId = ") 515 .append(getPermissionId()) 516 .append("\n"); 517 return(str.toString()); 518 } 519 } 520 | Popular Tags |