1 package org.apache.jetspeed.om.dbpsml; 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.jetspeed.om.dbpsml.map.*; 32 33 34 40 public abstract class BaseJetspeedUserProfilePeer 41 extends BasePeer 42 { 43 44 45 public static final String DATABASE_NAME = "default"; 46 47 48 public static final String TABLE_NAME = "JETSPEED_USER_PROFILE"; 49 50 55 public static MapBuilder getMapBuilder() 56 throws TorqueException 57 { 58 return getMapBuilder(JetspeedUserProfileMapBuilder.CLASS_NAME); 59 } 60 61 62 public static final String PSML_ID; 63 64 public static final String USER_NAME; 65 66 public static final String MEDIA_TYPE; 67 68 public static final String LANGUAGE; 69 70 public static final String COUNTRY; 71 72 public static final String PAGE; 73 74 public static final String PROFILE; 75 76 static 77 { 78 PSML_ID = "JETSPEED_USER_PROFILE.PSML_ID"; 79 USER_NAME = "JETSPEED_USER_PROFILE.USER_NAME"; 80 MEDIA_TYPE = "JETSPEED_USER_PROFILE.MEDIA_TYPE"; 81 LANGUAGE = "JETSPEED_USER_PROFILE.LANGUAGE"; 82 COUNTRY = "JETSPEED_USER_PROFILE.COUNTRY"; 83 PAGE = "JETSPEED_USER_PROFILE.PAGE"; 84 PROFILE = "JETSPEED_USER_PROFILE.PROFILE"; 85 if (Torque.isInit()) 86 { 87 try 88 { 89 getMapBuilder(); 90 } 91 catch (Exception e) 92 { 93 log.error("Could not initialize Peer", e); 94 } 95 } 96 else 97 { 98 Torque.registerMapBuilder(JetspeedUserProfileMapBuilder.CLASS_NAME); 99 } 100 } 101 102 103 public static final int numColumns = 7; 104 105 106 protected static final String CLASSNAME_DEFAULT = 107 "org.apache.jetspeed.om.dbpsml.JetspeedUserProfile"; 108 109 110 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 111 112 118 private static Class initClass(String className) 119 { 120 Class c = null; 121 try 122 { 123 c = Class.forName(className); 124 } 125 catch (Throwable t) 126 { 127 log.error("A FATAL ERROR has occurred which should not " 128 + "have happened under any circumstance. Please notify " 129 + "the Torque developers <turbine-torque-dev@jakarta.apache.org> " 130 + "and give as many details as possible (including the error " 131 + "stack trace).", t); 132 133 if (t instanceof Error ) 135 { 136 throw (Error ) t.fillInStackTrace(); 137 } 138 } 139 return c; 140 } 141 142 152 public static List resultSet2Objects(java.sql.ResultSet results) 153 throws TorqueException 154 { 155 try 156 { 157 QueryDataSet qds = null; 158 List rows = null; 159 try 160 { 161 qds = new QueryDataSet(results); 162 rows = getSelectResults(qds); 163 } 164 finally 165 { 166 if (qds != null) 167 { 168 qds.close(); 169 } 170 } 171 172 return populateObjects(rows); 173 } 174 catch (SQLException e) 175 { 176 throw new TorqueException(e); 177 } 178 catch (DataSetException e) 179 { 180 throw new TorqueException(e); 181 } 182 } 183 184 185 186 193 public static ObjectKey doInsert(Criteria criteria) 194 throws TorqueException 195 { 196 return BaseJetspeedUserProfilePeer 197 .doInsert(criteria, (Connection ) null); 198 } 199 200 210 public static ObjectKey doInsert(Criteria criteria, Connection con) 211 throws TorqueException 212 { 213 214 if (criteria.getDbName() == Torque.getDefaultDB()) 218 { 219 criteria.setDbName(DATABASE_NAME); 220 } 221 if (con == null) 222 { 223 return BasePeer.doInsert(criteria); 224 } 225 else 226 { 227 return BasePeer.doInsert(criteria, con); 228 } 229 } 230 231 238 public static void addSelectColumns(Criteria criteria) 239 throws TorqueException 240 { 241 criteria.addSelectColumn(PSML_ID); 242 criteria.addSelectColumn(USER_NAME); 243 criteria.addSelectColumn(MEDIA_TYPE); 244 criteria.addSelectColumn(LANGUAGE); 245 criteria.addSelectColumn(COUNTRY); 246 criteria.addSelectColumn(PAGE); 247 criteria.addSelectColumn(PROFILE); 248 } 249 250 259 public static JetspeedUserProfile row2Object(Record row, 260 int offset, 261 Class cls) 262 throws TorqueException 263 { 264 try 265 { 266 JetspeedUserProfile obj = (JetspeedUserProfile) cls.newInstance(); 267 JetspeedUserProfilePeer.populateObject(row, offset, obj); 268 obj.setModified(false); 269 obj.setNew(false); 270 271 return obj; 272 } 273 catch (InstantiationException e) 274 { 275 throw new TorqueException(e); 276 } 277 catch (IllegalAccessException e) 278 { 279 throw new TorqueException(e); 280 } 281 } 282 283 292 public static void populateObject(Record row, 293 int offset, 294 JetspeedUserProfile obj) 295 throws TorqueException 296 { 297 try 298 { 299 obj.setPsmlId(row.getValue(offset + 0).asInt()); 300 obj.setUserName(row.getValue(offset + 1).asString()); 301 obj.setMediaType(row.getValue(offset + 2).asString()); 302 obj.setLanguage(row.getValue(offset + 3).asString()); 303 obj.setCountry(row.getValue(offset + 4).asString()); 304 obj.setPage(row.getValue(offset + 5).asString()); 305 obj.setProfile(row.getValue(offset + 6).asBytes()); 306 } 307 catch (DataSetException e) 308 { 309 throw new TorqueException(e); 310 } 311 } 312 313 321 public static List doSelect(Criteria criteria) throws TorqueException 322 { 323 return populateObjects(doSelectVillageRecords(criteria)); 324 } 325 326 335 public static List doSelect(Criteria criteria, Connection con) 336 throws TorqueException 337 { 338 return populateObjects(doSelectVillageRecords(criteria, con)); 339 } 340 341 351 public static List doSelectVillageRecords(Criteria criteria) 352 throws TorqueException 353 { 354 return BaseJetspeedUserProfilePeer 355 .doSelectVillageRecords(criteria, (Connection ) null); 356 } 357 358 366 public static List doSelectVillageRecords(Criteria criteria, Connection con) 367 throws TorqueException 368 { 369 if (criteria.getSelectColumns().size() == 0) 370 { 371 addSelectColumns(criteria); 372 } 373 374 375 if (criteria.getDbName() == Torque.getDefaultDB()) 379 { 380 criteria.setDbName(DATABASE_NAME); 381 } 382 if (con == null) 385 { 386 return BasePeer.doSelect(criteria); 387 } 388 else 389 { 390 return BasePeer.doSelect(criteria, con); 391 } 392 } 393 394 401 public static List populateObjects(List records) 402 throws TorqueException 403 { 404 List results = new ArrayList (records.size()); 405 406 for (int i = 0; i < records.size(); i++) 408 { 409 Record row = (Record) records.get(i); 410 results.add(JetspeedUserProfilePeer.row2Object(row, 1, 411 JetspeedUserProfilePeer.getOMClass())); 412 } 413 return results; 414 } 415 416 417 425 public static Class getOMClass() 426 throws TorqueException 427 { 428 return CLASS_DEFAULT; 429 } 430 431 439 public static void doUpdate(Criteria criteria) throws TorqueException 440 { 441 BaseJetspeedUserProfilePeer 442 .doUpdate(criteria, (Connection ) null); 443 } 444 445 456 public static void doUpdate(Criteria criteria, Connection con) 457 throws TorqueException 458 { 459 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 460 selectCriteria.put(PSML_ID, criteria.remove(PSML_ID)); 461 462 if (criteria.getDbName() == Torque.getDefaultDB()) 466 { 467 criteria.setDbName(DATABASE_NAME); 468 } 469 if (con == null) 470 { 471 BasePeer.doUpdate(selectCriteria, criteria); 472 } 473 else 474 { 475 BasePeer.doUpdate(selectCriteria, criteria, con); 476 } 477 } 478 479 486 public static void doDelete(Criteria criteria) throws TorqueException 487 { 488 BaseJetspeedUserProfilePeer 489 .doDelete(criteria, (Connection ) null); 490 } 491 492 502 public static void doDelete(Criteria criteria, Connection con) 503 throws TorqueException 504 { 505 506 if (criteria.getDbName() == Torque.getDefaultDB()) 510 { 511 criteria.setDbName(DATABASE_NAME); 512 } 513 if (con == null) 514 { 515 BasePeer.doDelete(criteria); 516 } 517 else 518 { 519 BasePeer.doDelete(criteria, con); 520 } 521 } 522 523 529 public static List doSelect(JetspeedUserProfile obj) throws TorqueException 530 { 531 return doSelect(buildCriteria(obj)); 532 } 533 534 540 public static void doInsert(JetspeedUserProfile obj) throws TorqueException 541 { 542 obj.setPrimaryKey(doInsert(buildCriteria(obj))); 543 obj.setNew(false); 544 obj.setModified(false); 545 } 546 547 552 public static void doUpdate(JetspeedUserProfile obj) throws TorqueException 553 { 554 doUpdate(buildCriteria(obj)); 555 obj.setModified(false); 556 } 557 558 563 public static void doDelete(JetspeedUserProfile obj) throws TorqueException 564 { 565 doDelete(buildCriteria(obj)); 566 } 567 568 578 public static void doInsert(JetspeedUserProfile obj, Connection con) 579 throws TorqueException 580 { 581 obj.setPrimaryKey(doInsert(buildCriteria(obj), con)); 582 obj.setNew(false); 583 obj.setModified(false); 584 } 585 586 596 public static void doUpdate(JetspeedUserProfile obj, Connection con) 597 throws TorqueException 598 { 599 doUpdate(buildCriteria(obj), con); 600 obj.setModified(false); 601 } 602 603 613 public static void doDelete(JetspeedUserProfile obj, Connection con) 614 throws TorqueException 615 { 616 doDelete(buildCriteria(obj), con); 617 } 618 619 626 public static void doDelete(ObjectKey pk) throws TorqueException 627 { 628 BaseJetspeedUserProfilePeer 629 .doDelete(pk, (Connection ) null); 630 } 631 632 642 public static void doDelete(ObjectKey pk, Connection con) 643 throws TorqueException 644 { 645 doDelete(buildCriteria(pk), con); 646 } 647 648 649 public static Criteria buildCriteria( ObjectKey pk ) 650 { 651 Criteria criteria = new Criteria(); 652 criteria.add(PSML_ID, pk); 653 return criteria; 654 } 655 656 657 public static Criteria buildCriteria( JetspeedUserProfile obj ) 658 { 659 Criteria criteria = new Criteria(DATABASE_NAME); 660 if (!obj.isNew()) 661 criteria.add(PSML_ID, obj.getPsmlId()); 662 criteria.add(USER_NAME, obj.getUserName()); 663 criteria.add(MEDIA_TYPE, obj.getMediaType()); 664 criteria.add(LANGUAGE, obj.getLanguage()); 665 criteria.add(COUNTRY, obj.getCountry()); 666 criteria.add(PAGE, obj.getPage()); 667 criteria.add(PROFILE, obj.getProfile()); 668 return criteria; 669 } 670 671 672 681 public static JetspeedUserProfile retrieveByPK(int pk) 682 throws TorqueException, NoRowsException, TooManyRowsException 683 { 684 return retrieveByPK(SimpleKey.keyFor(pk)); 685 } 686 687 696 public static JetspeedUserProfile retrieveByPK(ObjectKey pk) 697 throws TorqueException, NoRowsException, TooManyRowsException 698 { 699 Connection db = null; 700 JetspeedUserProfile retVal = null; 701 try 702 { 703 db = Torque.getConnection(DATABASE_NAME); 704 retVal = retrieveByPK(pk, db); 705 } 706 finally 707 { 708 Torque.closeConnection(db); 709 } 710 return(retVal); 711 } 712 713 723 public static JetspeedUserProfile retrieveByPK(ObjectKey pk, Connection con) 724 throws TorqueException, NoRowsException, TooManyRowsException 725 { 726 Criteria criteria = buildCriteria(pk); 727 List v = doSelect(criteria, con); 728 if (v.size() == 0) 729 { 730 throw new NoRowsException("Failed to select a row."); 731 } 732 else if (v.size() > 1) 733 { 734 throw new TooManyRowsException("Failed to select only one row."); 735 } 736 else 737 { 738 return (JetspeedUserProfile)v.get(0); 739 } 740 } 741 742 749 public static List retrieveByPKs(List pks) 750 throws TorqueException 751 { 752 Connection db = null; 753 List retVal = null; 754 try 755 { 756 db = Torque.getConnection(DATABASE_NAME); 757 retVal = retrieveByPKs(pks, db); 758 } 759 finally 760 { 761 Torque.closeConnection(db); 762 } 763 return(retVal); 764 } 765 766 774 public static List retrieveByPKs( List pks, Connection dbcon ) 775 throws TorqueException 776 { 777 List objs = null; 778 if (pks == null || pks.size() == 0) 779 { 780 objs = new LinkedList (); 781 } 782 else 783 { 784 Criteria criteria = new Criteria(); 785 criteria.addIn( PSML_ID, pks ); 786 objs = doSelect(criteria, dbcon); 787 } 788 return objs; 789 } 790 791 792 793 794 795 796 797 798 799 800 807 protected static TableMap getTableMap() 808 throws TorqueException 809 { 810 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 811 } 812 } 813 | Popular Tags |