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 41 public abstract class BaseInboxAttachmentPeer 42 extends BasePeer 43 { 44 45 46 public static final String DATABASE_NAME = "cream"; 47 48 49 public static final String TABLE_NAME = "INBOX_ATTACHMENT"; 50 51 56 public static MapBuilder getMapBuilder() 57 throws TorqueException 58 { 59 return getMapBuilder(InboxAttachmentMapBuilder.CLASS_NAME); 60 } 61 62 63 public static final String INBOX_ATTACHMENT_ID; 64 65 public static final String INBOX_EVENT_ID; 66 67 public static final String CONTENT_TYPE; 68 69 public static final String CONTENT_DISPOSITION; 70 71 public static final String CONTENT_ID; 72 73 public static final String FILE_NAME; 74 75 public static final String CONTENT; 76 77 static 78 { 79 INBOX_ATTACHMENT_ID = "INBOX_ATTACHMENT.INBOX_ATTACHMENT_ID"; 80 INBOX_EVENT_ID = "INBOX_ATTACHMENT.INBOX_EVENT_ID"; 81 CONTENT_TYPE = "INBOX_ATTACHMENT.CONTENT_TYPE"; 82 CONTENT_DISPOSITION = "INBOX_ATTACHMENT.CONTENT_DISPOSITION"; 83 CONTENT_ID = "INBOX_ATTACHMENT.CONTENT_ID"; 84 FILE_NAME = "INBOX_ATTACHMENT.FILE_NAME"; 85 CONTENT = "INBOX_ATTACHMENT.CONTENT"; 86 if (Torque.isInit()) 87 { 88 try 89 { 90 getMapBuilder(InboxAttachmentMapBuilder.CLASS_NAME); 91 } 92 catch (Exception e) 93 { 94 log.error("Could not initialize Peer", e); 95 } 96 } 97 else 98 { 99 Torque.registerMapBuilder(InboxAttachmentMapBuilder.CLASS_NAME); 100 } 101 } 102 103 104 public static final int numColumns = 7; 105 106 107 protected static final String CLASSNAME_DEFAULT = 108 "org.campware.cream.om.InboxAttachment"; 109 110 111 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 112 113 119 private static Class initClass(String className) 120 { 121 Class c = null; 122 try 123 { 124 c = Class.forName(className); 125 } 126 catch (Throwable t) 127 { 128 log.error("A FATAL ERROR has occurred which should not " 129 + "have happened under any circumstance. Please notify " 130 + "the Torque developers <torque-dev@db.apache.org> " 131 + "and give as many details as possible (including the error " 132 + "stack trace).", t); 133 134 if (t instanceof Error ) 136 { 137 throw (Error ) t.fillInStackTrace(); 138 } 139 } 140 return c; 141 } 142 143 153 public static List resultSet2Objects(java.sql.ResultSet results) 154 throws TorqueException 155 { 156 try 157 { 158 QueryDataSet qds = null; 159 List rows = null; 160 try 161 { 162 qds = new QueryDataSet(results); 163 rows = getSelectResults(qds); 164 } 165 finally 166 { 167 if (qds != null) 168 { 169 qds.close(); 170 } 171 } 172 173 return populateObjects(rows); 174 } 175 catch (SQLException e) 176 { 177 throw new TorqueException(e); 178 } 179 catch (DataSetException e) 180 { 181 throw new TorqueException(e); 182 } 183 } 184 185 186 187 194 public static ObjectKey doInsert(Criteria criteria) 195 throws TorqueException 196 { 197 return BaseInboxAttachmentPeer 198 .doInsert(criteria, (Connection ) null); 199 } 200 201 211 public static ObjectKey doInsert(Criteria criteria, Connection con) 212 throws TorqueException 213 { 214 215 setDbName(criteria); 216 217 if (con == null) 218 { 219 return BasePeer.doInsert(criteria); 220 } 221 else 222 { 223 return BasePeer.doInsert(criteria, con); 224 } 225 } 226 227 234 public static void addSelectColumns(Criteria criteria) 235 throws TorqueException 236 { 237 criteria.addSelectColumn(INBOX_ATTACHMENT_ID); 238 criteria.addSelectColumn(INBOX_EVENT_ID); 239 criteria.addSelectColumn(CONTENT_TYPE); 240 criteria.addSelectColumn(CONTENT_DISPOSITION); 241 criteria.addSelectColumn(CONTENT_ID); 242 criteria.addSelectColumn(FILE_NAME); 243 criteria.addSelectColumn(CONTENT); 244 } 245 246 255 public static InboxAttachment row2Object(Record row, 256 int offset, 257 Class cls) 258 throws TorqueException 259 { 260 try 261 { 262 InboxAttachment obj = (InboxAttachment) cls.newInstance(); 263 InboxAttachmentPeer.populateObject(row, offset, obj); 264 obj.setModified(false); 265 obj.setNew(false); 266 267 return obj; 268 } 269 catch (InstantiationException e) 270 { 271 throw new TorqueException(e); 272 } 273 catch (IllegalAccessException e) 274 { 275 throw new TorqueException(e); 276 } 277 } 278 279 288 public static void populateObject(Record row, 289 int offset, 290 InboxAttachment obj) 291 throws TorqueException 292 { 293 try 294 { 295 obj.setInboxAttachmentId(row.getValue(offset + 0).asInt()); 296 obj.setInboxEventId(row.getValue(offset + 1).asInt()); 297 obj.setContentType(row.getValue(offset + 2).asString()); 298 obj.setContentDisposition(row.getValue(offset + 3).asString()); 299 obj.setContentId(row.getValue(offset + 4).asString()); 300 obj.setFileName(row.getValue(offset + 5).asString()); 301 obj.setContent(row.getValue(offset + 6).asString()); 302 } 303 catch (DataSetException e) 304 { 305 throw new TorqueException(e); 306 } 307 } 308 309 317 public static List doSelect(Criteria criteria) throws TorqueException 318 { 319 return populateObjects(doSelectVillageRecords(criteria)); 320 } 321 322 331 public static List doSelect(Criteria criteria, Connection con) 332 throws TorqueException 333 { 334 return populateObjects(doSelectVillageRecords(criteria, con)); 335 } 336 337 347 public static List doSelectVillageRecords(Criteria criteria) 348 throws TorqueException 349 { 350 return BaseInboxAttachmentPeer 351 .doSelectVillageRecords(criteria, (Connection ) null); 352 } 353 354 363 public static List doSelectVillageRecords(Criteria criteria, Connection con) 364 throws TorqueException 365 { 366 if (criteria.getSelectColumns().size() == 0) 367 { 368 addSelectColumns(criteria); 369 } 370 371 372 setDbName(criteria); 373 374 if (con == null) 377 { 378 return BasePeer.doSelect(criteria); 379 } 380 else 381 { 382 return BasePeer.doSelect(criteria, con); 383 } 384 } 385 386 393 public static List populateObjects(List records) 394 throws TorqueException 395 { 396 List results = new ArrayList (records.size()); 397 398 for (int i = 0; i < records.size(); i++) 400 { 401 Record row = (Record) records.get(i); 402 results.add(InboxAttachmentPeer.row2Object(row, 1, 403 InboxAttachmentPeer.getOMClass())); 404 } 405 return results; 406 } 407 408 409 417 public static Class getOMClass() 418 throws TorqueException 419 { 420 return CLASS_DEFAULT; 421 } 422 423 431 public static void doUpdate(Criteria criteria) throws TorqueException 432 { 433 BaseInboxAttachmentPeer 434 .doUpdate(criteria, (Connection ) null); 435 } 436 437 448 public static void doUpdate(Criteria criteria, Connection con) 449 throws TorqueException 450 { 451 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 452 selectCriteria.put(INBOX_ATTACHMENT_ID, criteria.remove(INBOX_ATTACHMENT_ID)); 453 454 setDbName(criteria); 455 456 if (con == null) 457 { 458 BasePeer.doUpdate(selectCriteria, criteria); 459 } 460 else 461 { 462 BasePeer.doUpdate(selectCriteria, criteria, con); 463 } 464 } 465 466 473 public static void doDelete(Criteria criteria) throws TorqueException 474 { 475 InboxAttachmentPeer 476 .doDelete(criteria, (Connection ) null); 477 } 478 479 489 public static void doDelete(Criteria criteria, Connection con) 490 throws TorqueException 491 { 492 493 setDbName(criteria); 494 495 if (con == null) 496 { 497 BasePeer.doDelete(criteria); 498 } 499 else 500 { 501 BasePeer.doDelete(criteria, con); 502 } 503 } 504 505 511 public static List doSelect(InboxAttachment obj) throws TorqueException 512 { 513 return doSelect(buildSelectCriteria(obj)); 514 } 515 516 522 public static void doInsert(InboxAttachment obj) throws TorqueException 523 { 524 obj.setPrimaryKey(doInsert(buildCriteria(obj))); 525 obj.setNew(false); 526 obj.setModified(false); 527 } 528 529 534 public static void doUpdate(InboxAttachment obj) throws TorqueException 535 { 536 doUpdate(buildCriteria(obj)); 537 obj.setModified(false); 538 } 539 540 545 public static void doDelete(InboxAttachment obj) throws TorqueException 546 { 547 doDelete(buildSelectCriteria(obj)); 548 } 549 550 560 public static void doInsert(InboxAttachment obj, Connection con) 561 throws TorqueException 562 { 563 obj.setPrimaryKey(doInsert(buildCriteria(obj), con)); 564 obj.setNew(false); 565 obj.setModified(false); 566 } 567 568 578 public static void doUpdate(InboxAttachment obj, Connection con) 579 throws TorqueException 580 { 581 doUpdate(buildCriteria(obj), con); 582 obj.setModified(false); 583 } 584 585 595 public static void doDelete(InboxAttachment obj, Connection con) 596 throws TorqueException 597 { 598 doDelete(buildSelectCriteria(obj), con); 599 } 600 601 608 public static void doDelete(ObjectKey pk) throws TorqueException 609 { 610 BaseInboxAttachmentPeer 611 .doDelete(pk, (Connection ) null); 612 } 613 614 624 public static void doDelete(ObjectKey pk, Connection con) 625 throws TorqueException 626 { 627 doDelete(buildCriteria(pk), con); 628 } 629 630 631 public static Criteria buildCriteria( ObjectKey pk ) 632 { 633 Criteria criteria = new Criteria(); 634 criteria.add(INBOX_ATTACHMENT_ID, pk); 635 return criteria; 636 } 637 638 639 public static Criteria buildCriteria( InboxAttachment obj ) 640 { 641 Criteria criteria = new Criteria(DATABASE_NAME); 642 if (!obj.isNew()) 643 criteria.add(INBOX_ATTACHMENT_ID, obj.getInboxAttachmentId()); 644 criteria.add(INBOX_EVENT_ID, obj.getInboxEventId()); 645 criteria.add(CONTENT_TYPE, obj.getContentType()); 646 criteria.add(CONTENT_DISPOSITION, obj.getContentDisposition()); 647 criteria.add(CONTENT_ID, obj.getContentId()); 648 criteria.add(FILE_NAME, obj.getFileName()); 649 criteria.add(CONTENT, obj.getContent()); 650 return criteria; 651 } 652 653 654 public static Criteria buildSelectCriteria( InboxAttachment obj ) 655 { 656 Criteria criteria = new Criteria(DATABASE_NAME); 657 if (!obj.isNew()) 658 criteria.add(INBOX_ATTACHMENT_ID, obj.getInboxAttachmentId()); 659 criteria.add(INBOX_EVENT_ID, obj.getInboxEventId()); 660 criteria.add(CONTENT_TYPE, obj.getContentType()); 661 criteria.add(CONTENT_DISPOSITION, obj.getContentDisposition()); 662 criteria.add(CONTENT_ID, obj.getContentId()); 663 criteria.add(FILE_NAME, obj.getFileName()); 664 criteria.add(CONTENT, obj.getContent()); 665 return criteria; 666 } 667 668 669 678 public static InboxAttachment retrieveByPK(int pk) 679 throws TorqueException, NoRowsException, TooManyRowsException 680 { 681 return retrieveByPK(SimpleKey.keyFor(pk)); 682 } 683 684 694 public static InboxAttachment retrieveByPK(int pk, Connection con) 695 throws TorqueException, NoRowsException, TooManyRowsException 696 { 697 return retrieveByPK(SimpleKey.keyFor(pk), con); 698 } 699 700 709 public static InboxAttachment retrieveByPK(ObjectKey pk) 710 throws TorqueException, NoRowsException, TooManyRowsException 711 { 712 Connection db = null; 713 InboxAttachment retVal = null; 714 try 715 { 716 db = Torque.getConnection(DATABASE_NAME); 717 retVal = retrieveByPK(pk, db); 718 } 719 finally 720 { 721 Torque.closeConnection(db); 722 } 723 return(retVal); 724 } 725 726 736 public static InboxAttachment retrieveByPK(ObjectKey pk, Connection con) 737 throws TorqueException, NoRowsException, TooManyRowsException 738 { 739 Criteria criteria = buildCriteria(pk); 740 List v = doSelect(criteria, con); 741 if (v.size() == 0) 742 { 743 throw new NoRowsException("Failed to select a row."); 744 } 745 else if (v.size() > 1) 746 { 747 throw new TooManyRowsException("Failed to select only one row."); 748 } 749 else 750 { 751 return (InboxAttachment)v.get(0); 752 } 753 } 754 755 762 public static List retrieveByPKs(List pks) 763 throws TorqueException 764 { 765 Connection db = null; 766 List retVal = null; 767 try 768 { 769 db = Torque.getConnection(DATABASE_NAME); 770 retVal = retrieveByPKs(pks, db); 771 } 772 finally 773 { 774 Torque.closeConnection(db); 775 } 776 return(retVal); 777 } 778 779 787 public static List retrieveByPKs( List pks, Connection dbcon ) 788 throws TorqueException 789 { 790 List objs = null; 791 if (pks == null || pks.size() == 0) 792 { 793 objs = new LinkedList (); 794 } 795 else 796 { 797 Criteria criteria = new Criteria(); 798 criteria.addIn( INBOX_ATTACHMENT_ID, pks ); 799 objs = doSelect(criteria, dbcon); 800 } 801 return objs; 802 } 803 804 805 806 807 808 809 810 811 812 813 824 protected static List doSelectJoinInboxEvent(Criteria criteria) 825 throws TorqueException 826 { 827 setDbName(criteria); 828 829 InboxAttachmentPeer.addSelectColumns(criteria); 830 int offset = numColumns + 1; 831 InboxEventPeer.addSelectColumns(criteria); 832 833 834 criteria.addJoin(InboxAttachmentPeer.INBOX_EVENT_ID, 835 InboxEventPeer.INBOX_EVENT_ID); 836 837 838 839 List rows = BasePeer.doSelect(criteria); 840 List results = new ArrayList (); 841 842 for (int i = 0; i < rows.size(); i++) 843 { 844 Record row = (Record) rows.get(i); 845 846 Class omClass = InboxAttachmentPeer.getOMClass(); 847 InboxAttachment obj1 = (InboxAttachment) InboxAttachmentPeer 848 .row2Object(row, 1, omClass); 849 omClass = InboxEventPeer.getOMClass(); 850 InboxEvent obj2 = (InboxEvent)InboxEventPeer 851 .row2Object(row, offset, omClass); 852 853 boolean newObject = true; 854 for (int j = 0; j < results.size(); j++) 855 { 856 InboxAttachment temp_obj1 = (InboxAttachment)results.get(j); 857 InboxEvent temp_obj2 = (InboxEvent)temp_obj1.getInboxEvent(); 858 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 859 { 860 newObject = false; 861 temp_obj2.addInboxAttachment(obj1); 862 break; 863 } 864 } 865 if (newObject) 866 { 867 obj2.initInboxAttachments(); 868 obj2.addInboxAttachment(obj1); 869 } 870 results.add(obj1); 871 } 872 return results; 873 } 874 875 876 877 878 885 protected static TableMap getTableMap() 886 throws TorqueException 887 { 888 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 889 } 890 891 private static void setDbName(Criteria crit) 892 { 893 if (crit.getDbName() == Torque.getDefaultDB()) 897 { 898 crit.setDbName(DATABASE_NAME); 899 } 900 } 901 } 902
| Popular Tags
|