1packageorg.apache.jetspeed.om.security.turbine;
23import java.math.BigDecimal;
4import java.sql.Connection;
5import java.sql.SQLException;
6import java.util.ArrayList;
7import java.util.Date;
8import java.util.Iterator;
9import java.util.LinkedList;
10import java.util.List;
1112import org.apache.torque.NoRowsException;
13import org.apache.torque.TooManyRowsException;
14import org.apache.torque.Torque;
15import org.apache.torque.TorqueException;
16import org.apache.torque.map.MapBuilder;
17import org.apache.torque.map.TableMap;
18import org.apache.torque.om.DateKey;
19import org.apache.torque.om.NumberKey;
20import org.apache.torque.om.StringKey;
21import org.apache.torque.om.ObjectKey;
22import org.apache.torque.om.SimpleKey;
23import org.apache.torque.util.BasePeer;
24import org.apache.torque.util.Criteria;
2526import com.workingdogs.village.DataSetException;
27import com.workingdogs.village.QueryDataSet;
28import com.workingdogs.village.Record;
2930// Local classes31importorg.apache.jetspeed.om.security.turbine.map.*;
323334/***35 * This class was autogenerated by Torque on:36 *37 * [Thu Apr 22 23:12:36 EDT 2004]38 *39 */40publicabstractclassBaseTurbineRolePeer41extends BasePeer
42 {
4344/*** the default database name for this class */45publicstaticfinal String DATABASE_NAME = "default";
4647/*** the table name for this class */48publicstaticfinal String TABLE_NAME = "TURBINE_ROLE";
4950/***51 * @return the map builder for this peer52 * @throws TorqueException Any exceptions caught during processing will be53 * rethrown wrapped into a TorqueException.54 */55publicstatic MapBuilder getMapBuilder()
56 throws TorqueException
57 {
58return getMapBuilder(TurbineRoleMapBuilder.CLASS_NAME);
59 }
6061/*** the column name for the ROLE_ID field */62publicstaticfinal String ROLE_ID;
63/*** the column name for the ROLE_NAME field */64publicstaticfinal String ROLE_NAME;
65/*** the column name for the OBJECTDATA field */66publicstaticfinal String OBJECTDATA;
6768static69 {
70 ROLE_ID = "TURBINE_ROLE.ROLE_ID";
71 ROLE_NAME = "TURBINE_ROLE.ROLE_NAME";
72 OBJECTDATA = "TURBINE_ROLE.OBJECTDATA";
73if (Torque.isInit())
74 {
75try76 {
77 getMapBuilder();
78 }
79catch (Exception e)
80 {
81 log.error("Could not initialize Peer", e);
82 }
83 }
84else85 {
86 Torque.registerMapBuilder(TurbineRoleMapBuilder.CLASS_NAME);
87 }
88 }
8990/*** number of columns for this peer */91publicstaticfinalint numColumns = 3;
9293/*** A class that can be returned by this peer. */94protectedstaticfinal String CLASSNAME_DEFAULT =
95"org.apache.jetspeed.om.security.turbine.TurbineRole";
9697/*** A class that can be returned by this peer. */98protectedstaticfinal Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
99100/***101 * Class object initialization method.102 *103 * @param className name of the class to initialize104 * @return the initialized class105 */106privatestatic Class initClass(String className)
107 {
108 Class c = null;
109try110 {
111 c = Class.forName(className);
112 }
113catch (Throwable t)
114 {
115 log.error("A FATAL ERROR has occurred which should not "116 + "have happened under any circumstance. Please notify "117 + "the Torque developers <turbine-torque-dev@jakarta.apache.org> "118 + "and give as many details as possible (including the error "119 + "stack trace).", t);
120121// Error objects should always be propogated.122if (t instanceof Error)
123 {
124throw (Error) t.fillInStackTrace();
125 }
126 }
127return c;
128 }
129130/***131 * Get the list of objects for a ResultSet. Please not that your132 * resultset MUST return columns in the right order. You can use133 * getFieldNames() in BaseObject to get the correct sequence.134 *135 * @param results the ResultSet136 * @return the list of objects137 * @throws TorqueException Any exceptions caught during processing will be138 * rethrown wrapped into a TorqueException.139 */140publicstatic List resultSet2Objects(java.sql.ResultSet results)
141 throws TorqueException
142 {
143try144 {
145 QueryDataSet qds = null;
146 List rows = null;
147try148 {
149 qds = new QueryDataSet(results);
150 rows = getSelectResults(qds);
151 }
152finally153 {
154if (qds != null)
155 {
156 qds.close();
157 }
158 }
159160return populateObjects(rows);
161 }
162catch (SQLException e)
163 {
164thrownew TorqueException(e);
165 }
166catch (DataSetException e)
167 {
168thrownew TorqueException(e);
169 }
170 }
171172173174/***175 * Method to do inserts.176 *177 * @param criteria object used to create the INSERT statement.178 * @throws TorqueException Any exceptions caught during processing will be179 * rethrown wrapped into a TorqueException.180 */181publicstatic ObjectKey doInsert(Criteria criteria)
182 throws TorqueException
183 {
184returnBaseTurbineRolePeer185 .doInsert(criteria, (Connection) null);
186 }
187188/***189 * Method to do inserts. This method is to be used during a transaction,190 * otherwise use the doInsert(Criteria) method. It will take care of191 * the connection details internally.192 *193 * @param criteria object used to create the INSERT statement.194 * @param con the connection to use195 * @throws TorqueException Any exceptions caught during processing will be196 * rethrown wrapped into a TorqueException.197 */198publicstatic ObjectKey doInsert(Criteria criteria, Connection con)
199 throws TorqueException
200 {
201202// Set the correct dbName if it has not been overridden203// criteria.getDbName will return the same object if not set to204// another value so == check is okay and faster205if (criteria.getDbName() == Torque.getDefaultDB())
206 {
207 criteria.setDbName(DATABASE_NAME);
208 }
209if (con == null)
210 {
211return BasePeer.doInsert(criteria);
212 }
213else214 {
215return BasePeer.doInsert(criteria, con);
216 }
217 }
218219/***220 * Add all the columns needed to create a new object.221 *222 * @param criteria object containing the columns to add.223 * @throws TorqueException Any exceptions caught during processing will be224 * rethrown wrapped into a TorqueException.225 */226publicstaticvoid addSelectColumns(Criteria criteria)
227 throws TorqueException
228 {
229 criteria.addSelectColumn(ROLE_ID);
230 criteria.addSelectColumn(ROLE_NAME);
231 criteria.addSelectColumn(OBJECTDATA);
232 }
233234/***235 * Create a new object of type cls from a resultset row starting236 * from a specified offset. This is done so that you can select237 * other rows than just those needed for this object. You may238 * for example want to create two objects from the same row.239 *240 * @throws TorqueException Any exceptions caught during processing will be241 * rethrown wrapped into a TorqueException.242 */243publicstaticTurbineRole row2Object(Record row,
244int offset,
245 Class cls)
246 throws TorqueException
247 {
248try249 {
250TurbineRole obj = (TurbineRole) cls.newInstance();
251 TurbineRolePeer.populateObject(row, offset, obj);
252 obj.setModified(false);
253 obj.setNew(false);
254255return obj;
256 }
257catch (InstantiationException e)
258 {
259thrownew TorqueException(e);
260 }
261catch (IllegalAccessException e)
262 {
263thrownew TorqueException(e);
264 }
265 }
266267/***268 * Populates an object from a resultset row starting269 * from a specified offset. This is done so that you can select270 * other rows than just those needed for this object. You may271 * for example want to create two objects from the same row.272 *273 * @throws TorqueException Any exceptions caught during processing will be274 * rethrown wrapped into a TorqueException.275 */276publicstaticvoid populateObject(Record row,
277int offset,
278TurbineRole obj)
279 throws TorqueException
280 {
281try282 {
283 obj.setRoleId(row.getValue(offset + 0).asInt());
284 obj.setRoleName(row.getValue(offset + 1).asString());
285 obj.setObjectdata(row.getValue(offset + 2).asBytes());
286 }
287catch (DataSetException e)
288 {
289thrownew TorqueException(e);
290 }
291 }
292293/***294 * Method to do selects.295 *296 * @param criteria object used to create the SELECT statement.297 * @return List of selected Objects298 * @throws TorqueException Any exceptions caught during processing will be299 * rethrown wrapped into a TorqueException.300 */301publicstatic List doSelect(Criteria criteria) throws TorqueException
302 {
303return populateObjects(doSelectVillageRecords(criteria));
304 }
305306/***307 * Method to do selects within a transaction.308 *309 * @param criteria object used to create the SELECT statement.310 * @param con the connection to use311 * @return List of selected Objects312 * @throws TorqueException Any exceptions caught during processing will be313 * rethrown wrapped into a TorqueException.314 */315publicstatic List doSelect(Criteria criteria, Connection con)
316 throws TorqueException
317 {
318return populateObjects(doSelectVillageRecords(criteria, con));
319 }
320321/***322 * Grabs the raw Village records to be formed into objects.323 * This method handles connections internally. The Record objects324 * returned by this method should be considered readonly. Do not325 * alter the data and call save(), your results may vary, but are326 * certainly likely to result in hard to track MT bugs.327 *328 * @throws TorqueException Any exceptions caught during processing will be329 * rethrown wrapped into a TorqueException.330 */331publicstatic List doSelectVillageRecords(Criteria criteria)
332 throws TorqueException
333 {
334returnBaseTurbineRolePeer335 .doSelectVillageRecords(criteria, (Connection) null);
336 }
337338/***339 * Grabs the raw Village records to be formed into objects.340 * This method should be used for transactions341 *342 * @param con the connection to use343 * @throws TorqueException Any exceptions caught during processing will be344 * rethrown wrapped into a TorqueException.345 */346publicstatic List doSelectVillageRecords(Criteria criteria, Connection con)
347 throws TorqueException
348 {
349if (criteria.getSelectColumns().size() == 0)
350 {
351 addSelectColumns(criteria);
352 }
353354355// Set the correct dbName if it has not been overridden356// criteria.getDbName will return the same object if not set to357// another value so == check is okay and faster358if (criteria.getDbName() == Torque.getDefaultDB())
359 {
360 criteria.setDbName(DATABASE_NAME);
361 }
362// BasePeer returns a List of Value (Village) arrays. The array363// order follows the order columns were placed in the Select clause.364if (con == null)
365 {
366return BasePeer.doSelect(criteria);
367 }
368else369 {
370return BasePeer.doSelect(criteria, con);
371 }
372 }
373374/***375 * The returned List will contain objects of the default type or376 * objects that inherit from the default.377 *378 * @throws TorqueException Any exceptions caught during processing will be379 * rethrown wrapped into a TorqueException.380 */381publicstatic List populateObjects(List records)
382 throws TorqueException
383 {
384 List results = new ArrayList(records.size());
385386// populate the object(s)387for (int i = 0; i < records.size(); i++)
388 {
389 Record row = (Record) records.get(i);
390 results.add(TurbineRolePeer.row2Object(row, 1,
391 TurbineRolePeer.getOMClass()));
392 }
393return results;
394 }
395396397/***398 * The class that the Peer will make instances of.399 * If the BO is abstract then you must implement this method400 * in the BO.401 *402 * @throws TorqueException Any exceptions caught during processing will be403 * rethrown wrapped into a TorqueException.404 */405publicstatic Class getOMClass()
406 throws TorqueException
407 {
408return CLASS_DEFAULT;
409 }
410411/***412 * Method to do updates.413 *414 * @param criteria object containing data that is used to create the UPDATE415 * statement.416 * @throws TorqueException Any exceptions caught during processing will be417 * rethrown wrapped into a TorqueException.418 */419publicstaticvoid doUpdate(Criteria criteria) throws TorqueException
420 {
421BaseTurbineRolePeer422 .doUpdate(criteria, (Connection) null);
423 }
424425/***426 * Method to do updates. This method is to be used during a transaction,427 * otherwise use the doUpdate(Criteria) method. It will take care of428 * the connection details internally.429 *430 * @param criteria object containing data that is used to create the UPDATE431 * statement.432 * @param con the connection to use433 * @throws TorqueException Any exceptions caught during processing will be434 * rethrown wrapped into a TorqueException.435 */436publicstaticvoid doUpdate(Criteria criteria, Connection con)
437 throws TorqueException
438 {
439 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
440 selectCriteria.put(ROLE_ID, criteria.remove(ROLE_ID));
441442// Set the correct dbName if it has not been overridden443// criteria.getDbName will return the same object if not set to444// another value so == check is okay and faster445if (criteria.getDbName() == Torque.getDefaultDB())
446 {
447 criteria.setDbName(DATABASE_NAME);
448 }
449if (con == null)
450 {
451 BasePeer.doUpdate(selectCriteria, criteria);
452 }
453else454 {
455 BasePeer.doUpdate(selectCriteria, criteria, con);
456 }
457 }
458459/***460 * Method to do deletes.461 *462 * @param criteria object containing data that is used DELETE from database.463 * @throws TorqueException Any exceptions caught during processing will be464 * rethrown wrapped into a TorqueException.465 */466publicstaticvoid doDelete(Criteria criteria) throws TorqueException
467 {
468BaseTurbineRolePeer469 .doDelete(criteria, (Connection) null);
470 }
471472/***473 * Method to do deletes. This method is to be used during a transaction,474 * otherwise use the doDelete(Criteria) method. It will take care of475 * the connection details internally.476 *477 * @param criteria object containing data that is used DELETE from database.478 * @param con the connection to use479 * @throws TorqueException Any exceptions caught during processing will be480 * rethrown wrapped into a TorqueException.481 */482publicstaticvoid doDelete(Criteria criteria, Connection con)
483 throws TorqueException
484 {
485486// Set the correct dbName if it has not been overridden487// criteria.getDbName will return the same object if not set to488// another value so == check is okay and faster489if (criteria.getDbName() == Torque.getDefaultDB())
490 {
491 criteria.setDbName(DATABASE_NAME);
492 }
493if (con == null)
494 {
495 BasePeer.doDelete(criteria);
496 }
497else498 {
499 BasePeer.doDelete(criteria, con);
500 }
501 }
502503/***504 * Method to do selects505 *506 * @throws TorqueException Any exceptions caught during processing will be507 * rethrown wrapped into a TorqueException.508 */509publicstatic List doSelect(TurbineRole obj) throws TorqueException
510 {
511return doSelect(buildCriteria(obj));
512 }
513514/***515 * Method to do inserts516 *517 * @throws TorqueException Any exceptions caught during processing will be518 * rethrown wrapped into a TorqueException.519 */520publicstaticvoid doInsert(TurbineRole obj) throws TorqueException
521 {
522 obj.setPrimaryKey(doInsert(buildCriteria(obj)));
523 obj.setNew(false);
524 obj.setModified(false);
525 }
526527/***528 * @param obj the data object to update in the database.529 * @throws TorqueException Any exceptions caught during processing will be530 * rethrown wrapped into a TorqueException.531 */532publicstaticvoid doUpdate(TurbineRole obj) throws TorqueException
533 {
534 doUpdate(buildCriteria(obj));
535 obj.setModified(false);
536 }
537538/***539 * @param obj the data object to delete in the database.540 * @throws TorqueException Any exceptions caught during processing will be541 * rethrown wrapped into a TorqueException.542 */543publicstaticvoid doDelete(TurbineRole obj) throws TorqueException
544 {
545 doDelete(buildCriteria(obj));
546 }
547548/***549 * Method to do inserts. This method is to be used during a transaction,550 * otherwise use the doInsert(TurbineRole) method. It will take551 * care of the connection details internally.552 *553 * @param obj the data object to insert into the database.554 * @param con the connection to use555 * @throws TorqueException Any exceptions caught during processing will be556 * rethrown wrapped into a TorqueException.557 */558publicstaticvoid doInsert(TurbineRole obj, Connection con)
559 throws TorqueException
560 {
561 obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
562 obj.setNew(false);
563 obj.setModified(false);
564 }
565566/***567 * Method to do update. This method is to be used during a transaction,568 * otherwise use the doUpdate(TurbineRole) method. It will take569 * care of the connection details internally.570 *571 * @param obj the data object to update in the database.572 * @param con the connection to use573 * @throws TorqueException Any exceptions caught during processing will be574 * rethrown wrapped into a TorqueException.575 */576publicstaticvoid doUpdate(TurbineRole obj, Connection con)
577 throws TorqueException
578 {
579 doUpdate(buildCriteria(obj), con);
580 obj.setModified(false);
581 }
582583/***584 * Method to delete. This method is to be used during a transaction,585 * otherwise use the doDelete(TurbineRole) method. It will take586 * care of the connection details internally.587 *588 * @param obj the data object to delete in the database.589 * @param con the connection to use590 * @throws TorqueException Any exceptions caught during processing will be591 * rethrown wrapped into a TorqueException.592 */593publicstaticvoid doDelete(TurbineRole obj, Connection con)
594 throws TorqueException
595 {
596 doDelete(buildCriteria(obj), con);
597 }
598599/***600 * Method to do deletes.601 *602 * @param pk ObjectKey that is used DELETE from database.603 * @throws TorqueException Any exceptions caught during processing will be604 * rethrown wrapped into a TorqueException.605 */606publicstaticvoid doDelete(ObjectKey pk) throws TorqueException
607 {
608BaseTurbineRolePeer609 .doDelete(pk, (Connection) null);
610 }
611612/***613 * Method to delete. This method is to be used during a transaction,614 * otherwise use the doDelete(ObjectKey) method. It will take615 * care of the connection details internally.616 *617 * @param pk the primary key for the object to delete in the database.618 * @param con the connection to use619 * @throws TorqueException Any exceptions caught during processing will be620 * rethrown wrapped into a TorqueException.621 */622publicstaticvoid doDelete(ObjectKey pk, Connection con)
623 throws TorqueException
624 {
625 doDelete(buildCriteria(pk), con);
626 }
627628/*** Build a Criteria object from an ObjectKey */629publicstatic Criteria buildCriteria( ObjectKey pk )
630 {
631 Criteria criteria = new Criteria();
632 criteria.add(ROLE_ID, pk);
633return criteria;
634 }
635636/*** Build a Criteria object from the data object for this peer */637publicstatic Criteria buildCriteria( TurbineRole obj )
638 {
639 Criteria criteria = new Criteria(DATABASE_NAME);
640if (!obj.isNew())
641 criteria.add(ROLE_ID, obj.getRoleId());
642 criteria.add(ROLE_NAME, obj.getRoleName());
643 criteria.add(OBJECTDATA, obj.getObjectdata());
644return criteria;
645 }
646647648/***649 * Retrieve a single object by pk650 *651 * @param pk the primary key652 * @throws TorqueException Any exceptions caught during processing will be653 * rethrown wrapped into a TorqueException.654 * @throws NoRowsException Primary key was not found in database.655 * @throws TooManyRowsException Primary key was not found in database.656 */657publicstaticTurbineRole retrieveByPK(int pk)
658 throws TorqueException, NoRowsException, TooManyRowsException
659 {
660return retrieveByPK(SimpleKey.keyFor(pk));
661 }
662663/***664 * Retrieve a single object by pk665 *666 * @param pk the primary key667 * @throws TorqueException Any exceptions caught during processing will be668 * rethrown wrapped into a TorqueException.669 * @throws NoRowsException Primary key was not found in database.670 * @throws TooManyRowsException Primary key was not found in database.671 */672publicstaticTurbineRole retrieveByPK(ObjectKey pk)
673 throws TorqueException, NoRowsException, TooManyRowsException
674 {
675 Connection db = null;
676TurbineRole retVal = null;
677try678 {
679 db = Torque.getConnection(DATABASE_NAME);
680 retVal = retrieveByPK(pk, db);
681 }
682finally683 {
684 Torque.closeConnection(db);
685 }
686return(retVal);
687 }
688689/***690 * Retrieve a single object by pk691 *692 * @param pk the primary key693 * @param con the connection to use694 * @throws TorqueException Any exceptions caught during processing will be695 * rethrown wrapped into a TorqueException.696 * @throws NoRowsException Primary key was not found in database.697 * @throws TooManyRowsException Primary key was not found in database.698 */699publicstaticTurbineRole retrieveByPK(ObjectKey pk, Connection con)
700 throws TorqueException, NoRowsException, TooManyRowsException
701 {
702 Criteria criteria = buildCriteria(pk);
703 List v = doSelect(criteria, con);
704if (v.size() == 0)
705 {
706thrownew NoRowsException("Failed to select a row.");
707 }
708elseif (v.size() > 1)
709 {
710thrownew TooManyRowsException("Failed to select only one row.");
711 }
712else713 {
714return (TurbineRole)v.get(0);
715 }
716 }
717718/***719 * Retrieve a multiple objects by pk720 *721 * @param pks List of primary keys722 * @throws TorqueException Any exceptions caught during processing will be723 * rethrown wrapped into a TorqueException.724 */725publicstatic List retrieveByPKs(List pks)
726 throws TorqueException
727 {
728 Connection db = null;
729 List retVal = null;
730try731 {
732 db = Torque.getConnection(DATABASE_NAME);
733 retVal = retrieveByPKs(pks, db);
734 }
735finally736 {
737 Torque.closeConnection(db);
738 }
739return(retVal);
740 }
741742/***743 * Retrieve a multiple objects by pk744 *745 * @param pks List of primary keys746 * @param dbcon the connection to use747 * @throws TorqueException Any exceptions caught during processing will be748 * rethrown wrapped into a TorqueException.749 */750publicstatic List retrieveByPKs( List pks, Connection dbcon )
751 throws TorqueException
752 {
753 List objs = null;
754if (pks == null || pks.size() == 0)
755 {
756 objs = new LinkedList();
757 }
758else759 {
760 Criteria criteria = new Criteria();
761 criteria.addIn( ROLE_ID, pks );
762 objs = doSelect(criteria, dbcon);
763 }
764return objs;
765 }
766767768769770771772773774775776/***777 * Returns the TableMap related to this peer. This method is not778 * needed for general use but a specific application could have a need.779 *780 * @throws TorqueException Any exceptions caught during processing will be781 * rethrown wrapped into a TorqueException.782 */783protectedstatic TableMap getTableMap()
784 throws TorqueException
785 {
786return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
787 }
788 }