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 33 public abstract class BaseTurbinePermission extends BaseObject 34 { 35 36 private static final TurbinePermissionPeer peer = 37 new TurbinePermissionPeer(); 38 39 40 41 private int permissionId; 42 43 44 private String permissionName; 45 46 47 private byte[] objectdata; 48 49 50 54 public int getPermissionId() 55 { 56 return permissionId; 57 } 58 59 60 63 public void setPermissionId(int v ) throws TorqueException 64 { 65 66 if (this.permissionId != v) 67 { 68 this.permissionId = v; 69 setModified(true); 70 } 71 72 73 74 if (collTurbineRolePermissions != null ) 76 { 77 for (int i = 0; i < collTurbineRolePermissions.size(); i++) 78 { 79 ((TurbineRolePermission)collTurbineRolePermissions.get(i)) 80 .setPermissionId(v); 81 } 82 } 83 } 84 85 86 90 public String getPermissionName() 91 { 92 return permissionName; 93 } 94 95 96 99 public void setPermissionName(String v ) 100 { 101 102 if (!ObjectUtils.equals(this.permissionName, v)) 103 { 104 this.permissionName = v; 105 setModified(true); 106 } 107 108 109 } 110 111 112 116 public byte[] getObjectdata() 117 { 118 return objectdata; 119 } 120 121 122 125 public void setObjectdata(byte[] v ) 126 { 127 128 if (!ObjectUtils.equals(this.objectdata, v)) 129 { 130 this.objectdata = v; 131 setModified(true); 132 } 133 134 135 } 136 137 138 139 140 141 144 protected List collTurbineRolePermissions; 145 146 151 protected void initTurbineRolePermissions() 152 { 153 if (collTurbineRolePermissions == null) 154 { 155 collTurbineRolePermissions = new ArrayList (); 156 } 157 } 158 159 160 166 public void addTurbineRolePermission(TurbineRolePermission l) throws TorqueException 167 { 168 getTurbineRolePermissions().add(l); 169 l.setTurbinePermission((TurbinePermission)this); 170 } 171 172 175 private Criteria lastTurbineRolePermissionsCriteria = null; 176 177 182 public List getTurbineRolePermissions() throws TorqueException 183 { 184 if (collTurbineRolePermissions == null) 185 { 186 collTurbineRolePermissions = getTurbineRolePermissions(new Criteria(10)); 187 } 188 return collTurbineRolePermissions; 189 } 190 191 200 public List getTurbineRolePermissions(Criteria criteria) throws TorqueException 201 { 202 if (collTurbineRolePermissions == null) 203 { 204 if (isNew()) 205 { 206 collTurbineRolePermissions = new ArrayList (); 207 } 208 else 209 { 210 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() ); 211 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria); 212 } 213 } 214 else 215 { 216 if (!isNew()) 218 { 219 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() ); 223 if (!lastTurbineRolePermissionsCriteria.equals(criteria)) 224 { 225 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria); 226 } 227 } 228 } 229 lastTurbineRolePermissionsCriteria = criteria; 230 231 return collTurbineRolePermissions; 232 } 233 234 242 public List getTurbineRolePermissions(Connection con) throws TorqueException 243 { 244 if (collTurbineRolePermissions == null) 245 { 246 collTurbineRolePermissions = getTurbineRolePermissions(new Criteria(10),con); 247 } 248 return collTurbineRolePermissions; 249 } 250 251 263 public List getTurbineRolePermissions(Criteria criteria,Connection con) throws TorqueException 264 { 265 if (collTurbineRolePermissions == null) 266 { 267 if (isNew()) 268 { 269 collTurbineRolePermissions = new ArrayList (); 270 } 271 else 272 { 273 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() ); 274 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria,con); 275 } 276 } 277 else 278 { 279 if (!isNew()) 281 { 282 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() ); 286 if (!lastTurbineRolePermissionsCriteria.equals(criteria)) 287 { 288 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria,con); 289 } 290 } 291 } 292 lastTurbineRolePermissionsCriteria = criteria; 293 294 return collTurbineRolePermissions; 295 } 296 297 298 299 300 301 302 303 304 305 306 307 308 319 protected List getTurbineRolePermissionsJoinTurbineRole(Criteria criteria) 320 throws TorqueException 321 { 322 if (collTurbineRolePermissions == null) 323 { 324 if (isNew()) 325 { 326 collTurbineRolePermissions = new ArrayList (); 327 } 328 else 329 { 330 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() ); 331 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbineRole(criteria); 332 } 333 } 334 else 335 { 336 boolean newCriteria = true; 340 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() ); 341 if (!lastTurbineRolePermissionsCriteria.equals(criteria)) 342 { 343 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbineRole(criteria); 344 } 345 } 346 lastTurbineRolePermissionsCriteria = criteria; 347 348 return collTurbineRolePermissions; 349 } 350 351 352 353 354 355 356 357 358 359 370 protected List getTurbineRolePermissionsJoinTurbinePermission(Criteria criteria) 371 throws TorqueException 372 { 373 if (collTurbineRolePermissions == null) 374 { 375 if (isNew()) 376 { 377 collTurbineRolePermissions = new ArrayList (); 378 } 379 else 380 { 381 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() ); 382 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbinePermission(criteria); 383 } 384 } 385 else 386 { 387 boolean newCriteria = true; 391 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() ); 392 if (!lastTurbineRolePermissionsCriteria.equals(criteria)) 393 { 394 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbinePermission(criteria); 395 } 396 } 397 lastTurbineRolePermissionsCriteria = criteria; 398 399 return collTurbineRolePermissions; 400 } 401 402 403 404 405 private static List fieldNames = null; 406 407 410 public static synchronized List getFieldNames() 411 { 412 if (fieldNames == null) 413 { 414 fieldNames = new ArrayList (); 415 fieldNames.add("PermissionId"); 416 fieldNames.add("PermissionName"); 417 fieldNames.add("Objectdata"); 418 fieldNames = Collections.unmodifiableList(fieldNames); 419 } 420 return fieldNames; 421 } 422 423 427 public Object getByName(String name) 428 { 429 if (name.equals("PermissionId")) 430 { 431 return new Integer (getPermissionId()); 432 } 433 if (name.equals("PermissionName")) 434 { 435 return getPermissionName(); 436 } 437 if (name.equals("Objectdata")) 438 { 439 return getObjectdata(); 440 } 441 return null; 442 } 443 444 449 public Object getByPeerName(String name) 450 { 451 if (name.equals(TurbinePermissionPeer.PERMISSION_ID )) 452 { 453 return new Integer (getPermissionId()); 454 } 455 if (name.equals(TurbinePermissionPeer.PERMISSION_NAME )) 456 { 457 return getPermissionName(); 458 } 459 if (name.equals(TurbinePermissionPeer.OBJECTDATA )) 460 { 461 return getObjectdata(); 462 } 463 return null; 464 } 465 466 470 public Object getByPosition(int pos) 471 { 472 if ( pos == 0 ) 473 { 474 return new Integer (getPermissionId()); 475 } 476 if ( pos == 1 ) 477 { 478 return getPermissionName(); 479 } 480 if ( pos == 2 ) 481 { 482 return getObjectdata(); 483 } 484 return null; 485 } 486 487 491 public void save() throws Exception 492 { 493 save(TurbinePermissionPeer.getMapBuilder() 494 .getDatabaseMap().getName()); 495 } 496 497 504 public void save(String dbName) throws TorqueException 505 { 506 Connection con = null; 507 try 508 { 509 con = Transaction.begin(dbName); 510 save(con); 511 Transaction.commit(con); 512 } 513 catch(TorqueException e) 514 { 515 Transaction.safeRollback(con); 516 throw e; 517 } 518 } 519 520 522 private boolean alreadyInSave = false; 523 530 public void save(Connection con) throws TorqueException 531 { 532 if (!alreadyInSave) 533 { 534 alreadyInSave = true; 535 536 537 538 if (isModified()) 540 { 541 if (isNew()) 542 { 543 TurbinePermissionPeer.doInsert((TurbinePermission)this, con); 544 setNew(false); 545 } 546 else 547 { 548 TurbinePermissionPeer.doUpdate((TurbinePermission)this, con); 549 } 550 551 if (isCacheOnSave()) 552 { 553 TurbinePermissionManager.putInstance(this); 554 } 555 } 556 557 558 if (collTurbineRolePermissions != null ) 559 { 560 for (int i = 0; i < collTurbineRolePermissions.size(); i++) 561 { 562 ((TurbineRolePermission)collTurbineRolePermissions.get(i)).save(con); 563 } 564 } 565 alreadyInSave = false; 566 } 567 } 568 569 573 protected boolean isCacheOnSave() 574 { 575 return true; 576 } 577 578 579 584 public void setPrimaryKey(ObjectKey permissionId) 585 throws TorqueException { 586 setPermissionId(((NumberKey)permissionId).intValue()); 587 } 588 589 592 public void setPrimaryKey(String key) throws TorqueException 593 { 594 setPermissionId(Integer.parseInt(key)); 595 } 596 597 598 602 public ObjectKey getPrimaryKey() 603 { 604 return SimpleKey.keyFor(getPermissionId()); 605 } 606 607 608 613 public TurbinePermission copy() throws TorqueException 614 { 615 TurbinePermission copyObj = new TurbinePermission(); 616 copyObj.setPermissionId(permissionId); 617 copyObj.setPermissionName(permissionName); 618 copyObj.setObjectdata(objectdata); 619 620 copyObj.setPermissionId(0); 621 622 623 624 List v = getTurbineRolePermissions(); 625 for (int i = 0; i < v.size(); i++) 626 { 627 TurbineRolePermission obj = (TurbineRolePermission) v.get(i); 628 copyObj.addTurbineRolePermission(obj.copy()); 629 } 630 return copyObj; 631 } 632 633 639 public TurbinePermissionPeer getPeer() 640 { 641 return peer; 642 } 643 } 644 | Popular Tags |