1 package org.apache.fulcrum.security.impl.db.entity; 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.fulcrum.security.impl.db.entity.map.*; 32 33 34 36 public abstract class BaseTurbineUserPeer 37 extends BasePeer 38 { 39 40 41 public static final String DATABASE_NAME = "scarab"; 42 43 44 public static final String TABLE_NAME = "TURBINE_USER"; 45 46 51 public static MapBuilder getMapBuilder() 52 throws TorqueException 53 { 54 return getMapBuilder(TurbineUserMapBuilder.CLASS_NAME); 55 } 56 57 58 public static final String USER_ID; 59 60 public static final String LOGIN_NAME; 61 62 public static final String PASSWORD_VALUE; 63 64 public static final String FIRST_NAME; 65 66 public static final String LAST_NAME; 67 68 public static final String EMAIL; 69 70 public static final String CONFIRM_VALUE; 71 72 public static final String MODIFIED; 73 74 public static final String CREATED; 75 76 public static final String LAST_LOGIN; 77 78 public static final String OBJECTDATA; 79 80 static 81 { 82 USER_ID = "TURBINE_USER.USER_ID"; 83 LOGIN_NAME = "TURBINE_USER.LOGIN_NAME"; 84 PASSWORD_VALUE = "TURBINE_USER.PASSWORD_VALUE"; 85 FIRST_NAME = "TURBINE_USER.FIRST_NAME"; 86 LAST_NAME = "TURBINE_USER.LAST_NAME"; 87 EMAIL = "TURBINE_USER.EMAIL"; 88 CONFIRM_VALUE = "TURBINE_USER.CONFIRM_VALUE"; 89 MODIFIED = "TURBINE_USER.MODIFIED"; 90 CREATED = "TURBINE_USER.CREATED"; 91 LAST_LOGIN = "TURBINE_USER.LAST_LOGIN"; 92 OBJECTDATA = "TURBINE_USER.OBJECTDATA"; 93 if (Torque.isInit()) 94 { 95 try 96 { 97 getMapBuilder(TurbineUserMapBuilder.CLASS_NAME); 98 } 99 catch (Exception e) 100 { 101 log.error("Could not initialize Peer", e); 102 } 103 } 104 else 105 { 106 Torque.registerMapBuilder(TurbineUserMapBuilder.CLASS_NAME); 107 } 108 } 109 110 111 public static final int numColumns = 11; 112 113 114 protected static final String CLASSNAME_DEFAULT = 115 "org.apache.fulcrum.security.impl.db.entity.TurbineUser"; 116 117 118 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 119 120 126 private static Class initClass(String className) 127 { 128 Class c = null; 129 try 130 { 131 c = Class.forName(className); 132 } 133 catch (Throwable t) 134 { 135 log.error("A FATAL ERROR has occurred which should not " 136 + "have happened under any circumstance. Please notify " 137 + "the Torque developers <torque-dev@db.apache.org> " 138 + "and give as many details as possible (including the error " 139 + "stack trace).", t); 140 141 if (t instanceof Error ) 143 { 144 throw (Error ) t.fillInStackTrace(); 145 } 146 } 147 return c; 148 } 149 150 160 public static List resultSet2Objects(java.sql.ResultSet results) 161 throws TorqueException 162 { 163 try 164 { 165 QueryDataSet qds = null; 166 List rows = null; 167 try 168 { 169 qds = new QueryDataSet(results); 170 rows = getSelectResults(qds); 171 } 172 finally 173 { 174 if (qds != null) 175 { 176 qds.close(); 177 } 178 } 179 180 return populateObjects(rows); 181 } 182 catch (SQLException e) 183 { 184 throw new TorqueException(e); 185 } 186 catch (DataSetException e) 187 { 188 throw new TorqueException(e); 189 } 190 } 191 192 193 194 201 public static ObjectKey doInsert(Criteria criteria) 202 throws TorqueException 203 { 204 return BaseTurbineUserPeer 205 .doInsert(criteria, (Connection ) null); 206 } 207 208 218 public static ObjectKey doInsert(Criteria criteria, Connection con) 219 throws TorqueException 220 { 221 222 if (criteria.getDbName() == Torque.getDefaultDB()) 226 { 227 criteria.setDbName(DATABASE_NAME); 228 } 229 if (con == null) 230 { 231 return BasePeer.doInsert(criteria); 232 } 233 else 234 { 235 return BasePeer.doInsert(criteria, con); 236 } 237 } 238 239 246 public static void addSelectColumns(Criteria criteria) 247 throws TorqueException 248 { 249 criteria.addSelectColumn(USER_ID); 250 criteria.addSelectColumn(LOGIN_NAME); 251 criteria.addSelectColumn(PASSWORD_VALUE); 252 criteria.addSelectColumn(FIRST_NAME); 253 criteria.addSelectColumn(LAST_NAME); 254 criteria.addSelectColumn(EMAIL); 255 criteria.addSelectColumn(CONFIRM_VALUE); 256 criteria.addSelectColumn(MODIFIED); 257 criteria.addSelectColumn(CREATED); 258 criteria.addSelectColumn(LAST_LOGIN); 259 criteria.addSelectColumn(OBJECTDATA); 260 } 261 262 271 public static TurbineUser row2Object(Record row, 272 int offset, 273 Class cls) 274 throws TorqueException 275 { 276 try 277 { 278 TurbineUser obj = (TurbineUser) cls.newInstance(); 279 TurbineUserPeer.populateObject(row, offset, obj); 280 obj.setModified(false); 281 obj.setNew(false); 282 283 return obj; 284 } 285 catch (InstantiationException e) 286 { 287 throw new TorqueException(e); 288 } 289 catch (IllegalAccessException e) 290 { 291 throw new TorqueException(e); 292 } 293 } 294 295 304 public static void populateObject(Record row, 305 int offset, 306 TurbineUser obj) 307 throws TorqueException 308 { 309 try 310 { 311 obj.setUserId(row.getValue(offset + 0).asIntegerObj()); 312 obj.setUserName(row.getValue(offset + 1).asString()); 313 obj.setPassword(row.getValue(offset + 2).asString()); 314 obj.setFirstName(row.getValue(offset + 3).asString()); 315 obj.setLastName(row.getValue(offset + 4).asString()); 316 obj.setEmail(row.getValue(offset + 5).asString()); 317 obj.setConfirmed(row.getValue(offset + 6).asString()); 318 obj.setModified(row.getValue(offset + 7).asUtilDate()); 319 obj.setCreateDate(row.getValue(offset + 8).asUtilDate()); 320 obj.setLastLogin(row.getValue(offset + 9).asUtilDate()); 321 obj.setObjectdata(row.getValue(offset + 10).asBytes()); 322 } 323 catch (DataSetException e) 324 { 325 throw new TorqueException(e); 326 } 327 } 328 329 337 public static List doSelect(Criteria criteria) throws TorqueException 338 { 339 return populateObjects(doSelectVillageRecords(criteria)); 340 } 341 342 351 public static List doSelect(Criteria criteria, Connection con) 352 throws TorqueException 353 { 354 return populateObjects(doSelectVillageRecords(criteria, con)); 355 } 356 357 367 public static List doSelectVillageRecords(Criteria criteria) 368 throws TorqueException 369 { 370 return BaseTurbineUserPeer 371 .doSelectVillageRecords(criteria, (Connection ) null); 372 } 373 374 382 public static List doSelectVillageRecords(Criteria criteria, Connection con) 383 throws TorqueException 384 { 385 if (criteria.getSelectColumns().size() == 0) 386 { 387 addSelectColumns(criteria); 388 } 389 390 391 if (criteria.getDbName() == Torque.getDefaultDB()) 395 { 396 criteria.setDbName(DATABASE_NAME); 397 } 398 if (con == null) 401 { 402 return BasePeer.doSelect(criteria); 403 } 404 else 405 { 406 return BasePeer.doSelect(criteria, con); 407 } 408 } 409 410 417 public static List populateObjects(List records) 418 throws TorqueException 419 { 420 List results = new ArrayList (records.size()); 421 422 for (int i = 0; i < records.size(); i++) 424 { 425 Record row = (Record) records.get(i); 426 results.add(TurbineUserPeer.row2Object(row, 1, 427 TurbineUserPeer.getOMClass())); 428 } 429 return results; 430 } 431 432 433 441 public static Class getOMClass() 442 throws TorqueException 443 { 444 return CLASS_DEFAULT; 445 } 446 447 455 public static void doUpdate(Criteria criteria) throws TorqueException 456 { 457 BaseTurbineUserPeer 458 .doUpdate(criteria, (Connection ) null); 459 } 460 461 472 public static void doUpdate(Criteria criteria, Connection con) 473 throws TorqueException 474 { 475 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 476 selectCriteria.put(USER_ID, criteria.remove(USER_ID)); 477 478 if (criteria.getDbName() == Torque.getDefaultDB()) 482 { 483 criteria.setDbName(DATABASE_NAME); 484 } 485 if (con == null) 486 { 487 BasePeer.doUpdate(selectCriteria, criteria); 488 } 489 else 490 { 491 BasePeer.doUpdate(selectCriteria, criteria, con); 492 } 493 } 494 495 502 public static void doDelete(Criteria criteria) throws TorqueException 503 { 504 BaseTurbineUserPeer 505 .doDelete(criteria, (Connection ) null); 506 } 507 508 518 public static void doDelete(Criteria criteria, Connection con) 519 throws TorqueException 520 { 521 522 if (criteria.getDbName() == Torque.getDefaultDB()) 526 { 527 criteria.setDbName(DATABASE_NAME); 528 } 529 if (con == null) 530 { 531 BasePeer.doDelete(criteria); 532 } 533 else 534 { 535 BasePeer.doDelete(criteria, con); 536 } 537 } 538 539 545 public static List doSelect(TurbineUser obj) throws TorqueException 546 { 547 return doSelect(buildCriteria(obj)); 548 } 549 550 556 public static void doInsert(TurbineUser obj) throws TorqueException 557 { 558 obj.setPrimaryKey(doInsert(buildCriteria(obj))); 559 obj.setNew(false); 560 obj.setModified(false); 561 } 562 563 568 public static void doUpdate(TurbineUser obj) throws TorqueException 569 { 570 doUpdate(buildCriteria(obj)); 571 obj.setModified(false); 572 } 573 574 579 public static void doDelete(TurbineUser obj) throws TorqueException 580 { 581 doDelete(buildCriteria(obj)); 582 } 583 584 594 public static void doInsert(TurbineUser obj, Connection con) 595 throws TorqueException 596 { 597 obj.setPrimaryKey(doInsert(buildCriteria(obj), con)); 598 obj.setNew(false); 599 obj.setModified(false); 600 } 601 602 612 public static void doUpdate(TurbineUser obj, Connection con) 613 throws TorqueException 614 { 615 doUpdate(buildCriteria(obj), con); 616 obj.setModified(false); 617 } 618 619 629 public static void doDelete(TurbineUser obj, Connection con) 630 throws TorqueException 631 { 632 doDelete(buildCriteria(obj), con); 633 } 634 635 642 public static void doDelete(ObjectKey pk) throws TorqueException 643 { 644 BaseTurbineUserPeer 645 .doDelete(pk, (Connection ) null); 646 } 647 648 658 public static void doDelete(ObjectKey pk, Connection con) 659 throws TorqueException 660 { 661 doDelete(buildCriteria(pk), con); 662 } 663 664 665 public static Criteria buildCriteria( ObjectKey pk ) 666 { 667 Criteria criteria = new Criteria(); 668 criteria.add(USER_ID, pk); 669 return criteria; 670 } 671 672 673 public static Criteria buildCriteria( TurbineUser obj ) 674 { 675 Criteria criteria = new Criteria(DATABASE_NAME); 676 if (!obj.isNew()) 677 criteria.add(USER_ID, obj.getUserId()); 678 criteria.add(LOGIN_NAME, obj.getUserName()); 679 criteria.add(PASSWORD_VALUE, obj.getPassword()); 680 criteria.add(FIRST_NAME, obj.getFirstName()); 681 criteria.add(LAST_NAME, obj.getLastName()); 682 criteria.add(EMAIL, obj.getEmail()); 683 criteria.add(CONFIRM_VALUE, obj.getConfirmed()); 684 criteria.add(MODIFIED, obj.getModified()); 685 criteria.add(CREATED, obj.getCreateDate()); 686 criteria.add(LAST_LOGIN, obj.getLastLogin()); 687 criteria.add(OBJECTDATA, obj.getObjectdata()); 688 return criteria; 689 } 690 691 692 701 public static TurbineUser retrieveByPK(Integer pk) 702 throws TorqueException, NoRowsException, TooManyRowsException 703 { 704 return retrieveByPK(SimpleKey.keyFor(pk)); 705 } 706 707 716 public static TurbineUser retrieveByPK(ObjectKey pk) 717 throws TorqueException, NoRowsException, TooManyRowsException 718 { 719 Connection db = null; 720 TurbineUser retVal = null; 721 try 722 { 723 db = Torque.getConnection(DATABASE_NAME); 724 retVal = retrieveByPK(pk, db); 725 } 726 finally 727 { 728 Torque.closeConnection(db); 729 } 730 return(retVal); 731 } 732 733 743 public static TurbineUser retrieveByPK(ObjectKey pk, Connection con) 744 throws TorqueException, NoRowsException, TooManyRowsException 745 { 746 Criteria criteria = buildCriteria(pk); 747 List v = doSelect(criteria, con); 748 if (v.size() == 0) 749 { 750 throw new NoRowsException("Failed to select a row."); 751 } 752 else if (v.size() > 1) 753 { 754 throw new TooManyRowsException("Failed to select only one row."); 755 } 756 else 757 { 758 return (TurbineUser)v.get(0); 759 } 760 } 761 762 769 public static List retrieveByPKs(List pks) 770 throws TorqueException 771 { 772 Connection db = null; 773 List retVal = null; 774 try 775 { 776 db = Torque.getConnection(DATABASE_NAME); 777 retVal = retrieveByPKs(pks, db); 778 } 779 finally 780 { 781 Torque.closeConnection(db); 782 } 783 return(retVal); 784 } 785 786 794 public static List retrieveByPKs( List pks, Connection dbcon ) 795 throws TorqueException 796 { 797 List objs = null; 798 if (pks == null || pks.size() == 0) 799 { 800 objs = new LinkedList (); 801 } 802 else 803 { 804 Criteria criteria = new Criteria(); 805 criteria.addIn( USER_ID, pks ); 806 objs = doSelect(criteria, dbcon); 807 } 808 return objs; 809 } 810 811 812 813 814 815 816 817 818 819 820 827 protected static TableMap getTableMap() 828 throws TorqueException 829 { 830 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 831 } 832 } 833 | Popular Tags |