1 package org.apache.fulcrum.security.impl.db.entity; 2 3 import java.math.BigDecimal ; 4 import java.sql.Connection ; 5 import java.sql.SQLException ; 6 import java.util.ArrayList ; 7 import java.util.Date ; 8 import java.util.Iterator ; 9 import java.util.LinkedList ; 10 import java.util.List ; 11 12 import org.apache.torque.NoRowsException; 13 import org.apache.torque.TooManyRowsException; 14 import org.apache.torque.Torque; 15 import org.apache.torque.TorqueException; 16 import org.apache.torque.map.MapBuilder; 17 import org.apache.torque.map.TableMap; 18 import org.apache.torque.om.DateKey; 19 import org.apache.torque.om.NumberKey; 20 import org.apache.torque.om.StringKey; 21 import org.apache.torque.om.ObjectKey; 22 import org.apache.torque.om.SimpleKey; 23 import org.apache.torque.util.BasePeer; 24 import org.apache.torque.util.Criteria; 25 26 import com.workingdogs.village.DataSetException; 27 import com.workingdogs.village.QueryDataSet; 28 import com.workingdogs.village.Record; 29 30 import org.apache.fulcrum.security.impl.db.entity.map.*; 32 33 34 36 public abstract class BaseTurbinePermissionPeer 37 extends BasePeer 38 { 39 40 41 public static final String DATABASE_NAME = "scarab"; 42 43 44 public static final String TABLE_NAME = "TURBINE_PERMISSION"; 45 46 51 public static MapBuilder getMapBuilder() 52 throws TorqueException 53 { 54 return getMapBuilder(TurbinePermissionMapBuilder.CLASS_NAME); 55 } 56 57 58 public static final String PERMISSION_ID; 59 60 public static final String PERMISSION_NAME; 61 62 static 63 { 64 PERMISSION_ID = "TURBINE_PERMISSION.PERMISSION_ID"; 65 PERMISSION_NAME = "TURBINE_PERMISSION.PERMISSION_NAME"; 66 if (Torque.isInit()) 67 { 68 try 69 { 70 getMapBuilder(TurbinePermissionMapBuilder.CLASS_NAME); 71 } 72 catch (Exception e) 73 { 74 log.error("Could not initialize Peer", e); 75 } 76 } 77 else 78 { 79 Torque.registerMapBuilder(TurbinePermissionMapBuilder.CLASS_NAME); 80 } 81 } 82 83 84 public static final int numColumns = 2; 85 86 87 protected static final String CLASSNAME_DEFAULT = 88 "org.apache.fulcrum.security.impl.db.entity.TurbinePermission"; 89 90 91 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 92 93 99 private static Class initClass(String className) 100 { 101 Class c = null; 102 try 103 { 104 c = Class.forName(className); 105 } 106 catch (Throwable t) 107 { 108 log.error("A FATAL ERROR has occurred which should not " 109 + "have happened under any circumstance. Please notify " 110 + "the Torque developers <torque-dev@db.apache.org> " 111 + "and give as many details as possible (including the error " 112 + "stack trace).", t); 113 114 if (t instanceof Error ) 116 { 117 throw (Error ) t.fillInStackTrace(); 118 } 119 } 120 return c; 121 } 122 123 133 public static List resultSet2Objects(java.sql.ResultSet results) 134 throws TorqueException 135 { 136 try 137 { 138 QueryDataSet qds = null; 139 List rows = null; 140 try 141 { 142 qds = new QueryDataSet(results); 143 rows = getSelectResults(qds); 144 } 145 finally 146 { 147 if (qds != null) 148 { 149 qds.close(); 150 } 151 } 152 153 return populateObjects(rows); 154 } 155 catch (SQLException e) 156 { 157 throw new TorqueException(e); 158 } 159 catch (DataSetException e) 160 { 161 throw new TorqueException(e); 162 } 163 } 164 165 166 167 174 public static ObjectKey doInsert(Criteria criteria) 175 throws TorqueException 176 { 177 return BaseTurbinePermissionPeer 178 .doInsert(criteria, (Connection ) null); 179 } 180 181 191 public static ObjectKey doInsert(Criteria criteria, Connection con) 192 throws TorqueException 193 { 194 195 if (criteria.getDbName() == Torque.getDefaultDB()) 199 { 200 criteria.setDbName(DATABASE_NAME); 201 } 202 if (con == null) 203 { 204 return BasePeer.doInsert(criteria); 205 } 206 else 207 { 208 return BasePeer.doInsert(criteria, con); 209 } 210 } 211 212 219 public static void addSelectColumns(Criteria criteria) 220 throws TorqueException 221 { 222 criteria.addSelectColumn(PERMISSION_ID); 223 criteria.addSelectColumn(PERMISSION_NAME); 224 } 225 226 235 public static TurbinePermission row2Object(Record row, 236 int offset, 237 Class cls) 238 throws TorqueException 239 { 240 try 241 { 242 TurbinePermission obj = (TurbinePermission) cls.newInstance(); 243 TurbinePermissionPeer.populateObject(row, offset, obj); 244 obj.setModified(false); 245 obj.setNew(false); 246 247 return obj; 248 } 249 catch (InstantiationException e) 250 { 251 throw new TorqueException(e); 252 } 253 catch (IllegalAccessException e) 254 { 255 throw new TorqueException(e); 256 } 257 } 258 259 268 public static void populateObject(Record row, 269 int offset, 270 TurbinePermission obj) 271 throws TorqueException 272 { 273 try 274 { 275 obj.setPermissionId(row.getValue(offset + 0).asIntegerObj()); 276 obj.setName(row.getValue(offset + 1).asString()); 277 } 278 catch (DataSetException e) 279 { 280 throw new TorqueException(e); 281 } 282 } 283 284 292 public static List doSelect(Criteria criteria) throws TorqueException 293 { 294 return populateObjects(doSelectVillageRecords(criteria)); 295 } 296 297 306 public static List doSelect(Criteria criteria, Connection con) 307 throws TorqueException 308 { 309 return populateObjects(doSelectVillageRecords(criteria, con)); 310 } 311 312 322 public static List doSelectVillageRecords(Criteria criteria) 323 throws TorqueException 324 { 325 return BaseTurbinePermissionPeer 326 .doSelectVillageRecords(criteria, (Connection ) null); 327 } 328 329 337 public static List doSelectVillageRecords(Criteria criteria, Connection con) 338 throws TorqueException 339 { 340 if (criteria.getSelectColumns().size() == 0) 341 { 342 addSelectColumns(criteria); 343 } 344 345 346 if (criteria.getDbName() == Torque.getDefaultDB()) 350 { 351 criteria.setDbName(DATABASE_NAME); 352 } 353 if (con == null) 356 { 357 return BasePeer.doSelect(criteria); 358 } 359 else 360 { 361 return BasePeer.doSelect(criteria, con); 362 } 363 } 364 365 372 public static List populateObjects(List records) 373 throws TorqueException 374 { 375 List results = new ArrayList (records.size()); 376 377 for (int i = 0; i < records.size(); i++) 379 { 380 Record row = (Record) records.get(i); 381 results.add(TurbinePermissionPeer.row2Object(row, 1, 382 TurbinePermissionPeer.getOMClass())); 383 } 384 return results; 385 } 386 387 388 396 public static Class getOMClass() 397 throws TorqueException 398 { 399 return CLASS_DEFAULT; 400 } 401 402 410 public static void doUpdate(Criteria criteria) throws TorqueException 411 { 412 BaseTurbinePermissionPeer 413 .doUpdate(criteria, (Connection ) null); 414 } 415 416 427 public static void doUpdate(Criteria criteria, Connection con) 428 throws TorqueException 429 { 430 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 431 selectCriteria.put(PERMISSION_ID, criteria.remove(PERMISSION_ID)); 432 433 if (criteria.getDbName() == Torque.getDefaultDB()) 437 { 438 criteria.setDbName(DATABASE_NAME); 439 } 440 if (con == null) 441 { 442 BasePeer.doUpdate(selectCriteria, criteria); 443 } 444 else 445 { 446 BasePeer.doUpdate(selectCriteria, criteria, con); 447 } 448 } 449 450 457 public static void doDelete(Criteria criteria) throws TorqueException 458 { 459 BaseTurbinePermissionPeer 460 .doDelete(criteria, (Connection ) null); 461 } 462 463 473 public static void doDelete(Criteria criteria, Connection con) 474 throws TorqueException 475 { 476 477 if (criteria.getDbName() == Torque.getDefaultDB()) 481 { 482 criteria.setDbName(DATABASE_NAME); 483 } 484 if (con == null) 485 { 486 BasePeer.doDelete(criteria); 487 } 488 else 489 { 490 BasePeer.doDelete(criteria, con); 491 } 492 } 493 494 500 public static List doSelect(TurbinePermission obj) throws TorqueException 501 { 502 return doSelect(buildCriteria(obj)); 503 } 504 505 511 public static void doInsert(TurbinePermission obj) throws TorqueException 512 { 513 obj.setPrimaryKey(doInsert(buildCriteria(obj))); 514 obj.setNew(false); 515 obj.setModified(false); 516 } 517 518 523 public static void doUpdate(TurbinePermission obj) throws TorqueException 524 { 525 doUpdate(buildCriteria(obj)); 526 obj.setModified(false); 527 } 528 529 534 public static void doDelete(TurbinePermission obj) throws TorqueException 535 { 536 doDelete(buildCriteria(obj)); 537 } 538 539 549 public static void doInsert(TurbinePermission obj, Connection con) 550 throws TorqueException 551 { 552 obj.setPrimaryKey(doInsert(buildCriteria(obj), con)); 553 obj.setNew(false); 554 obj.setModified(false); 555 } 556 557 567 public static void doUpdate(TurbinePermission obj, Connection con) 568 throws TorqueException 569 { 570 doUpdate(buildCriteria(obj), con); 571 obj.setModified(false); 572 } 573 574 584 public static void doDelete(TurbinePermission obj, Connection con) 585 throws TorqueException 586 { 587 doDelete(buildCriteria(obj), con); 588 } 589 590 597 public static void doDelete(ObjectKey pk) throws TorqueException 598 { 599 BaseTurbinePermissionPeer 600 .doDelete(pk, (Connection ) null); 601 } 602 603 613 public static void doDelete(ObjectKey pk, Connection con) 614 throws TorqueException 615 { 616 doDelete(buildCriteria(pk), con); 617 } 618 619 620 public static Criteria buildCriteria( ObjectKey pk ) 621 { 622 Criteria criteria = new Criteria(); 623 criteria.add(PERMISSION_ID, pk); 624 return criteria; 625 } 626 627 628 public static Criteria buildCriteria( TurbinePermission obj ) 629 { 630 Criteria criteria = new Criteria(DATABASE_NAME); 631 if (!obj.isNew()) 632 criteria.add(PERMISSION_ID, obj.getPermissionId()); 633 criteria.add(PERMISSION_NAME, obj.getName()); 634 return criteria; 635 } 636 637 638 647 public static TurbinePermission retrieveByPK(Integer pk) 648 throws TorqueException, NoRowsException, TooManyRowsException 649 { 650 return retrieveByPK(SimpleKey.keyFor(pk)); 651 } 652 653 662 public static TurbinePermission retrieveByPK(ObjectKey pk) 663 throws TorqueException, NoRowsException, TooManyRowsException 664 { 665 Connection db = null; 666 TurbinePermission retVal = null; 667 try 668 { 669 db = Torque.getConnection(DATABASE_NAME); 670 retVal = retrieveByPK(pk, db); 671 } 672 finally 673 { 674 Torque.closeConnection(db); 675 } 676 return(retVal); 677 } 678 679 689 public static TurbinePermission retrieveByPK(ObjectKey pk, Connection con) 690 throws TorqueException, NoRowsException, TooManyRowsException 691 { 692 Criteria criteria = buildCriteria(pk); 693 List v = doSelect(criteria, con); 694 if (v.size() == 0) 695 { 696 throw new NoRowsException("Failed to select a row."); 697 } 698 else if (v.size() > 1) 699 { 700 throw new TooManyRowsException("Failed to select only one row."); 701 } 702 else 703 { 704 return (TurbinePermission)v.get(0); 705 } 706 } 707 708 715 public static List retrieveByPKs(List pks) 716 throws TorqueException 717 { 718 Connection db = null; 719 List retVal = null; 720 try 721 { 722 db = Torque.getConnection(DATABASE_NAME); 723 retVal = retrieveByPKs(pks, db); 724 } 725 finally 726 { 727 Torque.closeConnection(db); 728 } 729 return(retVal); 730 } 731 732 740 public static List retrieveByPKs( List pks, Connection dbcon ) 741 throws TorqueException 742 { 743 List objs = null; 744 if (pks == null || pks.size() == 0) 745 { 746 objs = new LinkedList (); 747 } 748 else 749 { 750 Criteria criteria = new Criteria(); 751 criteria.addIn( PERMISSION_ID, pks ); 752 objs = doSelect(criteria, dbcon); 753 } 754 return objs; 755 } 756 757 758 759 760 761 762 763 764 765 766 773 protected static TableMap getTableMap() 774 throws TorqueException 775 { 776 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 777 } 778 } 779 | Popular Tags |