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 30 public abstract class BaseTurbinePermission extends BaseObject 31 implements org.apache.fulcrum.intake.Retrievable 32 { 33 34 private static final TurbinePermissionPeer peer = 35 new TurbinePermissionPeer(); 36 37 38 39 private Integer permissionId; 40 41 42 private String name; 43 44 45 50 public Integer getPermissionId() 51 { 52 return permissionId; 53 } 54 55 56 61 public void setPermissionId(Integer v) throws TorqueException 62 { 63 64 if (!ObjectUtils.equals(this.permissionId, v)) 65 { 66 this.permissionId = v; 67 setModified(true); 68 } 69 70 71 72 if (collTurbineRolePermissions != null) 74 { 75 for (int i = 0; i < collTurbineRolePermissions.size(); i++) 76 { 77 ((TurbineRolePermission) collTurbineRolePermissions.get(i)) 78 .setPermissionId(v); 79 } 80 } 81 } 82 83 88 public String getName() 89 { 90 return name; 91 } 92 93 94 99 public void setName(String v) 100 { 101 102 if (!ObjectUtils.equals(this.name, v)) 103 { 104 this.name = v; 105 setModified(true); 106 } 107 108 109 } 110 111 112 113 114 117 protected List collTurbineRolePermissions; 118 119 124 protected void initTurbineRolePermissions() 125 { 126 if (collTurbineRolePermissions == null) 127 { 128 collTurbineRolePermissions = new ArrayList (); 129 } 130 } 131 132 139 public void addTurbineRolePermission(TurbineRolePermission l) throws TorqueException 140 { 141 getTurbineRolePermissions().add(l); 142 l.setTurbinePermission((TurbinePermission) this); 143 } 144 145 148 private Criteria lastTurbineRolePermissionsCriteria = null; 149 150 157 public List getTurbineRolePermissions() throws TorqueException 158 { 159 if (collTurbineRolePermissions == null) 160 { 161 collTurbineRolePermissions = getTurbineRolePermissions(new Criteria(10)); 162 } 163 return collTurbineRolePermissions; 164 } 165 166 177 public List getTurbineRolePermissions(Criteria criteria) throws TorqueException 178 { 179 if (collTurbineRolePermissions == null) 180 { 181 if (isNew()) 182 { 183 collTurbineRolePermissions = new ArrayList (); 184 } 185 else 186 { 187 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId() ); 188 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria); 189 } 190 } 191 else 192 { 193 if (!isNew()) 195 { 196 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId()); 200 if (!lastTurbineRolePermissionsCriteria.equals(criteria)) 201 { 202 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria); 203 } 204 } 205 } 206 lastTurbineRolePermissionsCriteria = criteria; 207 208 return collTurbineRolePermissions; 209 } 210 211 219 public List getTurbineRolePermissions(Connection con) throws TorqueException 220 { 221 if (collTurbineRolePermissions == null) 222 { 223 collTurbineRolePermissions = getTurbineRolePermissions(new Criteria(10), con); 224 } 225 return collTurbineRolePermissions; 226 } 227 228 240 public List getTurbineRolePermissions(Criteria criteria, Connection con) 241 throws TorqueException 242 { 243 if (collTurbineRolePermissions == null) 244 { 245 if (isNew()) 246 { 247 collTurbineRolePermissions = new ArrayList (); 248 } 249 else 250 { 251 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId()); 252 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria, con); 253 } 254 } 255 else 256 { 257 if (!isNew()) 259 { 260 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId()); 264 if (!lastTurbineRolePermissionsCriteria.equals(criteria)) 265 { 266 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelect(criteria, con); 267 } 268 } 269 } 270 lastTurbineRolePermissionsCriteria = criteria; 271 272 return collTurbineRolePermissions; 273 } 274 275 276 277 278 279 280 281 282 283 284 285 296 protected List getTurbineRolePermissionsJoinTurbineRole(Criteria criteria) 297 throws TorqueException 298 { 299 if (collTurbineRolePermissions == null) 300 { 301 if (isNew()) 302 { 303 collTurbineRolePermissions = new ArrayList (); 304 } 305 else 306 { 307 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId()); 308 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbineRole(criteria); 309 } 310 } 311 else 312 { 313 boolean newCriteria = true; 317 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId()); 318 if (!lastTurbineRolePermissionsCriteria.equals(criteria)) 319 { 320 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbineRole(criteria); 321 } 322 } 323 lastTurbineRolePermissionsCriteria = criteria; 324 325 return collTurbineRolePermissions; 326 } 327 328 329 330 331 332 333 334 335 336 347 protected List getTurbineRolePermissionsJoinTurbinePermission(Criteria criteria) 348 throws TorqueException 349 { 350 if (collTurbineRolePermissions == null) 351 { 352 if (isNew()) 353 { 354 collTurbineRolePermissions = new ArrayList (); 355 } 356 else 357 { 358 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId()); 359 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbinePermission(criteria); 360 } 361 } 362 else 363 { 364 boolean newCriteria = true; 368 criteria.add(TurbineRolePermissionPeer.PERMISSION_ID, getPermissionId()); 369 if (!lastTurbineRolePermissionsCriteria.equals(criteria)) 370 { 371 collTurbineRolePermissions = TurbineRolePermissionPeer.doSelectJoinTurbinePermission(criteria); 372 } 373 } 374 lastTurbineRolePermissionsCriteria = criteria; 375 376 return collTurbineRolePermissions; 377 } 378 379 380 381 382 private static List fieldNames = null; 383 384 389 public static synchronized List getFieldNames() 390 { 391 if (fieldNames == null) 392 { 393 fieldNames = new ArrayList (); 394 fieldNames.add("PermissionId"); 395 fieldNames.add("Name"); 396 fieldNames = Collections.unmodifiableList(fieldNames); 397 } 398 return fieldNames; 399 } 400 401 407 public Object getByName(String name) 408 { 409 if (name.equals("PermissionId")) 410 { 411 return getPermissionId(); 412 } 413 if (name.equals("Name")) 414 { 415 return getName(); 416 } 417 return null; 418 } 419 420 428 public Object getByPeerName(String name) 429 { 430 if (name.equals(TurbinePermissionPeer.PERMISSION_ID)) 431 { 432 return getPermissionId(); 433 } 434 if (name.equals(TurbinePermissionPeer.PERMISSION_NAME)) 435 { 436 return getName(); 437 } 438 return null; 439 } 440 441 448 public Object getByPosition(int pos) 449 { 450 if (pos == 0) 451 { 452 return getPermissionId(); 453 } 454 if (pos == 1) 455 { 456 return getName(); 457 } 458 return null; 459 } 460 461 467 public void save() throws Exception 468 { 469 save(TurbinePermissionPeer.getMapBuilder() 470 .getDatabaseMap().getName()); 471 } 472 473 483 public void save(String dbName) throws TorqueException 484 { 485 Connection con = null; 486 try 487 { 488 con = Transaction.begin(dbName); 489 save(con); 490 Transaction.commit(con); 491 } 492 catch(TorqueException e) 493 { 494 Transaction.safeRollback(con); 495 throw e; 496 } 497 } 498 499 501 private boolean alreadyInSave = false; 502 512 public void save(Connection con) throws TorqueException 513 { 514 if (!alreadyInSave) 515 { 516 alreadyInSave = true; 517 518 519 520 if (isModified()) 522 { 523 if (isNew()) 524 { 525 TurbinePermissionPeer.doInsert((TurbinePermission) this, con); 526 setNew(false); 527 } 528 else 529 { 530 TurbinePermissionPeer.doUpdate((TurbinePermission) this, con); 531 } 532 } 533 534 535 536 if (collTurbineRolePermissions != null) 537 { 538 for (int i = 0; i < collTurbineRolePermissions.size(); i++) 539 { 540 ((TurbineRolePermission) collTurbineRolePermissions.get(i)).save(con); 541 } 542 } 543 alreadyInSave = false; 544 } 545 } 546 547 548 549 554 public void setPrimaryKey(ObjectKey key) 555 throws TorqueException 556 { 557 setPermissionId(new Integer (((NumberKey) key).intValue())); 558 } 559 560 565 public void setPrimaryKey(String key) throws TorqueException 566 { 567 setPermissionId(new Integer (key)); 568 } 569 570 571 575 public ObjectKey getPrimaryKey() 576 { 577 return SimpleKey.keyFor(getPermissionId()); 578 } 579 580 581 585 public String getQueryKey() 586 { 587 if (getPrimaryKey() == null) 588 { 589 return ""; 590 } 591 else 592 { 593 return getPrimaryKey().toString(); 594 } 595 } 596 597 601 public void setQueryKey(String key) 602 throws TorqueException 603 { 604 setPrimaryKey(key); 605 } 606 607 613 public TurbinePermission copy() throws TorqueException 614 { 615 return copyInto(new TurbinePermission()); 616 } 617 618 protected TurbinePermission copyInto(TurbinePermission copyObj) throws TorqueException 619 { 620 copyObj.setPermissionId(permissionId); 621 copyObj.setName(name); 622 623 copyObj.setPermissionId((Integer )null); 624 625 626 627 List v = getTurbineRolePermissions(); 628 for (int i = 0; i < v.size(); i++) 629 { 630 TurbineRolePermission obj = (TurbineRolePermission) v.get(i); 631 copyObj.addTurbineRolePermission(obj.copy()); 632 } 633 634 return copyObj; 635 } 636 637 643 public TurbinePermissionPeer getPeer() 644 { 645 return peer; 646 } 647 648 public String toString() 649 { 650 StringBuffer str = new StringBuffer (); 651 str.append("TurbinePermission:\n"); 652 str.append("PermissionId = ") 653 .append(getPermissionId()) 654 .append("\n"); 655 str.append("Name = ") 656 .append(getName()) 657 .append("\n"); 658 return(str.toString()); 659 } 660 } 661 | Popular Tags |