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 35 public abstract class BaseTurbineRolePermission extends BaseObject 36 { 37 38 private static final TurbineRolePermissionPeer peer = 39 new TurbineRolePermissionPeer(); 40 41 42 43 private int roleId; 44 45 46 private int permissionId; 47 48 49 53 public int getRoleId() 54 { 55 return roleId; 56 } 57 58 59 62 public void setRoleId(int v ) throws TorqueException 63 { 64 65 if (this.roleId != v) 66 { 67 this.roleId = v; 68 setModified(true); 69 } 70 71 72 if (aTurbineRole != null && !(aTurbineRole.getRoleId() == v)) 73 { 74 aTurbineRole = null; 75 } 76 77 } 78 79 80 84 public int getPermissionId() 85 { 86 return permissionId; 87 } 88 89 90 93 public void setPermissionId(int v ) throws TorqueException 94 { 95 96 if (this.permissionId != v) 97 { 98 this.permissionId = v; 99 setModified(true); 100 } 101 102 103 if (aTurbinePermission != null && !(aTurbinePermission.getPermissionId() == v)) 104 { 105 aTurbinePermission = null; 106 } 107 108 } 109 110 111 112 113 114 private TurbineRole aTurbineRole; 115 116 121 public void setTurbineRole(TurbineRole v) throws TorqueException 122 { 123 if (v == null) 124 { 125 setRoleId(0); 126 } 127 else 128 { 129 setRoleId(v.getRoleId()); 130 } 131 aTurbineRole = v; 132 } 133 134 135 public TurbineRole getTurbineRole() throws TorqueException 136 { 137 if ( getRoleId()>0 ) 138 { 139 return TurbineRoleManager.getInstance(SimpleKey.keyFor(getRoleId())); 140 } 141 return aTurbineRole; 142 } 143 144 150 public void setTurbineRoleKey(ObjectKey key) throws TorqueException 151 { 152 153 setRoleId(((NumberKey) key).intValue()); 154 } 155 156 157 158 159 private TurbinePermission aTurbinePermission; 160 161 166 public void setTurbinePermission(TurbinePermission v) throws TorqueException 167 { 168 if (v == null) 169 { 170 setPermissionId(0); 171 } 172 else 173 { 174 setPermissionId(v.getPermissionId()); 175 } 176 aTurbinePermission = v; 177 } 178 179 180 public TurbinePermission getTurbinePermission() throws TorqueException 181 { 182 if ( getPermissionId()>0 ) 183 { 184 return TurbinePermissionManager.getInstance(SimpleKey.keyFor(getPermissionId())); 185 } 186 return aTurbinePermission; 187 } 188 189 195 public void setTurbinePermissionKey(ObjectKey key) throws TorqueException 196 { 197 198 setPermissionId(((NumberKey) key).intValue()); 199 } 200 201 202 203 private static List fieldNames = null; 204 205 208 public static synchronized List getFieldNames() 209 { 210 if (fieldNames == null) 211 { 212 fieldNames = new ArrayList (); 213 fieldNames.add("RoleId"); 214 fieldNames.add("PermissionId"); 215 fieldNames = Collections.unmodifiableList(fieldNames); 216 } 217 return fieldNames; 218 } 219 220 224 public Object getByName(String name) 225 { 226 if (name.equals("RoleId")) 227 { 228 return new Integer (getRoleId()); 229 } 230 if (name.equals("PermissionId")) 231 { 232 return new Integer (getPermissionId()); 233 } 234 return null; 235 } 236 237 242 public Object getByPeerName(String name) 243 { 244 if (name.equals(TurbineRolePermissionPeer.ROLE_ID )) 245 { 246 return new Integer (getRoleId()); 247 } 248 if (name.equals(TurbineRolePermissionPeer.PERMISSION_ID )) 249 { 250 return new Integer (getPermissionId()); 251 } 252 return null; 253 } 254 255 259 public Object getByPosition(int pos) 260 { 261 if ( pos == 0 ) 262 { 263 return new Integer (getRoleId()); 264 } 265 if ( pos == 1 ) 266 { 267 return new Integer (getPermissionId()); 268 } 269 return null; 270 } 271 272 276 public void save() throws Exception 277 { 278 save(TurbineRolePermissionPeer.getMapBuilder() 279 .getDatabaseMap().getName()); 280 } 281 282 289 public void save(String dbName) throws TorqueException 290 { 291 Connection con = null; 292 try 293 { 294 con = Transaction.begin(dbName); 295 save(con); 296 Transaction.commit(con); 297 } 298 catch(TorqueException e) 299 { 300 Transaction.safeRollback(con); 301 throw e; 302 } 303 } 304 305 307 private boolean alreadyInSave = false; 308 315 public void save(Connection con) throws TorqueException 316 { 317 if (!alreadyInSave) 318 { 319 alreadyInSave = true; 320 321 322 323 if (isModified()) 325 { 326 if (isNew()) 327 { 328 TurbineRolePermissionPeer.doInsert((TurbineRolePermission)this, con); 329 setNew(false); 330 } 331 else 332 { 333 TurbineRolePermissionPeer.doUpdate((TurbineRolePermission)this, con); 334 } 335 336 if (isCacheOnSave()) 337 { 338 TurbineRolePermissionManager.putInstance(this); 339 } 340 } 341 342 alreadyInSave = false; 343 } 344 } 345 346 350 protected boolean isCacheOnSave() 351 { 352 return true; 353 } 354 355 356 357 private final SimpleKey[] pks = new SimpleKey[2]; 358 private final ComboKey comboPK = new ComboKey(pks); 359 362 public void setPrimaryKey(ObjectKey key) throws TorqueException 363 { 364 SimpleKey[] keys = (SimpleKey[]) key.getValue(); 365 SimpleKey tmpKey = null; 366 setRoleId(((NumberKey)keys[0]).intValue()); 367 setPermissionId(((NumberKey)keys[1]).intValue()); 368 } 369 370 376 public void setPrimaryKey( int roleId, int permissionId) 377 throws TorqueException 378 { 379 setRoleId(roleId); 380 setPermissionId(permissionId); 381 } 382 383 386 public void setPrimaryKey(String key) throws TorqueException 387 { 388 setPrimaryKey(new ComboKey(key)); 389 } 390 391 395 public ObjectKey getPrimaryKey() 396 { 397 pks[0] = SimpleKey.keyFor(getRoleId()); 398 pks[1] = SimpleKey.keyFor(getPermissionId()); 399 return comboPK; 400 } 401 402 403 408 public TurbineRolePermission copy() throws TorqueException 409 { 410 TurbineRolePermission copyObj = new TurbineRolePermission(); 411 copyObj.setRoleId(roleId); 412 copyObj.setPermissionId(permissionId); 413 414 copyObj.setRoleId(0); 415 copyObj.setPermissionId(0); 416 417 return copyObj; 418 } 419 420 426 public TurbineRolePermissionPeer getPeer() 427 { 428 return peer; 429 } 430 } 431 | Popular Tags |