1 package org.tigris.scarab.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.tigris.scarab.om.map.*; 32 33 34 35 36 38 public abstract class BasePendingGroupUserRolePeer 39 extends BasePeer 40 { 41 42 43 public static final String DATABASE_NAME = "scarab"; 44 45 46 public static final String TABLE_NAME = "SCARAB_PENDING_GROUP_USER_ROLE"; 47 48 53 public static MapBuilder getMapBuilder() 54 throws TorqueException 55 { 56 return getMapBuilder(PendingGroupUserRoleMapBuilder.CLASS_NAME); 57 } 58 59 60 public static final String USER_ID; 61 62 public static final String GROUP_ID; 63 64 public static final String ROLE_NAME; 65 66 static 67 { 68 USER_ID = "SCARAB_PENDING_GROUP_USER_ROLE.USER_ID"; 69 GROUP_ID = "SCARAB_PENDING_GROUP_USER_ROLE.GROUP_ID"; 70 ROLE_NAME = "SCARAB_PENDING_GROUP_USER_ROLE.ROLE_NAME"; 71 if (Torque.isInit()) 72 { 73 try 74 { 75 getMapBuilder(PendingGroupUserRoleMapBuilder.CLASS_NAME); 76 } 77 catch (Exception e) 78 { 79 log.error("Could not initialize Peer", e); 80 } 81 } 82 else 83 { 84 Torque.registerMapBuilder(PendingGroupUserRoleMapBuilder.CLASS_NAME); 85 } 86 } 87 88 89 public static final int numColumns = 3; 90 91 92 protected static final String CLASSNAME_DEFAULT = 93 "org.tigris.scarab.om.PendingGroupUserRole"; 94 95 96 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 97 98 104 private static Class initClass(String className) 105 { 106 Class c = null; 107 try 108 { 109 c = Class.forName(className); 110 } 111 catch (Throwable t) 112 { 113 log.error("A FATAL ERROR has occurred which should not " 114 + "have happened under any circumstance. Please notify " 115 + "the Torque developers <torque-dev@db.apache.org> " 116 + "and give as many details as possible (including the error " 117 + "stack trace).", t); 118 119 if (t instanceof Error ) 121 { 122 throw (Error ) t.fillInStackTrace(); 123 } 124 } 125 return c; 126 } 127 128 138 public static List resultSet2Objects(java.sql.ResultSet results) 139 throws TorqueException 140 { 141 try 142 { 143 QueryDataSet qds = null; 144 List rows = null; 145 try 146 { 147 qds = new QueryDataSet(results); 148 rows = getSelectResults(qds); 149 } 150 finally 151 { 152 if (qds != null) 153 { 154 qds.close(); 155 } 156 } 157 158 return populateObjects(rows); 159 } 160 catch (SQLException e) 161 { 162 throw new TorqueException(e); 163 } 164 catch (DataSetException e) 165 { 166 throw new TorqueException(e); 167 } 168 } 169 170 171 172 179 public static ObjectKey doInsert(Criteria criteria) 180 throws TorqueException 181 { 182 return BasePendingGroupUserRolePeer 183 .doInsert(criteria, (Connection ) null); 184 } 185 186 196 public static ObjectKey doInsert(Criteria criteria, Connection con) 197 throws TorqueException 198 { 199 200 setDbName(criteria); 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(USER_ID); 223 criteria.addSelectColumn(GROUP_ID); 224 criteria.addSelectColumn(ROLE_NAME); 225 } 226 227 236 public static PendingGroupUserRole row2Object(Record row, 237 int offset, 238 Class cls) 239 throws TorqueException 240 { 241 try 242 { 243 PendingGroupUserRole obj = (PendingGroupUserRole) cls.newInstance(); 244 PendingGroupUserRolePeer.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 PendingGroupUserRole obj) 272 throws TorqueException 273 { 274 try 275 { 276 obj.setUserId(row.getValue(offset + 0).asIntegerObj()); 277 obj.setGroupId(row.getValue(offset + 1).asIntegerObj()); 278 obj.setRoleName(row.getValue(offset + 2).asString()); 279 } 280 catch (DataSetException e) 281 { 282 throw new TorqueException(e); 283 } 284 } 285 286 294 public static List doSelect(Criteria criteria) throws TorqueException 295 { 296 return populateObjects(doSelectVillageRecords(criteria)); 297 } 298 299 308 public static List doSelect(Criteria criteria, Connection con) 309 throws TorqueException 310 { 311 return populateObjects(doSelectVillageRecords(criteria, con)); 312 } 313 314 324 public static List doSelectVillageRecords(Criteria criteria) 325 throws TorqueException 326 { 327 return BasePendingGroupUserRolePeer 328 .doSelectVillageRecords(criteria, (Connection ) null); 329 } 330 331 340 public static List doSelectVillageRecords(Criteria criteria, Connection con) 341 throws TorqueException 342 { 343 if (criteria.getSelectColumns().size() == 0) 344 { 345 addSelectColumns(criteria); 346 } 347 348 349 setDbName(criteria); 350 351 if (con == null) 354 { 355 return BasePeer.doSelect(criteria); 356 } 357 else 358 { 359 return BasePeer.doSelect(criteria, con); 360 } 361 } 362 363 370 public static List populateObjects(List records) 371 throws TorqueException 372 { 373 List results = new ArrayList (records.size()); 374 375 for (int i = 0; i < records.size(); i++) 377 { 378 Record row = (Record) records.get(i); 379 results.add(PendingGroupUserRolePeer.row2Object(row, 1, 380 PendingGroupUserRolePeer.getOMClass())); 381 } 382 return results; 383 } 384 385 386 394 public static Class getOMClass() 395 throws TorqueException 396 { 397 return CLASS_DEFAULT; 398 } 399 400 408 public static void doUpdate(Criteria criteria) throws TorqueException 409 { 410 BasePendingGroupUserRolePeer 411 .doUpdate(criteria, (Connection ) null); 412 } 413 414 425 public static void doUpdate(Criteria criteria, Connection con) 426 throws TorqueException 427 { 428 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 429 selectCriteria.put(USER_ID, criteria.remove(USER_ID)); 430 selectCriteria.put(GROUP_ID, criteria.remove(GROUP_ID)); 431 selectCriteria.put(ROLE_NAME, criteria.remove(ROLE_NAME)); 432 433 setDbName(criteria); 434 435 if (con == null) 436 { 437 BasePeer.doUpdate(selectCriteria, criteria); 438 } 439 else 440 { 441 BasePeer.doUpdate(selectCriteria, criteria, con); 442 } 443 } 444 445 452 public static void doDelete(Criteria criteria) throws TorqueException 453 { 454 PendingGroupUserRolePeer 455 .doDelete(criteria, (Connection ) null); 456 } 457 458 468 public static void doDelete(Criteria criteria, Connection con) 469 throws TorqueException 470 { 471 472 setDbName(criteria); 473 474 if (con == null) 475 { 476 BasePeer.doDelete(criteria); 477 } 478 else 479 { 480 BasePeer.doDelete(criteria, con); 481 } 482 } 483 484 490 public static List doSelect(PendingGroupUserRole obj) throws TorqueException 491 { 492 return doSelect(buildSelectCriteria(obj)); 493 } 494 495 501 public static void doInsert(PendingGroupUserRole obj) throws TorqueException 502 { 503 doInsert(buildCriteria(obj)); 504 obj.setNew(false); 505 obj.setModified(false); 506 } 507 508 513 public static void doUpdate(PendingGroupUserRole obj) throws TorqueException 514 { 515 doUpdate(buildCriteria(obj)); 516 obj.setModified(false); 517 } 518 519 524 public static void doDelete(PendingGroupUserRole obj) throws TorqueException 525 { 526 doDelete(buildSelectCriteria(obj)); 527 } 528 529 539 public static void doInsert(PendingGroupUserRole obj, Connection con) 540 throws TorqueException 541 { 542 doInsert(buildCriteria(obj), con); 543 obj.setNew(false); 544 obj.setModified(false); 545 } 546 547 557 public static void doUpdate(PendingGroupUserRole obj, Connection con) 558 throws TorqueException 559 { 560 doUpdate(buildCriteria(obj), con); 561 obj.setModified(false); 562 } 563 564 574 public static void doDelete(PendingGroupUserRole obj, Connection con) 575 throws TorqueException 576 { 577 doDelete(buildSelectCriteria(obj), con); 578 } 579 580 587 public static void doDelete(ObjectKey pk) throws TorqueException 588 { 589 BasePendingGroupUserRolePeer 590 .doDelete(pk, (Connection ) null); 591 } 592 593 603 public static void doDelete(ObjectKey pk, Connection con) 604 throws TorqueException 605 { 606 doDelete(buildCriteria(pk), con); 607 } 608 609 610 public static Criteria buildCriteria( ObjectKey pk ) 611 { 612 Criteria criteria = new Criteria(); 613 SimpleKey[] keys = (SimpleKey[])pk.getValue(); 614 criteria.add(USER_ID, keys[0]); 615 criteria.add(GROUP_ID, keys[1]); 616 criteria.add(ROLE_NAME, keys[2]); 617 return criteria; 618 } 619 620 621 public static Criteria buildCriteria( PendingGroupUserRole obj ) 622 { 623 Criteria criteria = new Criteria(DATABASE_NAME); 624 criteria.add(USER_ID, obj.getUserId()); 625 criteria.add(GROUP_ID, obj.getGroupId()); 626 criteria.add(ROLE_NAME, obj.getRoleName()); 627 return criteria; 628 } 629 630 631 public static Criteria buildSelectCriteria( PendingGroupUserRole obj ) 632 { 633 Criteria criteria = new Criteria(DATABASE_NAME); 634 criteria.add(USER_ID, obj.getUserId()); 635 criteria.add(GROUP_ID, obj.getGroupId()); 636 criteria.add(ROLE_NAME, obj.getRoleName()); 637 return criteria; 638 } 639 640 641 642 651 public static PendingGroupUserRole retrieveByPK(ObjectKey pk) 652 throws TorqueException, NoRowsException, TooManyRowsException 653 { 654 Connection db = null; 655 PendingGroupUserRole retVal = null; 656 try 657 { 658 db = Torque.getConnection(DATABASE_NAME); 659 retVal = retrieveByPK(pk, db); 660 } 661 finally 662 { 663 Torque.closeConnection(db); 664 } 665 return(retVal); 666 } 667 668 678 public static PendingGroupUserRole retrieveByPK(ObjectKey pk, Connection con) 679 throws TorqueException, NoRowsException, TooManyRowsException 680 { 681 Criteria criteria = buildCriteria(pk); 682 List v = doSelect(criteria, con); 683 if (v.size() == 0) 684 { 685 throw new NoRowsException("Failed to select a row."); 686 } 687 else if (v.size() > 1) 688 { 689 throw new TooManyRowsException("Failed to select only one row."); 690 } 691 else 692 { 693 return (PendingGroupUserRole)v.get(0); 694 } 695 } 696 697 704 public static List retrieveByPKs(List pks) 705 throws TorqueException 706 { 707 Connection db = null; 708 List retVal = null; 709 try 710 { 711 db = Torque.getConnection(DATABASE_NAME); 712 retVal = retrieveByPKs(pks, db); 713 } 714 finally 715 { 716 Torque.closeConnection(db); 717 } 718 return(retVal); 719 } 720 721 729 public static List retrieveByPKs( List pks, Connection dbcon ) 730 throws TorqueException 731 { 732 List objs = null; 733 if (pks == null || pks.size() == 0) 734 { 735 objs = new LinkedList (); 736 } 737 else 738 { 739 Criteria criteria = new Criteria(); 740 Iterator iter = pks.iterator(); 741 while (iter.hasNext()) 742 { 743 ObjectKey pk = (ObjectKey)iter.next(); 744 SimpleKey[] keys = (SimpleKey[])pk.getValue(); 745 Criteria.Criterion c0 = criteria.getNewCriterion( 746 USER_ID, keys[0], Criteria.EQUAL); 747 Criteria.Criterion c1 = criteria.getNewCriterion( 748 GROUP_ID, keys[1], Criteria.EQUAL); 749 c0.and(c1); 750 Criteria.Criterion c2 = criteria.getNewCriterion( 751 ROLE_NAME, keys[2], Criteria.EQUAL); 752 c1.and(c2); 753 criteria.or(c0); 754 } 755 objs = doSelect(criteria, dbcon); 756 } 757 return objs; 758 } 759 760 761 768 public static PendingGroupUserRole retrieveByPK( 769 Integer user_id 770 , Integer group_id 771 , String role_name 772 ) throws TorqueException 773 { 774 Connection db = null; 775 PendingGroupUserRole retVal = null; 776 try 777 { 778 db = Torque.getConnection(DATABASE_NAME); 779 retVal = retrieveByPK( 780 user_id 781 , group_id 782 , role_name 783 , db); 784 } 785 finally 786 { 787 Torque.closeConnection(db); 788 } 789 return(retVal); 790 } 791 792 800 public static PendingGroupUserRole retrieveByPK( 801 Integer user_id 802 , Integer group_id 803 , String role_name 804 ,Connection con) throws TorqueException 805 { 806 807 Criteria criteria = new Criteria(5); 808 criteria.add(USER_ID, user_id); 809 criteria.add(GROUP_ID, group_id); 810 criteria.add(ROLE_NAME, role_name); 811 List v = doSelect(criteria, con); 812 if (v.size() != 1) 813 { 814 throw new TorqueException("Failed to select one and only one row."); 815 } 816 else 817 { 818 return (PendingGroupUserRole) v.get(0); 819 } 820 } 821 822 823 824 825 826 827 828 829 840 protected static List doSelectJoinScarabUserImpl(Criteria criteria) 841 throws TorqueException 842 { 843 setDbName(criteria); 844 845 PendingGroupUserRolePeer.addSelectColumns(criteria); 846 int offset = numColumns + 1; 847 ScarabUserImplPeer.addSelectColumns(criteria); 848 849 850 criteria.addJoin(PendingGroupUserRolePeer.USER_ID, 851 ScarabUserImplPeer.USER_ID); 852 853 854 855 List rows = BasePeer.doSelect(criteria); 856 List results = new ArrayList (); 857 858 for (int i = 0; i < rows.size(); i++) 859 { 860 Record row = (Record) rows.get(i); 861 862 Class omClass = PendingGroupUserRolePeer.getOMClass(); 863 PendingGroupUserRole obj1 = (PendingGroupUserRole) PendingGroupUserRolePeer 864 .row2Object(row, 1, omClass); 865 omClass = ScarabUserImplPeer.getOMClass(); 866 ScarabUserImpl obj2 = (ScarabUserImpl)ScarabUserImplPeer 867 .row2Object(row, offset, omClass); 868 869 boolean newObject = true; 870 for (int j = 0; j < results.size(); j++) 871 { 872 PendingGroupUserRole temp_obj1 = (PendingGroupUserRole)results.get(j); 873 ScarabUserImpl temp_obj2 = (ScarabUserImpl)temp_obj1.getScarabUser(); 874 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 875 { 876 newObject = false; 877 temp_obj2.addPendingGroupUserRole(obj1); 878 break; 879 } 880 } 881 if (newObject) 882 { 883 obj2.initPendingGroupUserRoles(); 884 obj2.addPendingGroupUserRole(obj1); 885 } 886 results.add(obj1); 887 } 888 return results; 889 } 890 891 892 893 894 905 protected static List doSelectJoinScarabModule(Criteria criteria) 906 throws TorqueException 907 { 908 setDbName(criteria); 909 910 PendingGroupUserRolePeer.addSelectColumns(criteria); 911 int offset = numColumns + 1; 912 ScarabModulePeer.addSelectColumns(criteria); 913 914 915 criteria.addJoin(PendingGroupUserRolePeer.GROUP_ID, 916 ScarabModulePeer.MODULE_ID); 917 918 919 920 List rows = BasePeer.doSelect(criteria); 921 List results = new ArrayList (); 922 923 for (int i = 0; i < rows.size(); i++) 924 { 925 Record row = (Record) rows.get(i); 926 927 Class omClass = PendingGroupUserRolePeer.getOMClass(); 928 PendingGroupUserRole obj1 = (PendingGroupUserRole) PendingGroupUserRolePeer 929 .row2Object(row, 1, omClass); 930 omClass = ScarabModulePeer.getOMClass(row, offset); 931 ScarabModule obj2 = (ScarabModule)ScarabModulePeer 932 .row2Object(row, offset, omClass); 933 934 boolean newObject = true; 935 for (int j = 0; j < results.size(); j++) 936 { 937 PendingGroupUserRole temp_obj1 = (PendingGroupUserRole)results.get(j); 938 ScarabModule temp_obj2 = (ScarabModule)temp_obj1.getModule(); 939 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 940 { 941 newObject = false; 942 temp_obj2.addPendingGroupUserRole(obj1); 943 break; 944 } 945 } 946 if (newObject) 947 { 948 obj2.initPendingGroupUserRoles(); 949 obj2.addPendingGroupUserRole(obj1); 950 } 951 results.add(obj1); 952 } 953 return results; 954 } 955 956 957 958 959 966 protected static TableMap getTableMap() 967 throws TorqueException 968 { 969 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 970 } 971 972 private static void setDbName(Criteria crit) 973 { 974 if (crit.getDbName() == Torque.getDefaultDB()) 978 { 979 crit.setDbName(DATABASE_NAME); 980 } 981 } 982 } 983 | Popular Tags |