001 package org.apache.turbine.services.security.torque.om; 002 003 import java.math.BigDecimal; 004 import java.sql.Connection; 005 import java.sql.SQLException; 006 import java.util.ArrayList; 007 import java.util.Date; 008 import java.util.Iterator; 009 import java.util.LinkedList; 010 import java.util.List; 011 012 import org.apache.torque.NoRowsException; 013 import org.apache.torque.TooManyRowsException; 014 import org.apache.torque.Torque; 015 import org.apache.torque.TorqueException; 016 import org.apache.torque.TorqueRuntimeException; 017 import org.apache.torque.map.MapBuilder; 018 import org.apache.torque.map.TableMap; 019 import org.apache.torque.om.DateKey; 020 import org.apache.torque.om.NumberKey; 021 import org.apache.torque.om.StringKey; 022 import org.apache.torque.om.ObjectKey; 023 import org.apache.torque.om.SimpleKey; 024 import org.apache.torque.util.BasePeer; 025 import org.apache.torque.util.Criteria; 026 027 import com.workingdogs.village.DataSetException; 028 import com.workingdogs.village.QueryDataSet; 029 import com.workingdogs.village.Record; 030 031 // Local classes 032 import org.apache.turbine.services.security.torque.om.map.*; 033 034 035 036 037 /** 038 * This class was autogenerated by Torque on: 039 * 040 * [Thu Jun 23 17:25:46 CEST 2011] 041 * 042 */ 043 public abstract class BaseTurbineRolePermissionPeer 044 extends BasePeer 045 { 046 /** Serial version */ 047 private static final long serialVersionUID = 1308842746584L; 048 049 050 /** the default database name for this class */ 051 public static final String DATABASE_NAME; 052 053 /** the table name for this class */ 054 public static final String TABLE_NAME; 055 056 /** 057 * @return the map builder for this peer 058 * @throws TorqueException Any exceptions caught during processing will be 059 * rethrown wrapped into a TorqueException. 060 * @deprecated Torque.getMapBuilder(TurbineRolePermissionMapBuilder.CLASS_NAME) instead 061 */ 062 public static MapBuilder getMapBuilder() 063 throws TorqueException 064 { 065 return Torque.getMapBuilder(TurbineRolePermissionMapBuilder.CLASS_NAME); 066 } 067 068 /** the column name for the ROLE_ID field */ 069 public static final String ROLE_ID; 070 /** the column name for the PERMISSION_ID field */ 071 public static final String PERMISSION_ID; 072 073 static 074 { 075 DATABASE_NAME = "default"; 076 TABLE_NAME = "TURBINE_ROLE_PERMISSION"; 077 078 ROLE_ID = "TURBINE_ROLE_PERMISSION.ROLE_ID"; 079 PERMISSION_ID = "TURBINE_ROLE_PERMISSION.PERMISSION_ID"; 080 if (Torque.isInit()) 081 { 082 try 083 { 084 Torque.getMapBuilder(TurbineRolePermissionMapBuilder.CLASS_NAME); 085 } 086 catch (TorqueException e) 087 { 088 log.error("Could not initialize Peer", e); 089 throw new TorqueRuntimeException(e); 090 } 091 } 092 else 093 { 094 Torque.registerMapBuilder(TurbineRolePermissionMapBuilder.CLASS_NAME); 095 } 096 } 097 098 /** number of columns for this peer */ 099 public static final int numColumns = 2; 100 101 /** A class that can be returned by this peer. */ 102 protected static final String CLASSNAME_DEFAULT = 103 "org.apache.turbine.services.security.torque.om.TurbineRolePermission"; 104 105 /** A class that can be returned by this peer. */ 106 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 107 108 /** 109 * Class object initialization method. 110 * 111 * @param className name of the class to initialize 112 * @return the initialized class 113 */ 114 private static Class initClass(String className) 115 { 116 Class c = null; 117 try 118 { 119 c = Class.forName(className); 120 } 121 catch (Throwable t) 122 { 123 log.error("A FATAL ERROR has occurred which should not " 124 + "have happened under any circumstance. Please notify " 125 + "the Torque developers <torque-dev@db.apache.org> " 126 + "and give as many details as possible (including the error " 127 + "stack trace).", t); 128 129 // Error objects should always be propagated. 130 if (t instanceof Error) 131 { 132 throw (Error) t.fillInStackTrace(); 133 } 134 } 135 return c; 136 } 137 138 /** 139 * Get the list of objects for a ResultSet. Please not that your 140 * resultset MUST return columns in the right order. You can use 141 * getFieldNames() in BaseObject to get the correct sequence. 142 * 143 * @param results the ResultSet 144 * @return the list of objects 145 * @throws TorqueException Any exceptions caught during processing will be 146 * rethrown wrapped into a TorqueException. 147 */ 148 public static List<TurbineRolePermission> resultSet2Objects(java.sql.ResultSet results) 149 throws TorqueException 150 { 151 try 152 { 153 QueryDataSet qds = null; 154 List<Record> rows = null; 155 try 156 { 157 qds = new QueryDataSet(results); 158 rows = getSelectResults(qds); 159 } 160 finally 161 { 162 if (qds != null) 163 { 164 qds.close(); 165 } 166 } 167 168 return populateObjects(rows); 169 } 170 catch (SQLException e) 171 { 172 throw new TorqueException(e); 173 } 174 catch (DataSetException e) 175 { 176 throw new TorqueException(e); 177 } 178 } 179 180 181 182 /** 183 * Method to do inserts. 184 * 185 * @param criteria object used to create the INSERT statement. 186 * @throws TorqueException Any exceptions caught during processing will be 187 * rethrown wrapped into a TorqueException. 188 */ 189 public static ObjectKey doInsert(Criteria criteria) 190 throws TorqueException 191 { 192 return BaseTurbineRolePermissionPeer 193 .doInsert(criteria, (Connection) null); 194 } 195 196 /** 197 * Method to do inserts. This method is to be used during a transaction, 198 * otherwise use the doInsert(Criteria) method. It will take care of 199 * the connection details internally. 200 * 201 * @param criteria object used to create the INSERT statement. 202 * @param con the connection to use 203 * @throws TorqueException Any exceptions caught during processing will be 204 * rethrown wrapped into a TorqueException. 205 */ 206 public static ObjectKey doInsert(Criteria criteria, Connection con) 207 throws TorqueException 208 { 209 correctBooleans(criteria); 210 211 setDbName(criteria); 212 213 if (con == null) 214 { 215 return BasePeer.doInsert(criteria); 216 } 217 else 218 { 219 return BasePeer.doInsert(criteria, con); 220 } 221 } 222 223 /** 224 * Add all the columns needed to create a new object. 225 * 226 * @param criteria object containing the columns to add. 227 * @throws TorqueException Any exceptions caught during processing will be 228 * rethrown wrapped into a TorqueException. 229 */ 230 public static void addSelectColumns(Criteria criteria) 231 throws TorqueException 232 { 233 criteria.addSelectColumn(ROLE_ID); 234 criteria.addSelectColumn(PERMISSION_ID); 235 } 236 237 /** 238 * changes the boolean values in the criteria to the appropriate type, 239 * whenever a booleanchar or booleanint column is involved. 240 * This enables the user to create criteria using Boolean values 241 * for booleanchar or booleanint columns 242 * @param criteria the criteria in which the boolean values should be corrected 243 * @throws TorqueException if the database map for the criteria cannot be 244 obtained. 245 */ 246 public static void correctBooleans(Criteria criteria) throws TorqueException 247 { 248 correctBooleans(criteria, getTableMap()); 249 } 250 251 /** 252 * Create a new object of type cls from a resultset row starting 253 * from a specified offset. This is done so that you can select 254 * other rows than just those needed for this object. You may 255 * for example want to create two objects from the same row. 256 * 257 * @throws TorqueException Any exceptions caught during processing will be 258 * rethrown wrapped into a TorqueException. 259 */ 260 public static TurbineRolePermission row2Object(Record row, 261 int offset, 262 Class cls) 263 throws TorqueException 264 { 265 try 266 { 267 TurbineRolePermission obj = (TurbineRolePermission) cls.newInstance(); 268 TurbineRolePermissionPeer.populateObject(row, offset, obj); 269 obj.setModified(false); 270 obj.setNew(false); 271 272 return obj; 273 } 274 catch (InstantiationException e) 275 { 276 throw new TorqueException(e); 277 } 278 catch (IllegalAccessException e) 279 { 280 throw new TorqueException(e); 281 } 282 } 283 284 /** 285 * Populates an object from a resultset row starting 286 * from a specified offset. This is done so that you can select 287 * other rows than just those needed for this object. You may 288 * for example want to create two objects from the same row. 289 * 290 * @throws TorqueException Any exceptions caught during processing will be 291 * rethrown wrapped into a TorqueException. 292 */ 293 public static void populateObject(Record row, 294 int offset, 295 TurbineRolePermission obj) 296 throws TorqueException 297 { 298 try 299 { 300 obj.setRoleId(row.getValue(offset + 0).asInt()); 301 obj.setPermissionId(row.getValue(offset + 1).asInt()); 302 } 303 catch (DataSetException e) 304 { 305 throw new TorqueException(e); 306 } 307 } 308 309 /** 310 * Method to do selects. 311 * 312 * @param criteria object used to create the SELECT statement. 313 * @return List of selected Objects 314 * @throws TorqueException Any exceptions caught during processing will be 315 * rethrown wrapped into a TorqueException. 316 */ 317 public static List<TurbineRolePermission> doSelect(Criteria criteria) throws TorqueException 318 { 319 return populateObjects(doSelectVillageRecords(criteria)); 320 } 321 322 /** 323 * Method to do selects within a transaction. 324 * 325 * @param criteria object used to create the SELECT statement. 326 * @param con the connection to use 327 * @return List of selected Objects 328 * @throws TorqueException Any exceptions caught during processing will be 329 * rethrown wrapped into a TorqueException. 330 */ 331 public static List<TurbineRolePermission> doSelect(Criteria criteria, Connection con) 332 throws TorqueException 333 { 334 return populateObjects(doSelectVillageRecords(criteria, con)); 335 } 336 337 /** 338 * Grabs the raw Village records to be formed into objects. 339 * This method handles connections internally. The Record objects 340 * returned by this method should be considered readonly. Do not 341 * alter the data and call save(), your results may vary, but are 342 * certainly likely to result in hard to track MT bugs. 343 * 344 * @throws TorqueException Any exceptions caught during processing will be 345 * rethrown wrapped into a TorqueException. 346 */ 347 public static List<Record> doSelectVillageRecords(Criteria criteria) 348 throws TorqueException 349 { 350 return BaseTurbineRolePermissionPeer 351 .doSelectVillageRecords(criteria, (Connection) null); 352 } 353 354 /** 355 * Grabs the raw Village records to be formed into objects. 356 * This method should be used for transactions 357 * 358 * @param criteria object used to create the SELECT statement. 359 * @param con the connection to use 360 * @throws TorqueException Any exceptions caught during processing will be 361 * rethrown wrapped into a TorqueException. 362 */ 363 public static List<Record> doSelectVillageRecords(Criteria criteria, Connection con) 364 throws TorqueException 365 { 366 if (criteria.getSelectColumns().size() == 0) 367 { 368 addSelectColumns(criteria); 369 } 370 correctBooleans(criteria); 371 372 setDbName(criteria); 373 374 // BasePeer returns a List of Value (Village) arrays. The array 375 // order follows the order columns were placed in the Select clause. 376 if (con == null) 377 { 378 return BasePeer.doSelect(criteria); 379 } 380 else 381 { 382 return BasePeer.doSelect(criteria, con); 383 } 384 } 385 386 /** 387 * The returned List will contain objects of the default type or 388 * objects that inherit from the default. 389 * 390 * @throws TorqueException Any exceptions caught during processing will be 391 * rethrown wrapped into a TorqueException. 392 */ 393 public static List<TurbineRolePermission> populateObjects(List<Record> records) 394 throws TorqueException 395 { 396 List<TurbineRolePermission> results = new ArrayList<TurbineRolePermission>(records.size()); 397 398 // populate the object(s) 399 for (int i = 0; i < records.size(); i++) 400 { 401 Record row = records.get(i); 402 results.add(TurbineRolePermissionPeer.row2Object(row, 1, 403 TurbineRolePermissionPeer.getOMClass())); 404 } 405 return results; 406 } 407 408 409 /** 410 * The class that the Peer will make instances of. 411 * If the BO is abstract then you must implement this method 412 * in the BO. 413 * 414 * @throws TorqueException Any exceptions caught during processing will be 415 * rethrown wrapped into a TorqueException. 416 */ 417 public static Class getOMClass() 418 throws TorqueException 419 { 420 return CLASS_DEFAULT; 421 } 422 423 /** 424 * Method to do updates. 425 * 426 * @param criteria object containing data that is used to create the UPDATE 427 * statement. 428 * @throws TorqueException Any exceptions caught during processing will be 429 * rethrown wrapped into a TorqueException. 430 */ 431 public static void doUpdate(Criteria criteria) throws TorqueException 432 { 433 BaseTurbineRolePermissionPeer 434 .doUpdate(criteria, (Connection) null); 435 } 436 437 /** 438 * Method to do updates. This method is to be used during a transaction, 439 * otherwise use the doUpdate(Criteria) method. It will take care of 440 * the connection details internally. 441 * 442 * @param criteria object containing data that is used to create the UPDATE 443 * statement. 444 * @param con the connection to use 445 * @throws TorqueException Any exceptions caught during processing will be 446 * rethrown wrapped into a TorqueException. 447 */ 448 public static void doUpdate(Criteria criteria, Connection con) 449 throws TorqueException 450 { 451 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 452 correctBooleans(criteria); 453 454 455 selectCriteria.put(ROLE_ID, criteria.remove(ROLE_ID)); 456 457 selectCriteria.put(PERMISSION_ID, criteria.remove(PERMISSION_ID)); 458 459 setDbName(criteria); 460 461 if (con == null) 462 { 463 BasePeer.doUpdate(selectCriteria, criteria); 464 } 465 else 466 { 467 BasePeer.doUpdate(selectCriteria, criteria, con); 468 } 469 } 470 471 /** 472 * Method to do deletes. 473 * 474 * @param criteria object containing data that is used DELETE from database. 475 * @throws TorqueException Any exceptions caught during processing will be 476 * rethrown wrapped into a TorqueException. 477 */ 478 public static void doDelete(Criteria criteria) throws TorqueException 479 { 480 TurbineRolePermissionPeer 481 .doDelete(criteria, (Connection) null); 482 } 483 484 /** 485 * Method to do deletes. This method is to be used during a transaction, 486 * otherwise use the doDelete(Criteria) method. It will take care of 487 * the connection details internally. 488 * 489 * @param criteria object containing data that is used DELETE from database. 490 * @param con the connection to use 491 * @throws TorqueException Any exceptions caught during processing will be 492 * rethrown wrapped into a TorqueException. 493 */ 494 public static void doDelete(Criteria criteria, Connection con) 495 throws TorqueException 496 { 497 correctBooleans(criteria); 498 499 setDbName(criteria); 500 501 if (con == null) 502 { 503 BasePeer.doDelete(criteria, TABLE_NAME); 504 } 505 else 506 { 507 BasePeer.doDelete(criteria, TABLE_NAME, con); 508 } 509 } 510 511 /** 512 * Method to do selects 513 * 514 * @throws TorqueException Any exceptions caught during processing will be 515 * rethrown wrapped into a TorqueException. 516 */ 517 public static List<TurbineRolePermission> doSelect(TurbineRolePermission obj) throws TorqueException 518 { 519 return doSelect(buildSelectCriteria(obj)); 520 } 521 522 /** 523 * Method to do inserts 524 * 525 * @throws TorqueException Any exceptions caught during processing will be 526 * rethrown wrapped into a TorqueException. 527 */ 528 public static void doInsert(TurbineRolePermission obj) throws TorqueException 529 { 530 doInsert(buildCriteria(obj)); 531 obj.setNew(false); 532 obj.setModified(false); 533 } 534 535 /** 536 * @param obj the data object to update in the database. 537 * @throws TorqueException Any exceptions caught during processing will be 538 * rethrown wrapped into a TorqueException. 539 */ 540 public static void doUpdate(TurbineRolePermission obj) throws TorqueException 541 { 542 doUpdate(buildCriteria(obj)); 543 obj.setModified(false); 544 } 545 546 /** 547 * @param obj the data object to delete in the database. 548 * @throws TorqueException Any exceptions caught during processing will be 549 * rethrown wrapped into a TorqueException. 550 */ 551 public static void doDelete(TurbineRolePermission obj) throws TorqueException 552 { 553 doDelete(buildSelectCriteria(obj)); 554 } 555 556 /** 557 * Method to do inserts. This method is to be used during a transaction, 558 * otherwise use the doInsert(TurbineRolePermission) method. It will take 559 * care of the connection details internally. 560 * 561 * @param obj the data object to insert into the database. 562 * @param con the connection to use 563 * @throws TorqueException Any exceptions caught during processing will be 564 * rethrown wrapped into a TorqueException. 565 */ 566 public static void doInsert(TurbineRolePermission obj, Connection con) 567 throws TorqueException 568 { 569 doInsert(buildCriteria(obj), con); 570 obj.setNew(false); 571 obj.setModified(false); 572 } 573 574 /** 575 * Method to do update. This method is to be used during a transaction, 576 * otherwise use the doUpdate(TurbineRolePermission) method. It will take 577 * care of the connection details internally. 578 * 579 * @param obj the data object to update in the database. 580 * @param con the connection to use 581 * @throws TorqueException Any exceptions caught during processing will be 582 * rethrown wrapped into a TorqueException. 583 */ 584 public static void doUpdate(TurbineRolePermission obj, Connection con) 585 throws TorqueException 586 { 587 doUpdate(buildCriteria(obj), con); 588 obj.setModified(false); 589 } 590 591 /** 592 * Method to delete. This method is to be used during a transaction, 593 * otherwise use the doDelete(TurbineRolePermission) method. It will take 594 * care of the connection details internally. 595 * 596 * @param obj the data object to delete in the database. 597 * @param con the connection to use 598 * @throws TorqueException Any exceptions caught during processing will be 599 * rethrown wrapped into a TorqueException. 600 */ 601 public static void doDelete(TurbineRolePermission obj, Connection con) 602 throws TorqueException 603 { 604 doDelete(buildSelectCriteria(obj), con); 605 } 606 607 /** 608 * Method to do deletes. 609 * 610 * @param pk ObjectKey that is used DELETE from database. 611 * @throws TorqueException Any exceptions caught during processing will be 612 * rethrown wrapped into a TorqueException. 613 */ 614 public static void doDelete(ObjectKey pk) throws TorqueException 615 { 616 BaseTurbineRolePermissionPeer 617 .doDelete(pk, (Connection) null); 618 } 619 620 /** 621 * Method to delete. This method is to be used during a transaction, 622 * otherwise use the doDelete(ObjectKey) method. It will take 623 * care of the connection details internally. 624 * 625 * @param pk the primary key for the object to delete in the database. 626 * @param con the connection to use 627 * @throws TorqueException Any exceptions caught during processing will be 628 * rethrown wrapped into a TorqueException. 629 */ 630 public static void doDelete(ObjectKey pk, Connection con) 631 throws TorqueException 632 { 633 doDelete(buildCriteria(pk), con); 634 } 635 636 /** Build a Criteria object from an ObjectKey */ 637 public static Criteria buildCriteria( ObjectKey pk ) 638 { 639 Criteria criteria = new Criteria(); 640 SimpleKey[] keys = (SimpleKey[])pk.getValue(); 641 criteria.add(ROLE_ID, keys[0]); 642 criteria.add(PERMISSION_ID, keys[1]); 643 return criteria; 644 } 645 646 /** Build a Criteria object from the data object for this peer */ 647 public static Criteria buildCriteria( TurbineRolePermission obj ) 648 { 649 Criteria criteria = new Criteria(DATABASE_NAME); 650 criteria.add(ROLE_ID, obj.getRoleId()); 651 criteria.add(PERMISSION_ID, obj.getPermissionId()); 652 return criteria; 653 } 654 655 /** Build a Criteria object from the data object for this peer, skipping all binary columns */ 656 public static Criteria buildSelectCriteria( TurbineRolePermission obj ) 657 { 658 Criteria criteria = new Criteria(DATABASE_NAME); 659 criteria.add(ROLE_ID, obj.getRoleId()); 660 criteria.add(PERMISSION_ID, obj.getPermissionId()); 661 return criteria; 662 } 663 664 665 666 /** 667 * Retrieve a single object by pk 668 * 669 * @param pk the primary key 670 * @throws TorqueException Any exceptions caught during processing will be 671 * rethrown wrapped into a TorqueException. 672 * @throws NoRowsException Primary key was not found in database. 673 * @throws TooManyRowsException Primary key was not found in database. 674 */ 675 public static TurbineRolePermission retrieveByPK(ObjectKey pk) 676 throws TorqueException, NoRowsException, TooManyRowsException 677 { 678 Connection db = null; 679 TurbineRolePermission retVal = null; 680 try 681 { 682 db = Torque.getConnection(DATABASE_NAME); 683 retVal = retrieveByPK(pk, db); 684 } 685 finally 686 { 687 Torque.closeConnection(db); 688 } 689 return retVal; 690 } 691 692 /** 693 * Retrieve a single object by pk 694 * 695 * @param pk the primary key 696 * @param con the connection to use 697 * @throws TorqueException Any exceptions caught during processing will be 698 * rethrown wrapped into a TorqueException. 699 * @throws NoRowsException Primary key was not found in database. 700 * @throws TooManyRowsException Primary key was not found in database. 701 */ 702 public static TurbineRolePermission retrieveByPK(ObjectKey pk, Connection con) 703 throws TorqueException, NoRowsException, TooManyRowsException 704 { 705 Criteria criteria = buildCriteria(pk); 706 List<TurbineRolePermission> v = doSelect(criteria, con); 707 if (v.size() == 0) 708 { 709 throw new NoRowsException("Failed to select a row."); 710 } 711 else if (v.size() > 1) 712 { 713 throw new TooManyRowsException("Failed to select only one row."); 714 } 715 else 716 { 717 return (TurbineRolePermission)v.get(0); 718 } 719 } 720 721 /** 722 * Retrieve a multiple objects by pk 723 * 724 * @param pks List of primary keys 725 * @throws TorqueException Any exceptions caught during processing will be 726 * rethrown wrapped into a TorqueException. 727 */ 728 public static List<TurbineRolePermission> retrieveByPKs(List<ObjectKey> pks) 729 throws TorqueException 730 { 731 Connection db = null; 732 List<TurbineRolePermission> retVal = null; 733 try 734 { 735 db = Torque.getConnection(DATABASE_NAME); 736 retVal = retrieveByPKs(pks, db); 737 } 738 finally 739 { 740 Torque.closeConnection(db); 741 } 742 return retVal; 743 } 744 745 /** 746 * Retrieve a multiple objects by pk 747 * 748 * @param pks List of primary keys 749 * @param dbcon the connection to use 750 * @throws TorqueException Any exceptions caught during processing will be 751 * rethrown wrapped into a TorqueException. 752 */ 753 public static List<TurbineRolePermission> retrieveByPKs( List<ObjectKey> pks, Connection dbcon ) 754 throws TorqueException 755 { 756 List<TurbineRolePermission> objs = null; 757 if (pks == null || pks.size() == 0) 758 { 759 objs = new LinkedList<TurbineRolePermission>(); 760 } 761 else 762 { 763 Criteria criteria = new Criteria(); 764 Iterator<ObjectKey> iter = pks.iterator(); 765 while (iter.hasNext()) 766 { 767 ObjectKey pk = iter.next(); 768 SimpleKey[] keys = (SimpleKey[])pk.getValue(); 769 Criteria.Criterion c0 = criteria.getNewCriterion( 770 ROLE_ID, keys[0], Criteria.EQUAL); 771 Criteria.Criterion c1 = criteria.getNewCriterion( 772 PERMISSION_ID, keys[1], Criteria.EQUAL); 773 c0.and(c1); 774 criteria.or(c0); 775 } 776 objs = doSelect(criteria, dbcon); 777 } 778 return objs; 779 } 780 781 782 /** 783 * retrieve object using using pk values. 784 * 785 * @param roleId int 786 * @param permissionId int 787 */ 788 public static TurbineRolePermission retrieveByPK( 789 int roleId 790 , int permissionId 791 ) throws TorqueException 792 { 793 Connection db = null; 794 TurbineRolePermission retVal = null; 795 try 796 { 797 db = Torque.getConnection(DATABASE_NAME); 798 retVal = retrieveByPK( 799 roleId 800 , permissionId 801 , db); 802 } 803 finally 804 { 805 Torque.closeConnection(db); 806 } 807 return retVal; 808 } 809 810 /** 811 * retrieve object using using pk values. 812 * 813 * @param roleId int 814 * @param permissionId int 815 * @param con Connection 816 */ 817 public static TurbineRolePermission retrieveByPK( 818 int roleId 819 , int permissionId 820 ,Connection con) throws TorqueException 821 { 822 823 Criteria criteria = new Criteria(5); 824 criteria.add(ROLE_ID, roleId); 825 criteria.add(PERMISSION_ID, permissionId); 826 List<TurbineRolePermission> v = doSelect(criteria, con); 827 if (v.size() == 1) 828 { 829 return v.get(0); 830 } 831 else 832 { 833 throw new TorqueException("Failed to select one and only one row."); 834 } 835 } 836 837 838 839 840 841 842 843 844 /** 845 * selects a collection of TurbineRolePermission objects pre-filled with their 846 * TurbineRole objects. 847 * 848 * This method is protected by default in order to keep the public 849 * api reasonable. You can provide public methods for those you 850 * actually need in TurbineRolePermissionPeer. 851 * 852 * @throws TorqueException Any exceptions caught during processing will be 853 * rethrown wrapped into a TorqueException. 854 */ 855 protected static List<TurbineRolePermission> doSelectJoinTurbineRole(Criteria criteria) 856 throws TorqueException 857 { 858 return doSelectJoinTurbineRole(criteria, null); 859 } 860 861 /** 862 * selects a collection of TurbineRolePermission objects pre-filled with their 863 * TurbineRole objects. 864 * 865 * This method is protected by default in order to keep the public 866 * api reasonable. You can provide public methods for those you 867 * actually need in TurbineRolePermissionPeer. 868 * 869 * @throws TorqueException Any exceptions caught during processing will be 870 * rethrown wrapped into a TorqueException. 871 */ 872 protected static List<TurbineRolePermission> doSelectJoinTurbineRole(Criteria criteria, Connection conn) 873 throws TorqueException 874 { 875 setDbName(criteria); 876 877 TurbineRolePermissionPeer.addSelectColumns(criteria); 878 int offset = numColumns + 1; 879 TurbineRolePeer.addSelectColumns(criteria); 880 881 criteria.addJoin(TurbineRolePermissionPeer.ROLE_ID, 882 TurbineRolePeer.ROLE_ID); 883 884 correctBooleans(criteria); 885 886 List<Record> rows; 887 if (conn == null) 888 { 889 rows = BasePeer.doSelect(criteria); 890 } 891 else 892 { 893 rows = BasePeer.doSelect(criteria,conn); 894 } 895 896 List<TurbineRolePermission> results = new ArrayList<TurbineRolePermission>(); 897 898 for (int i = 0; i < rows.size(); i++) 899 { 900 Record row = rows.get(i); 901 902 Class omClass = TurbineRolePermissionPeer.getOMClass(); 903 TurbineRolePermission obj1 = (TurbineRolePermission) TurbineRolePermissionPeer 904 .row2Object(row, 1, omClass); 905 omClass = TurbineRolePeer.getOMClass(); 906 TurbineRole obj2 = (TurbineRole) TurbineRolePeer 907 .row2Object(row, offset, omClass); 908 909 boolean newObject = true; 910 for (int j = 0; j < results.size(); j++) 911 { 912 TurbineRolePermission temp_obj1 = results.get(j); 913 TurbineRole temp_obj2 = (TurbineRole) temp_obj1.getTurbineRole(); 914 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 915 { 916 newObject = false; 917 temp_obj2.addTurbineRolePermission(obj1); 918 break; 919 } 920 } 921 if (newObject) 922 { 923 obj2.initTurbineRolePermissions(); 924 obj2.addTurbineRolePermission(obj1); 925 } 926 results.add(obj1); 927 } 928 return results; 929 } 930 931 932 933 934 /** 935 * selects a collection of TurbineRolePermission objects pre-filled with their 936 * TurbinePermission objects. 937 * 938 * This method is protected by default in order to keep the public 939 * api reasonable. You can provide public methods for those you 940 * actually need in TurbineRolePermissionPeer. 941 * 942 * @throws TorqueException Any exceptions caught during processing will be 943 * rethrown wrapped into a TorqueException. 944 */ 945 protected static List<TurbineRolePermission> doSelectJoinTurbinePermission(Criteria criteria) 946 throws TorqueException 947 { 948 return doSelectJoinTurbinePermission(criteria, null); 949 } 950 951 /** 952 * selects a collection of TurbineRolePermission objects pre-filled with their 953 * TurbinePermission objects. 954 * 955 * This method is protected by default in order to keep the public 956 * api reasonable. You can provide public methods for those you 957 * actually need in TurbineRolePermissionPeer. 958 * 959 * @throws TorqueException Any exceptions caught during processing will be 960 * rethrown wrapped into a TorqueException. 961 */ 962 protected static List<TurbineRolePermission> doSelectJoinTurbinePermission(Criteria criteria, Connection conn) 963 throws TorqueException 964 { 965 setDbName(criteria); 966 967 TurbineRolePermissionPeer.addSelectColumns(criteria); 968 int offset = numColumns + 1; 969 TurbinePermissionPeer.addSelectColumns(criteria); 970 971 criteria.addJoin(TurbineRolePermissionPeer.PERMISSION_ID, 972 TurbinePermissionPeer.PERMISSION_ID); 973 974 correctBooleans(criteria); 975 976 List<Record> rows; 977 if (conn == null) 978 { 979 rows = BasePeer.doSelect(criteria); 980 } 981 else 982 { 983 rows = BasePeer.doSelect(criteria,conn); 984 } 985 986 List<TurbineRolePermission> results = new ArrayList<TurbineRolePermission>(); 987 988 for (int i = 0; i < rows.size(); i++) 989 { 990 Record row = rows.get(i); 991 992 Class omClass = TurbineRolePermissionPeer.getOMClass(); 993 TurbineRolePermission obj1 = (TurbineRolePermission) TurbineRolePermissionPeer 994 .row2Object(row, 1, omClass); 995 omClass = TurbinePermissionPeer.getOMClass(); 996 TurbinePermission obj2 = (TurbinePermission) TurbinePermissionPeer 997 .row2Object(row, offset, omClass); 998 999 boolean newObject = true; 1000 for (int j = 0; j < results.size(); j++) 1001 { 1002 TurbineRolePermission temp_obj1 = results.get(j); 1003 TurbinePermission temp_obj2 = (TurbinePermission) temp_obj1.getTurbinePermission(); 1004 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 1005 { 1006 newObject = false; 1007 temp_obj2.addTurbineRolePermission(obj1); 1008 break; 1009 } 1010 } 1011 if (newObject) 1012 { 1013 obj2.initTurbineRolePermissions(); 1014 obj2.addTurbineRolePermission(obj1); 1015 } 1016 results.add(obj1); 1017 } 1018 return results; 1019 } 1020 1021 1022 1023 1024 /** 1025 * Returns the TableMap related to this peer. 1026 * 1027 * @throws TorqueException Any exceptions caught during processing will be 1028 * rethrown wrapped into a TorqueException. 1029 */ 1030 public static TableMap getTableMap() 1031 throws TorqueException 1032 { 1033 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 1034 } 1035 1036 private static void setDbName(Criteria crit) 1037 { 1038 // Set the correct dbName if it has not been overridden 1039 // crit.getDbName will return the same object if not set to 1040 // another value so == check is okay and faster 1041 if (crit.getDbName() == Torque.getDefaultDB()) 1042 { 1043 crit.setDbName(DATABASE_NAME); 1044 } 1045 } 1046 1047 1048 // The following methods wrap some methods in BasePeer 1049 // to have more support for Java5 generic types in the Peer 1050 1051 /** 1052 * Utility method which executes a given sql statement. This 1053 * method should be used for select statements only. Use 1054 * executeStatement for update, insert, and delete operations. 1055 * 1056 * @param queryString A String with the sql statement to execute. 1057 * @return List of Record objects. 1058 * @throws TorqueException Any exceptions caught during processing will be 1059 * rethrown wrapped into a TorqueException. 1060 * @see org.apache.torque.util.BasePeer#executeQuery(String) 1061 */ 1062 public static List<Record> executeQuery(String queryString) throws TorqueException 1063 { 1064 return BasePeer.executeQuery(queryString); 1065 } 1066 1067 /** 1068 * Utility method which executes a given sql statement. This 1069 * method should be used for select statements only. Use 1070 * executeStatement for update, insert, and delete operations. 1071 * 1072 * @param queryString A String with the sql statement to execute. 1073 * @param dbName The database to connect to. 1074 * @return List of Record objects. 1075 * @throws TorqueException Any exceptions caught during processing will be 1076 * rethrown wrapped into a TorqueException. 1077 * @see org.apache.torque.util.BasePeer#executeQuery(String,String) 1078 */ 1079 public static List<Record> executeQuery(String queryString, String dbName) 1080 throws TorqueException 1081 { 1082 return BasePeer.executeQuery(queryString,dbName); 1083 } 1084 1085 1086 /** 1087 * Method for performing a SELECT. Returns all results. 1088 * 1089 * @param queryString A String with the sql statement to execute. 1090 * @param dbName The database to connect to. 1091 * @param singleRecord Whether or not we want to select only a 1092 * single record. 1093 * @return List of Record objects. 1094 * @throws TorqueException Any exceptions caught during processing will be 1095 * rethrown wrapped into a TorqueException. 1096 * @see org.apache.torque.util.BasePeer#executeQuery(String,String,boolean) 1097 */ 1098 public static List<Record> executeQuery( 1099 String queryString, 1100 String dbName, 1101 boolean singleRecord) 1102 throws TorqueException 1103 { 1104 return BasePeer.executeQuery(queryString,dbName,singleRecord); 1105 } 1106 1107 /** 1108 * Method for performing a SELECT. Returns all results. 1109 * 1110 * @param queryString A String with the sql statement to execute. 1111 * @param singleRecord Whether or not we want to select only a 1112 * single record. 1113 * @param con A Connection. 1114 * @return List of Record objects. 1115 * @throws TorqueException Any exceptions caught during processing will be 1116 * rethrown wrapped into a TorqueException. 1117 * @see org.apache.torque.util.BasePeer#executeQuery(String,boolean,Connection) 1118 */ 1119 public static List<Record> executeQuery( 1120 String queryString, 1121 boolean singleRecord, 1122 Connection con) 1123 throws TorqueException 1124 { 1125 return BasePeer.executeQuery(queryString,singleRecord,con); 1126 } 1127 1128 /** 1129 * Method for performing a SELECT. 1130 * 1131 * @param queryString A String with the sql statement to execute. 1132 * @param start The first row to return. 1133 * @param numberOfResults The number of rows to return. 1134 * @param dbName The database to connect to. 1135 * @param singleRecord Whether or not we want to select only a 1136 * single record. 1137 * @return List of Record objects. 1138 * @throws TorqueException Any exceptions caught during processing will be 1139 * rethrown wrapped into a TorqueException. 1140 * @see org.apache.torque.util.BasePeer#executeQuery(String,int,int,String,boolean) 1141 */ 1142 public static List<Record> executeQuery( 1143 String queryString, 1144 int start, 1145 int numberOfResults, 1146 String dbName, 1147 boolean singleRecord) 1148 throws TorqueException 1149 { 1150 return BasePeer.executeQuery(queryString,start,numberOfResults,dbName,singleRecord); 1151 } 1152 1153 /** 1154 * Method for performing a SELECT. Returns all results. 1155 * 1156 * @param queryString A String with the sql statement to execute. 1157 * @param start The first row to return. 1158 * @param numberOfResults The number of rows to return. 1159 * @param singleRecord Whether or not we want to select only a 1160 * single record. 1161 * @param con A Connection. 1162 * @return List of Record objects. 1163 * @throws TorqueException Any exceptions caught during processing will be 1164 * rethrown wrapped into a TorqueException. 1165 * @see org.apache.torque.util.BasePeer#executeQuery(String,int,int,String,boolean,Connection) 1166 */ 1167 public static List<Record> executeQuery( 1168 String queryString, 1169 int start, 1170 int numberOfResults, 1171 boolean singleRecord, 1172 Connection con) 1173 throws TorqueException 1174 { 1175 return BasePeer.executeQuery(queryString,start,numberOfResults,singleRecord,con); 1176 } 1177 1178 /** 1179 * Returns all records in a QueryDataSet as a List of Record 1180 * objects. Used for functionality like util.LargeSelect. 1181 * 1182 * @see #getSelectResults(QueryDataSet, int, int, boolean) 1183 * @param qds the QueryDataSet 1184 * @return a List of Record objects 1185 * @throws TorqueException Any exceptions caught during processing will be 1186 * rethrown wrapped into a TorqueException. 1187 * @see org.apache.torque.util.BasePeer#getSelectResults(QueryDataSet) 1188 */ 1189 public static List<Record> getSelectResults(QueryDataSet qds) 1190 throws TorqueException 1191 { 1192 return BasePeer.getSelectResults(qds); 1193 } 1194 1195 /** 1196 * Returns all records in a QueryDataSet as a List of Record 1197 * objects. Used for functionality like util.LargeSelect. 1198 * 1199 * @see #getSelectResults(QueryDataSet, int, int, boolean) 1200 * @param qds the QueryDataSet 1201 * @param singleRecord 1202 * @return a List of Record objects 1203 * @throws TorqueException Any exceptions caught during processing will be 1204 * rethrown wrapped into a TorqueException. 1205 * @see org.apache.torque.util.BasePeer#getSelectResults(QueryDataSet,boolean) 1206 */ 1207 public static List<Record> getSelectResults(QueryDataSet qds, boolean singleRecord) 1208 throws TorqueException 1209 { 1210 return BasePeer.getSelectResults(qds,singleRecord); 1211 } 1212 1213 /** 1214 * Returns numberOfResults records in a QueryDataSet as a List 1215 * of Record objects. Starting at record 0. Used for 1216 * functionality like util.LargeSelect. 1217 * 1218 * @see #getSelectResults(QueryDataSet, int, int, boolean) 1219 * @param qds the QueryDataSet 1220 * @param numberOfResults 1221 * @param singleRecord 1222 * @return a List of Record objects 1223 * @throws TorqueException Any exceptions caught during processing will be 1224 * rethrown wrapped into a TorqueException. 1225 * @see org.apache.torque.util.BasePeer#getSelectResults(QueryDataSet,int,boolean) 1226 */ 1227 public static List<Record> getSelectResults( 1228 QueryDataSet qds, 1229 int numberOfResults, 1230 boolean singleRecord) 1231 throws TorqueException 1232 { 1233 return BasePeer.getSelectResults(qds,numberOfResults,singleRecord); 1234 } 1235 1236 /** 1237 * Returns numberOfResults records in a QueryDataSet as a List 1238 * of Record objects. Starting at record start. Used for 1239 * functionality like util.LargeSelect. 1240 * 1241 * @param qds The <code>QueryDataSet</code> to extract results 1242 * from. 1243 * @param start The index from which to start retrieving 1244 * <code>Record</code> objects from the data set. 1245 * @param numberOfResults The number of results to return (or 1246 * <code> -1</code> for all results). 1247 * @param singleRecord Whether or not we want to select only a 1248 * single record. 1249 * @return A <code>List</code> of <code>Record</code> objects. 1250 * @exception TorqueException If any <code>Exception</code> occurs. 1251 * @see org.apache.torque.util.BasePeer#getSelectResults(QueryDataSet,int,int,boolean) 1252 */ 1253 public static List getSelectResults( 1254 QueryDataSet qds, 1255 int start, 1256 int numberOfResults, 1257 boolean singleRecord) 1258 throws TorqueException 1259 { 1260 return BasePeer.getSelectResults(qds,start,numberOfResults,singleRecord); 1261 } 1262 1263 /** 1264 * Performs a SQL <code>select</code> using a PreparedStatement. 1265 * Note: this method does not handle null criteria values. 1266 * 1267 * @param criteria 1268 * @param con 1269 * @return a List of Record objects. 1270 * @throws TorqueException Error performing database query. 1271 * @see org.apache.torque.util.BasePeer#doPSSelect(Criteria,Connection) 1272 */ 1273 public static List<Record> doPSSelect(Criteria criteria, Connection con) 1274 throws TorqueException 1275 { 1276 return BasePeer.doPSSelect(criteria,con); 1277 } 1278 1279 /** 1280 * Do a Prepared Statement select according to the given criteria 1281 * 1282 * @param criteria 1283 * @return a List of Record objects. 1284 * @throws TorqueException Any exceptions caught during processing will be 1285 * rethrown wrapped into a TorqueException. 1286 * @see org.apache.torque.util.BasePeer#doPSSelect(Criteria) 1287 */ 1288 public static List<Record> doPSSelect(Criteria criteria) throws TorqueException 1289 { 1290 return BasePeer.doPSSelect(criteria); 1291 } 1292 }