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 36 public abstract class BaseTurbineRolePermission extends BaseObject 37 implements org.apache.turbine.om.Retrievable 38 { 39 40 private static final TurbineRolePermissionPeer peer = 41 new TurbineRolePermissionPeer(); 42 43 44 45 private int roleId; 46 47 48 private int permissionId; 49 50 51 56 public int getRoleId() 57 { 58 return roleId; 59 } 60 61 62 67 public void setRoleId(int v) throws TorqueException 68 { 69 70 if (this.roleId != v) 71 { 72 this.roleId = v; 73 setModified(true); 74 } 75 76 77 if (aTurbineRole != null && !(aTurbineRole.getRoleId() == v)) 78 { 79 aTurbineRole = null; 80 } 81 82 } 83 84 89 public int getPermissionId() 90 { 91 return permissionId; 92 } 93 94 95 100 public void setPermissionId(int v) throws TorqueException 101 { 102 103 if (this.permissionId != v) 104 { 105 this.permissionId = v; 106 setModified(true); 107 } 108 109 110 if (aTurbinePermission != null && !(aTurbinePermission.getPermissionId() == v)) 111 { 112 aTurbinePermission = null; 113 } 114 115 } 116 117 118 119 120 121 private TurbineRole aTurbineRole; 122 123 129 public void setTurbineRole(TurbineRole v) throws TorqueException 130 { 131 if (v == null) 132 { 133 setRoleId( 0); 134 } 135 else 136 { 137 setRoleId(v.getRoleId()); 138 } 139 aTurbineRole = v; 140 } 141 142 143 149 public TurbineRole getTurbineRole() throws TorqueException 150 { 151 if (aTurbineRole == null && (this.roleId != 0)) 152 { 153 aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId)); 154 155 164 } 165 return aTurbineRole; 166 } 167 168 174 public void setTurbineRoleKey(ObjectKey key) throws TorqueException 175 { 176 177 setRoleId(((NumberKey) key).intValue()); 178 } 179 180 181 182 183 private TurbinePermission aTurbinePermission; 184 185 191 public void setTurbinePermission(TurbinePermission v) throws TorqueException 192 { 193 if (v == null) 194 { 195 setPermissionId( 0); 196 } 197 else 198 { 199 setPermissionId(v.getPermissionId()); 200 } 201 aTurbinePermission = v; 202 } 203 204 205 211 public TurbinePermission getTurbinePermission() throws TorqueException 212 { 213 if (aTurbinePermission == null && (this.permissionId != 0)) 214 { 215 aTurbinePermission = TurbinePermissionPeer.retrieveByPK(SimpleKey.keyFor(this.permissionId)); 216 217 226 } 227 return aTurbinePermission; 228 } 229 230 236 public void setTurbinePermissionKey(ObjectKey key) throws TorqueException 237 { 238 239 setPermissionId(((NumberKey) key).intValue()); 240 } 241 242 243 private static List fieldNames = null; 244 245 250 public static synchronized List getFieldNames() 251 { 252 if (fieldNames == null) 253 { 254 fieldNames = new ArrayList (); 255 fieldNames.add("RoleId"); 256 fieldNames.add("PermissionId"); 257 fieldNames = Collections.unmodifiableList(fieldNames); 258 } 259 return fieldNames; 260 } 261 262 268 public Object getByName(String name) 269 { 270 if (name.equals("RoleId")) 271 { 272 return new Integer (getRoleId()); 273 } 274 if (name.equals("PermissionId")) 275 { 276 return new Integer (getPermissionId()); 277 } 278 return null; 279 } 280 281 289 public Object getByPeerName(String name) 290 { 291 if (name.equals(TurbineRolePermissionPeer.ROLE_ID)) 292 { 293 return new Integer (getRoleId()); 294 } 295 if (name.equals(TurbineRolePermissionPeer.PERMISSION_ID)) 296 { 297 return new Integer (getPermissionId()); 298 } 299 return null; 300 } 301 302 309 public Object getByPosition(int pos) 310 { 311 if (pos == 0) 312 { 313 return new Integer (getRoleId()); 314 } 315 if (pos == 1) 316 { 317 return new Integer (getPermissionId()); 318 } 319 return null; 320 } 321 322 328 public void save() throws Exception  329 { 330 save(TurbineRolePermissionPeer.getMapBuilder() 331 .getDatabaseMap().getName()); 332 } 333 334 344 public void save(String dbName) throws TorqueException 345 { 346 Connection con = null; 347 try 348 { 349 con = Transaction.begin(dbName); 350 save(con); 351 Transaction.commit(con); 352 } 353 catch(TorqueException e) 354 { 355 Transaction.safeRollback(con); 356 throw e; 357 } 358 } 359 360 362 private boolean alreadyInSave = false; 363 373 public void save(Connection con) throws TorqueException 374 { 375 if (!alreadyInSave) 376 { 377 alreadyInSave = true; 378 379 380 381 if (isModified()) 383 { 384 if (isNew()) 385 { 386 TurbineRolePermissionPeer.doInsert((TurbineRolePermission) this, con); 387 setNew(false); 388 } 389 else 390 { 391 TurbineRolePermissionPeer.doUpdate((TurbineRolePermission) this, con); 392 } 393 } 394 395 alreadyInSave = false; 396 } 397 } 398 399 400 401 private final SimpleKey[] pks = new SimpleKey[2]; 402 private final ComboKey comboPK = new ComboKey(pks); 403 404 409 public void setPrimaryKey(ObjectKey key) throws TorqueException 410 { 411 SimpleKey[] keys = (SimpleKey[]) key.getValue(); 412 SimpleKey tmpKey = null; 413 setRoleId(((NumberKey)keys[0]).intValue()); 414 setPermissionId(((NumberKey)keys[1]).intValue()); 415 } 416 417 423 public void setPrimaryKey( int roleId, int permissionId) 424 throws TorqueException 425 { 426 setRoleId(roleId); 427 setPermissionId(permissionId); 428 } 429 430 433 public void setPrimaryKey(String key) throws TorqueException 434 { 435 setPrimaryKey(new ComboKey(key)); 436 } 437 438 442 public ObjectKey getPrimaryKey() 443 { 444 pks[0] = SimpleKey.keyFor(getRoleId()); 445 pks[1] = SimpleKey.keyFor(getPermissionId()); 446 return comboPK; 447 } 448 449 453 public String getQueryKey() 454 { 455 if (getPrimaryKey() == null) 456 { 457 return ""; 458 } 459 else 460 { 461 return getPrimaryKey().toString(); 462 } 463 } 464 465 469 public void setQueryKey(String key) 470 throws TorqueException 471 { 472 setPrimaryKey(key); 473 } 474 475 481 public TurbineRolePermission copy() throws TorqueException 482 { 483 return copyInto(new TurbineRolePermission()); 484 } 485 486 protected TurbineRolePermission copyInto(TurbineRolePermission copyObj) throws TorqueException 487 { 488 copyObj.setRoleId(roleId); 489 copyObj.setPermissionId(permissionId); 490 491 copyObj.setRoleId( 0); 492 copyObj.setPermissionId( 0); 493 494 return copyObj; 495 } 496 497 503 public TurbineRolePermissionPeer getPeer() 504 { 505 return peer; 506 } 507 508 public String toString() 509 { 510 StringBuffer str = new StringBuffer (); 511 str.append("TurbineRolePermission:\n"); 512 str.append("RoleId = ") 513 .append(getRoleId()) 514 .append("\n"); 515 str.append("PermissionId = ") 516 .append(getPermissionId()) 517 .append("\n"); 518 return(str.toString()); 519 } 520 } 521
| Popular Tags
|