1 package org.campware.cream.om; 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.campware.cream.om.map.*; 32 33 34 35 36 42 public abstract class BaseTurbineRolePermissionPeer 43 extends BasePeer 44 { 45 46 47 public static final String DATABASE_NAME = "cream"; 48 49 50 public static final String TABLE_NAME = "TURBINE_ROLE_PERMISSION"; 51 52 57 public static MapBuilder getMapBuilder() 58 throws TorqueException 59 { 60 return getMapBuilder(TurbineRolePermissionMapBuilder.CLASS_NAME); 61 } 62 63 64 public static final String ROLE_ID; 65 66 public static final String PERMISSION_ID; 67 68 static 69 { 70 ROLE_ID = "TURBINE_ROLE_PERMISSION.ROLE_ID"; 71 PERMISSION_ID = "TURBINE_ROLE_PERMISSION.PERMISSION_ID"; 72 if (Torque.isInit()) 73 { 74 try 75 { 76 getMapBuilder(TurbineRolePermissionMapBuilder.CLASS_NAME); 77 } 78 catch (Exception e) 79 { 80 log.error("Could not initialize Peer", e); 81 } 82 } 83 else 84 { 85 Torque.registerMapBuilder(TurbineRolePermissionMapBuilder.CLASS_NAME); 86 } 87 } 88 89 90 public static final int numColumns = 2; 91 92 93 protected static final String CLASSNAME_DEFAULT = 94 "org.campware.cream.om.TurbineRolePermission"; 95 96 97 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 98 99 105 private static Class initClass(String className) 106 { 107 Class c = null; 108 try 109 { 110 c = Class.forName(className); 111 } 112 catch (Throwable t) 113 { 114 log.error("A FATAL ERROR has occurred which should not " 115 + "have happened under any circumstance. Please notify " 116 + "the Torque developers <torque-dev@db.apache.org> " 117 + "and give as many details as possible (including the error " 118 + "stack trace).", t); 119 120 if (t instanceof Error ) 122 { 123 throw (Error ) t.fillInStackTrace(); 124 } 125 } 126 return c; 127 } 128 129 139 public static List resultSet2Objects(java.sql.ResultSet results) 140 throws TorqueException 141 { 142 try 143 { 144 QueryDataSet qds = null; 145 List rows = null; 146 try 147 { 148 qds = new QueryDataSet(results); 149 rows = getSelectResults(qds); 150 } 151 finally 152 { 153 if (qds != null) 154 { 155 qds.close(); 156 } 157 } 158 159 return populateObjects(rows); 160 } 161 catch (SQLException e) 162 { 163 throw new TorqueException(e); 164 } 165 catch (DataSetException e) 166 { 167 throw new TorqueException(e); 168 } 169 } 170 171 172 173 180 public static ObjectKey doInsert(Criteria criteria) 181 throws TorqueException 182 { 183 return BaseTurbineRolePermissionPeer 184 .doInsert(criteria, (Connection ) null); 185 } 186 187 197 public static ObjectKey doInsert(Criteria criteria, Connection con) 198 throws TorqueException 199 { 200 201 setDbName(criteria); 202 203 if (con == null) 204 { 205 return BasePeer.doInsert(criteria); 206 } 207 else 208 { 209 return BasePeer.doInsert(criteria, con); 210 } 211 } 212 213 220 public static void addSelectColumns(Criteria criteria) 221 throws TorqueException 222 { 223 criteria.addSelectColumn(ROLE_ID); 224 criteria.addSelectColumn(PERMISSION_ID); 225 } 226 227 236 public static TurbineRolePermission row2Object(Record row, 237 int offset, 238 Class cls) 239 throws TorqueException 240 { 241 try 242 { 243 TurbineRolePermission obj = (TurbineRolePermission) cls.newInstance(); 244 TurbineRolePermissionPeer.populateObject(row, offset, obj); 245 obj.setModified(false); 246 obj.setNew(false); 247 248 return obj; 249 } 250 catch (InstantiationException e) 251 { 252 throw new TorqueException(e); 253 } 254 catch (IllegalAccessException e) 255 { 256 throw new TorqueException(e); 257 } 258 } 259 260 269 public static void populateObject(Record row, 270 int offset, 271 TurbineRolePermission obj) 272 throws TorqueException 273 { 274 try 275 { 276 obj.setRoleId(row.getValue(offset + 0).asInt()); 277 obj.setPermissionId(row.getValue(offset + 1).asInt()); 278 } 279 catch (DataSetException e) 280 { 281 throw new TorqueException(e); 282 } 283 } 284 285 293 public static List doSelect(Criteria criteria) throws TorqueException 294 { 295 return populateObjects(doSelectVillageRecords(criteria)); 296 } 297 298 307 public static List doSelect(Criteria criteria, Connection con) 308 throws TorqueException 309 { 310 return populateObjects(doSelectVillageRecords(criteria, con)); 311 } 312 313 323 public static List doSelectVillageRecords(Criteria criteria) 324 throws TorqueException 325 { 326 return BaseTurbineRolePermissionPeer 327 .doSelectVillageRecords(criteria, (Connection ) null); 328 } 329 330 339 public static List doSelectVillageRecords(Criteria criteria, Connection con) 340 throws TorqueException 341 { 342 if (criteria.getSelectColumns().size() == 0) 343 { 344 addSelectColumns(criteria); 345 } 346 347 348 setDbName(criteria); 349 350 if (con == null) 353 { 354 return BasePeer.doSelect(criteria); 355 } 356 else 357 { 358 return BasePeer.doSelect(criteria, con); 359 } 360 } 361 362 369 public static List populateObjects(List records) 370 throws TorqueException 371 { 372 List results = new ArrayList (records.size()); 373 374 for (int i = 0; i < records.size(); i++) 376 { 377 Record row = (Record) records.get(i); 378 results.add(TurbineRolePermissionPeer.row2Object(row, 1, 379 TurbineRolePermissionPeer.getOMClass())); 380 } 381 return results; 382 } 383 384 385 393 public static Class getOMClass() 394 throws TorqueException 395 { 396 return CLASS_DEFAULT; 397 } 398 399 407 public static void doUpdate(Criteria criteria) throws TorqueException 408 { 409 BaseTurbineRolePermissionPeer 410 .doUpdate(criteria, (Connection ) null); 411 } 412 413 424 public static void doUpdate(Criteria criteria, Connection con) 425 throws TorqueException 426 { 427 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 428 selectCriteria.put(ROLE_ID, criteria.remove(ROLE_ID)); 429 selectCriteria.put(PERMISSION_ID, criteria.remove(PERMISSION_ID)); 430 431 setDbName(criteria); 432 433 if (con == null) 434 { 435 BasePeer.doUpdate(selectCriteria, criteria); 436 } 437 else 438 { 439 BasePeer.doUpdate(selectCriteria, criteria, con); 440 } 441 } 442 443 450 public static void doDelete(Criteria criteria) throws TorqueException 451 { 452 TurbineRolePermissionPeer 453 .doDelete(criteria, (Connection ) null); 454 } 455 456 466 public static void doDelete(Criteria criteria, Connection con) 467 throws TorqueException 468 { 469 470 setDbName(criteria); 471 472 if (con == null) 473 { 474 BasePeer.doDelete(criteria); 475 } 476 else 477 { 478 BasePeer.doDelete(criteria, con); 479 } 480 } 481 482 488 public static List doSelect(TurbineRolePermission obj) throws TorqueException 489 { 490 return doSelect(buildSelectCriteria(obj)); 491 } 492 493 499 public static void doInsert(TurbineRolePermission obj) throws TorqueException 500 { 501 doInsert(buildCriteria(obj)); 502 obj.setNew(false); 503 obj.setModified(false); 504 } 505 506 511 public static void doUpdate(TurbineRolePermission obj) throws TorqueException 512 { 513 doUpdate(buildCriteria(obj)); 514 obj.setModified(false); 515 } 516 517 522 public static void doDelete(TurbineRolePermission obj) throws TorqueException 523 { 524 doDelete(buildSelectCriteria(obj)); 525 } 526 527 537 public static void doInsert(TurbineRolePermission obj, Connection con) 538 throws TorqueException 539 { 540 doInsert(buildCriteria(obj), con); 541 obj.setNew(false); 542 obj.setModified(false); 543 } 544 545 555 public static void doUpdate(TurbineRolePermission obj, Connection con) 556 throws TorqueException 557 { 558 doUpdate(buildCriteria(obj), con); 559 obj.setModified(false); 560 } 561 562 572 public static void doDelete(TurbineRolePermission obj, Connection con) 573 throws TorqueException 574 { 575 doDelete(buildSelectCriteria(obj), con); 576 } 577 578 585 public static void doDelete(ObjectKey pk) throws TorqueException 586 { 587 BaseTurbineRolePermissionPeer 588 .doDelete(pk, (Connection ) null); 589 } 590 591 601 public static void doDelete(ObjectKey pk, Connection con) 602 throws TorqueException 603 { 604 doDelete(buildCriteria(pk), con); 605 } 606 607 608 public static Criteria buildCriteria( ObjectKey pk ) 609 { 610 Criteria criteria = new Criteria(); 611 SimpleKey[] keys = (SimpleKey[])pk.getValue(); 612 criteria.add(ROLE_ID, keys[0]); 613 criteria.add(PERMISSION_ID, keys[1]); 614 return criteria; 615 } 616 617 618 public static Criteria buildCriteria( TurbineRolePermission obj ) 619 { 620 Criteria criteria = new Criteria(DATABASE_NAME); 621 criteria.add(ROLE_ID, obj.getRoleId()); 622 criteria.add(PERMISSION_ID, obj.getPermissionId()); 623 return criteria; 624 } 625 626 627 public static Criteria buildSelectCriteria( TurbineRolePermission obj ) 628 { 629 Criteria criteria = new Criteria(DATABASE_NAME); 630 criteria.add(ROLE_ID, obj.getRoleId()); 631 criteria.add(PERMISSION_ID, obj.getPermissionId()); 632 return criteria; 633 } 634 635 636 637 646 public static TurbineRolePermission retrieveByPK(ObjectKey pk) 647 throws TorqueException, NoRowsException, TooManyRowsException 648 { 649 Connection db = null; 650 TurbineRolePermission retVal = null; 651 try 652 { 653 db = Torque.getConnection(DATABASE_NAME); 654 retVal = retrieveByPK(pk, db); 655 } 656 finally 657 { 658 Torque.closeConnection(db); 659 } 660 return(retVal); 661 } 662 663 673 public static TurbineRolePermission retrieveByPK(ObjectKey pk, Connection con) 674 throws TorqueException, NoRowsException, TooManyRowsException 675 { 676 Criteria criteria = buildCriteria(pk); 677 List v = doSelect(criteria, con); 678 if (v.size() == 0) 679 { 680 throw new NoRowsException("Failed to select a row."); 681 } 682 else if (v.size() > 1) 683 { 684 throw new TooManyRowsException("Failed to select only one row."); 685 } 686 else 687 { 688 return (TurbineRolePermission)v.get(0); 689 } 690 } 691 692 699 public static List retrieveByPKs(List pks) 700 throws TorqueException 701 { 702 Connection db = null; 703 List retVal = null; 704 try 705 { 706 db = Torque.getConnection(DATABASE_NAME); 707 retVal = retrieveByPKs(pks, db); 708 } 709 finally 710 { 711 Torque.closeConnection(db); 712 } 713 return(retVal); 714 } 715 716 724 public static List retrieveByPKs( List pks, Connection dbcon ) 725 throws TorqueException 726 { 727 List objs = null; 728 if (pks == null || pks.size() == 0) 729 { 730 objs = new LinkedList (); 731 } 732 else 733 { 734 Criteria criteria = new Criteria(); 735 Iterator iter = pks.iterator(); 736 while (iter.hasNext()) 737 { 738 ObjectKey pk = (ObjectKey)iter.next(); 739 SimpleKey[] keys = (SimpleKey[])pk.getValue(); 740 Criteria.Criterion c0 = criteria.getNewCriterion( 741 ROLE_ID, keys[0], Criteria.EQUAL); 742 Criteria.Criterion c1 = criteria.getNewCriterion( 743 PERMISSION_ID, keys[1], Criteria.EQUAL); 744 c0.and(c1); 745 criteria.or(c0); 746 } 747 objs = doSelect(criteria, dbcon); 748 } 749 return objs; 750 } 751 752 753 759 public static TurbineRolePermission retrieveByPK( 760 int role_id 761 , int permission_id 762 ) throws TorqueException 763 { 764 Connection db = null; 765 TurbineRolePermission retVal = null; 766 try 767 { 768 db = Torque.getConnection(DATABASE_NAME); 769 retVal = retrieveByPK( 770 role_id 771 , permission_id 772 , db); 773 } 774 finally 775 { 776 Torque.closeConnection(db); 777 } 778 return(retVal); 779 } 780 781 788 public static TurbineRolePermission retrieveByPK( 789 int role_id 790 , int permission_id 791 ,Connection con) throws TorqueException 792 { 793 794 Criteria criteria = new Criteria(5); 795 criteria.add(ROLE_ID, role_id); 796 criteria.add(PERMISSION_ID, permission_id); 797 List v = doSelect(criteria, con); 798 if (v.size() != 1) 799 { 800 throw new TorqueException("Failed to select one and only one row."); 801 } 802 else 803 { 804 return (TurbineRolePermission) v.get(0); 805 } 806 } 807 808 809 810 811 812 813 814 815 826 protected static List doSelectJoinTurbineRole(Criteria criteria) 827 throws TorqueException 828 { 829 setDbName(criteria); 830 831 TurbineRolePermissionPeer.addSelectColumns(criteria); 832 int offset = numColumns + 1; 833 TurbineRolePeer.addSelectColumns(criteria); 834 835 836 criteria.addJoin(TurbineRolePermissionPeer.ROLE_ID, 837 TurbineRolePeer.ROLE_ID); 838 839 840 841 List rows = BasePeer.doSelect(criteria); 842 List results = new ArrayList (); 843 844 for (int i = 0; i < rows.size(); i++) 845 { 846 Record row = (Record) rows.get(i); 847 848 Class omClass = TurbineRolePermissionPeer.getOMClass(); 849 TurbineRolePermission obj1 = (TurbineRolePermission) TurbineRolePermissionPeer 850 .row2Object(row, 1, omClass); 851 omClass = TurbineRolePeer.getOMClass(); 852 TurbineRole obj2 = (TurbineRole)TurbineRolePeer 853 .row2Object(row, offset, omClass); 854 855 boolean newObject = true; 856 for (int j = 0; j < results.size(); j++) 857 { 858 TurbineRolePermission temp_obj1 = (TurbineRolePermission)results.get(j); 859 TurbineRole temp_obj2 = (TurbineRole)temp_obj1.getTurbineRole(); 860 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 861 { 862 newObject = false; 863 temp_obj2.addTurbineRolePermission(obj1); 864 break; 865 } 866 } 867 if (newObject) 868 { 869 obj2.initTurbineRolePermissions(); 870 obj2.addTurbineRolePermission(obj1); 871 } 872 results.add(obj1); 873 } 874 return results; 875 } 876 877 878 879 880 891 protected static List doSelectJoinTurbinePermission(Criteria criteria) 892 throws TorqueException 893 { 894 setDbName(criteria); 895 896 TurbineRolePermissionPeer.addSelectColumns(criteria); 897 int offset = numColumns + 1; 898 TurbinePermissionPeer.addSelectColumns(criteria); 899 900 901 criteria.addJoin(TurbineRolePermissionPeer.PERMISSION_ID, 902 TurbinePermissionPeer.PERMISSION_ID); 903 904 905 906 List rows = BasePeer.doSelect(criteria); 907 List results = new ArrayList (); 908 909 for (int i = 0; i < rows.size(); i++) 910 { 911 Record row = (Record) rows.get(i); 912 913 Class omClass = TurbineRolePermissionPeer.getOMClass(); 914 TurbineRolePermission obj1 = (TurbineRolePermission) TurbineRolePermissionPeer 915 .row2Object(row, 1, omClass); 916 omClass = TurbinePermissionPeer.getOMClass(); 917 TurbinePermission obj2 = (TurbinePermission)TurbinePermissionPeer 918 .row2Object(row, offset, omClass); 919 920 boolean newObject = true; 921 for (int j = 0; j < results.size(); j++) 922 { 923 TurbineRolePermission temp_obj1 = (TurbineRolePermission)results.get(j); 924 TurbinePermission temp_obj2 = (TurbinePermission)temp_obj1.getTurbinePermission(); 925 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 926 { 927 newObject = false; 928 temp_obj2.addTurbineRolePermission(obj1); 929 break; 930 } 931 } 932 if (newObject) 933 { 934 obj2.initTurbineRolePermissions(); 935 obj2.addTurbineRolePermission(obj1); 936 } 937 results.add(obj1); 938 } 939 return results; 940 } 941 942 943 944 945 952 protected static TableMap getTableMap() 953 throws TorqueException 954 { 955 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 956 } 957 958 private static void setDbName(Criteria crit) 959 { 960 if (crit.getDbName() == Torque.getDefaultDB()) 964 { 965 crit.setDbName(DATABASE_NAME); 966 } 967 } 968 } 969
| Popular Tags
|