1packageorg.apache.jetspeed.om.dbregistry;
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.dbregistry.map.*;
32333435/***36 * This class was autogenerated by Torque on:37 *38 * [Thu Apr 22 23:12:36 EDT 2004]39 *40 */41publicabstractclassBasePortletCategoryPeer42extends BasePeer
43 {
4445/*** the default database name for this class */46publicstaticfinal String DATABASE_NAME = "default";
4748/*** the table name for this class */49publicstaticfinal String TABLE_NAME = "CATEGORY";
5051/***52 * @return the map builder for this peer53 * @throws TorqueException Any exceptions caught during processing will be54 * rethrown wrapped into a TorqueException.55 */56publicstatic MapBuilder getMapBuilder()
57 throws TorqueException
58 {
59return getMapBuilder(PortletCategoryMapBuilder.CLASS_NAME);
60 }
6162/*** the column name for the ID field */63publicstaticfinal String ID;
64/*** the column name for the NAME field */65publicstaticfinal String NAME;
66/*** the column name for the GROUPE field */67publicstaticfinal String GROUPE;
68/*** the column name for the OWNER field */69publicstaticfinal String OWNER;
7071static72 {
73 ID = "CATEGORY.ID";
74 NAME = "CATEGORY.NAME";
75 GROUPE = "CATEGORY.GROUPE";
76 OWNER = "CATEGORY.OWNER";
77if (Torque.isInit())
78 {
79try80 {
81 getMapBuilder();
82 }
83catch (Exception e)
84 {
85 log.error("Could not initialize Peer", e);
86 }
87 }
88else89 {
90 Torque.registerMapBuilder(PortletCategoryMapBuilder.CLASS_NAME);
91 }
92 }
9394/*** number of columns for this peer */95publicstaticfinalint numColumns = 4;
9697/*** A class that can be returned by this peer. */98protectedstaticfinal String CLASSNAME_DEFAULT =
99"org.apache.jetspeed.om.dbregistry.PortletCategory";
100101/*** A class that can be returned by this peer. */102protectedstaticfinal Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
103104/***105 * Class object initialization method.106 *107 * @param className name of the class to initialize108 * @return the initialized class109 */110privatestatic Class initClass(String className)
111 {
112 Class c = null;
113try114 {
115 c = Class.forName(className);
116 }
117catch (Throwable t)
118 {
119 log.error("A FATAL ERROR has occurred which should not "120 + "have happened under any circumstance. Please notify "121 + "the Torque developers <turbine-torque-dev@jakarta.apache.org> "122 + "and give as many details as possible (including the error "123 + "stack trace).", t);
124125// Error objects should always be propogated.126if (t instanceof Error)
127 {
128throw (Error) t.fillInStackTrace();
129 }
130 }
131return c;
132 }
133134/***135 * Get the list of objects for a ResultSet. Please not that your136 * resultset MUST return columns in the right order. You can use137 * getFieldNames() in BaseObject to get the correct sequence.138 *139 * @param results the ResultSet140 * @return the list of objects141 * @throws TorqueException Any exceptions caught during processing will be142 * rethrown wrapped into a TorqueException.143 */144publicstatic List resultSet2Objects(java.sql.ResultSet results)
145 throws TorqueException
146 {
147try148 {
149 QueryDataSet qds = null;
150 List rows = null;
151try152 {
153 qds = new QueryDataSet(results);
154 rows = getSelectResults(qds);
155 }
156finally157 {
158if (qds != null)
159 {
160 qds.close();
161 }
162 }
163164return populateObjects(rows);
165 }
166catch (SQLException e)
167 {
168thrownew TorqueException(e);
169 }
170catch (DataSetException e)
171 {
172thrownew TorqueException(e);
173 }
174 }
175176177178/***179 * Method to do inserts.180 *181 * @param criteria object used to create the INSERT statement.182 * @throws TorqueException Any exceptions caught during processing will be183 * rethrown wrapped into a TorqueException.184 */185publicstatic ObjectKey doInsert(Criteria criteria)
186 throws TorqueException
187 {
188returnBasePortletCategoryPeer189 .doInsert(criteria, (Connection) null);
190 }
191192/***193 * Method to do inserts. This method is to be used during a transaction,194 * otherwise use the doInsert(Criteria) method. It will take care of195 * the connection details internally.196 *197 * @param criteria object used to create the INSERT statement.198 * @param con the connection to use199 * @throws TorqueException Any exceptions caught during processing will be200 * rethrown wrapped into a TorqueException.201 */202publicstatic ObjectKey doInsert(Criteria criteria, Connection con)
203 throws TorqueException
204 {
205206// Set the correct dbName if it has not been overridden207// criteria.getDbName will return the same object if not set to208// another value so == check is okay and faster209if (criteria.getDbName() == Torque.getDefaultDB())
210 {
211 criteria.setDbName(DATABASE_NAME);
212 }
213if (con == null)
214 {
215return BasePeer.doInsert(criteria);
216 }
217else218 {
219return BasePeer.doInsert(criteria, con);
220 }
221 }
222223/***224 * Add all the columns needed to create a new object.225 *226 * @param criteria object containing the columns to add.227 * @throws TorqueException Any exceptions caught during processing will be228 * rethrown wrapped into a TorqueException.229 */230publicstaticvoid addSelectColumns(Criteria criteria)
231 throws TorqueException
232 {
233 criteria.addSelectColumn(ID);
234 criteria.addSelectColumn(NAME);
235 criteria.addSelectColumn(GROUPE);
236 criteria.addSelectColumn(OWNER);
237 }
238239/***240 * Create a new object of type cls from a resultset row starting241 * from a specified offset. This is done so that you can select242 * other rows than just those needed for this object. You may243 * for example want to create two objects from the same row.244 *245 * @throws TorqueException Any exceptions caught during processing will be246 * rethrown wrapped into a TorqueException.247 */248publicstaticPortletCategory row2Object(Record row,
249int offset,
250 Class cls)
251 throws TorqueException
252 {
253try254 {
255PortletCategory obj = (PortletCategory) cls.newInstance();
256 PortletCategoryPeer.populateObject(row, offset, obj);
257 obj.setModified(false);
258 obj.setNew(false);
259260return obj;
261 }
262catch (InstantiationException e)
263 {
264thrownew TorqueException(e);
265 }
266catch (IllegalAccessException e)
267 {
268thrownew TorqueException(e);
269 }
270 }
271272/***273 * Populates an object from a resultset row starting274 * from a specified offset. This is done so that you can select275 * other rows than just those needed for this object. You may276 * for example want to create two objects from the same row.277 *278 * @throws TorqueException Any exceptions caught during processing will be279 * rethrown wrapped into a TorqueException.280 */281publicstaticvoid populateObject(Record row,
282int offset,
283PortletCategory obj)
284 throws TorqueException
285 {
286try287 {
288 obj.setId(row.getValue(offset + 0).asLong());
289 obj.setName(row.getValue(offset + 1).asString());
290 obj.setGroup(row.getValue(offset + 2).asString());
291 obj.setOwner(row.getValue(offset + 3).asLong());
292 }
293catch (DataSetException e)
294 {
295thrownew TorqueException(e);
296 }
297 }
298299/***300 * Method to do selects.301 *302 * @param criteria object used to create the SELECT statement.303 * @return List of selected Objects304 * @throws TorqueException Any exceptions caught during processing will be305 * rethrown wrapped into a TorqueException.306 */307publicstatic List doSelect(Criteria criteria) throws TorqueException
308 {
309return populateObjects(doSelectVillageRecords(criteria));
310 }
311312/***313 * Method to do selects within a transaction.314 *315 * @param criteria object used to create the SELECT statement.316 * @param con the connection to use317 * @return List of selected Objects318 * @throws TorqueException Any exceptions caught during processing will be319 * rethrown wrapped into a TorqueException.320 */321publicstatic List doSelect(Criteria criteria, Connection con)
322 throws TorqueException
323 {
324return populateObjects(doSelectVillageRecords(criteria, con));
325 }
326327/***328 * Grabs the raw Village records to be formed into objects.329 * This method handles connections internally. The Record objects330 * returned by this method should be considered readonly. Do not331 * alter the data and call save(), your results may vary, but are332 * certainly likely to result in hard to track MT bugs.333 *334 * @throws TorqueException Any exceptions caught during processing will be335 * rethrown wrapped into a TorqueException.336 */337publicstatic List doSelectVillageRecords(Criteria criteria)
338 throws TorqueException
339 {
340returnBasePortletCategoryPeer341 .doSelectVillageRecords(criteria, (Connection) null);
342 }
343344/***345 * Grabs the raw Village records to be formed into objects.346 * This method should be used for transactions347 *348 * @param con the connection to use349 * @throws TorqueException Any exceptions caught during processing will be350 * rethrown wrapped into a TorqueException.351 */352publicstatic List doSelectVillageRecords(Criteria criteria, Connection con)
353 throws TorqueException
354 {
355if (criteria.getSelectColumns().size() == 0)
356 {
357 addSelectColumns(criteria);
358 }
359360361// Set the correct dbName if it has not been overridden362// criteria.getDbName will return the same object if not set to363// another value so == check is okay and faster364if (criteria.getDbName() == Torque.getDefaultDB())
365 {
366 criteria.setDbName(DATABASE_NAME);
367 }
368// BasePeer returns a List of Value (Village) arrays. The array369// order follows the order columns were placed in the Select clause.370if (con == null)
371 {
372return BasePeer.doSelect(criteria);
373 }
374else375 {
376return BasePeer.doSelect(criteria, con);
377 }
378 }
379380/***381 * The returned List will contain objects of the default type or382 * objects that inherit from the default.383 *384 * @throws TorqueException Any exceptions caught during processing will be385 * rethrown wrapped into a TorqueException.386 */387publicstatic List populateObjects(List records)
388 throws TorqueException
389 {
390 List results = new ArrayList(records.size());
391392// populate the object(s)393for (int i = 0; i < records.size(); i++)
394 {
395 Record row = (Record) records.get(i);
396 results.add(PortletCategoryPeer.row2Object(row, 1,
397 PortletCategoryPeer.getOMClass()));
398 }
399return results;
400 }
401402403/***404 * The class that the Peer will make instances of.405 * If the BO is abstract then you must implement this method406 * in the BO.407 *408 * @throws TorqueException Any exceptions caught during processing will be409 * rethrown wrapped into a TorqueException.410 */411publicstatic Class getOMClass()
412 throws TorqueException
413 {
414return CLASS_DEFAULT;
415 }
416417/***418 * Method to do updates.419 *420 * @param criteria object containing data that is used to create the UPDATE421 * statement.422 * @throws TorqueException Any exceptions caught during processing will be423 * rethrown wrapped into a TorqueException.424 */425publicstaticvoid doUpdate(Criteria criteria) throws TorqueException
426 {
427BasePortletCategoryPeer428 .doUpdate(criteria, (Connection) null);
429 }
430431/***432 * Method to do updates. This method is to be used during a transaction,433 * otherwise use the doUpdate(Criteria) method. It will take care of434 * the connection details internally.435 *436 * @param criteria object containing data that is used to create the UPDATE437 * statement.438 * @param con the connection to use439 * @throws TorqueException Any exceptions caught during processing will be440 * rethrown wrapped into a TorqueException.441 */442publicstaticvoid doUpdate(Criteria criteria, Connection con)
443 throws TorqueException
444 {
445 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
446 selectCriteria.put(ID, criteria.remove(ID));
447448// Set the correct dbName if it has not been overridden449// criteria.getDbName will return the same object if not set to450// another value so == check is okay and faster451if (criteria.getDbName() == Torque.getDefaultDB())
452 {
453 criteria.setDbName(DATABASE_NAME);
454 }
455if (con == null)
456 {
457 BasePeer.doUpdate(selectCriteria, criteria);
458 }
459else460 {
461 BasePeer.doUpdate(selectCriteria, criteria, con);
462 }
463 }
464465/***466 * Method to do deletes.467 *468 * @param criteria object containing data that is used DELETE from database.469 * @throws TorqueException Any exceptions caught during processing will be470 * rethrown wrapped into a TorqueException.471 */472publicstaticvoid doDelete(Criteria criteria) throws TorqueException
473 {
474BasePortletCategoryPeer475 .doDelete(criteria, (Connection) null);
476 }
477478/***479 * Method to do deletes. This method is to be used during a transaction,480 * otherwise use the doDelete(Criteria) method. It will take care of481 * the connection details internally.482 *483 * @param criteria object containing data that is used DELETE from database.484 * @param con the connection to use485 * @throws TorqueException Any exceptions caught during processing will be486 * rethrown wrapped into a TorqueException.487 */488publicstaticvoid doDelete(Criteria criteria, Connection con)
489 throws TorqueException
490 {
491492// Set the correct dbName if it has not been overridden493// criteria.getDbName will return the same object if not set to494// another value so == check is okay and faster495if (criteria.getDbName() == Torque.getDefaultDB())
496 {
497 criteria.setDbName(DATABASE_NAME);
498 }
499if (con == null)
500 {
501 BasePeer.doDelete(criteria);
502 }
503else504 {
505 BasePeer.doDelete(criteria, con);
506 }
507 }
508509/***510 * Method to do selects511 *512 * @throws TorqueException Any exceptions caught during processing will be513 * rethrown wrapped into a TorqueException.514 */515publicstatic List doSelect(PortletCategory obj) throws TorqueException
516 {
517return doSelect(buildCriteria(obj));
518 }
519520/***521 * Method to do inserts522 *523 * @throws TorqueException Any exceptions caught during processing will be524 * rethrown wrapped into a TorqueException.525 */526publicstaticvoid doInsert(PortletCategory obj) throws TorqueException
527 {
528 obj.setPrimaryKey(doInsert(buildCriteria(obj)));
529 obj.setNew(false);
530 obj.setModified(false);
531 }
532533/***534 * @param obj the data object to update in the database.535 * @throws TorqueException Any exceptions caught during processing will be536 * rethrown wrapped into a TorqueException.537 */538publicstaticvoid doUpdate(PortletCategory obj) throws TorqueException
539 {
540 doUpdate(buildCriteria(obj));
541 obj.setModified(false);
542 }
543544/***545 * @param obj the data object to delete in the database.546 * @throws TorqueException Any exceptions caught during processing will be547 * rethrown wrapped into a TorqueException.548 */549publicstaticvoid doDelete(PortletCategory obj) throws TorqueException
550 {
551 doDelete(buildCriteria(obj));
552 }
553554/***555 * Method to do inserts. This method is to be used during a transaction,556 * otherwise use the doInsert(PortletCategory) method. It will take557 * care of the connection details internally.558 *559 * @param obj the data object to insert into the database.560 * @param con the connection to use561 * @throws TorqueException Any exceptions caught during processing will be562 * rethrown wrapped into a TorqueException.563 */564publicstaticvoid doInsert(PortletCategory obj, Connection con)
565 throws TorqueException
566 {
567 obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
568 obj.setNew(false);
569 obj.setModified(false);
570 }
571572/***573 * Method to do update. This method is to be used during a transaction,574 * otherwise use the doUpdate(PortletCategory) method. It will take575 * care of the connection details internally.576 *577 * @param obj the data object to update in the database.578 * @param con the connection to use579 * @throws TorqueException Any exceptions caught during processing will be580 * rethrown wrapped into a TorqueException.581 */582publicstaticvoid doUpdate(PortletCategory obj, Connection con)
583 throws TorqueException
584 {
585 doUpdate(buildCriteria(obj), con);
586 obj.setModified(false);
587 }
588589/***590 * Method to delete. This method is to be used during a transaction,591 * otherwise use the doDelete(PortletCategory) method. It will take592 * care of the connection details internally.593 *594 * @param obj the data object to delete in the database.595 * @param con the connection to use596 * @throws TorqueException Any exceptions caught during processing will be597 * rethrown wrapped into a TorqueException.598 */599publicstaticvoid doDelete(PortletCategory obj, Connection con)
600 throws TorqueException
601 {
602 doDelete(buildCriteria(obj), con);
603 }
604605/***606 * Method to do deletes.607 *608 * @param pk ObjectKey that is used DELETE from database.609 * @throws TorqueException Any exceptions caught during processing will be610 * rethrown wrapped into a TorqueException.611 */612publicstaticvoid doDelete(ObjectKey pk) throws TorqueException
613 {
614BasePortletCategoryPeer615 .doDelete(pk, (Connection) null);
616 }
617618/***619 * Method to delete. This method is to be used during a transaction,620 * otherwise use the doDelete(ObjectKey) method. It will take621 * care of the connection details internally.622 *623 * @param pk the primary key for the object to delete in the database.624 * @param con the connection to use625 * @throws TorqueException Any exceptions caught during processing will be626 * rethrown wrapped into a TorqueException.627 */628publicstaticvoid doDelete(ObjectKey pk, Connection con)
629 throws TorqueException
630 {
631 doDelete(buildCriteria(pk), con);
632 }
633634/*** Build a Criteria object from an ObjectKey */635publicstatic Criteria buildCriteria( ObjectKey pk )
636 {
637 Criteria criteria = new Criteria();
638 criteria.add(ID, pk);
639return criteria;
640 }
641642/*** Build a Criteria object from the data object for this peer */643publicstatic Criteria buildCriteria( PortletCategory obj )
644 {
645 Criteria criteria = new Criteria(DATABASE_NAME);
646if (!obj.isNew())
647 criteria.add(ID, obj.getId());
648 criteria.add(NAME, obj.getName());
649 criteria.add(GROUPE, obj.getGroup());
650 criteria.add(OWNER, obj.getOwner());
651return criteria;
652 }
653654655/***656 * Retrieve a single object by pk657 *658 * @param pk the primary key659 * @throws TorqueException Any exceptions caught during processing will be660 * rethrown wrapped into a TorqueException.661 * @throws NoRowsException Primary key was not found in database.662 * @throws TooManyRowsException Primary key was not found in database.663 */664publicstaticPortletCategory retrieveByPK(long pk)
665 throws TorqueException, NoRowsException, TooManyRowsException
666 {
667return retrieveByPK(SimpleKey.keyFor(pk));
668 }
669670/***671 * Retrieve a single object by pk672 *673 * @param pk the primary key674 * @throws TorqueException Any exceptions caught during processing will be675 * rethrown wrapped into a TorqueException.676 * @throws NoRowsException Primary key was not found in database.677 * @throws TooManyRowsException Primary key was not found in database.678 */679publicstaticPortletCategory retrieveByPK(ObjectKey pk)
680 throws TorqueException, NoRowsException, TooManyRowsException
681 {
682 Connection db = null;
683PortletCategory retVal = null;
684try685 {
686 db = Torque.getConnection(DATABASE_NAME);
687 retVal = retrieveByPK(pk, db);
688 }
689finally690 {
691 Torque.closeConnection(db);
692 }
693return(retVal);
694 }
695696/***697 * Retrieve a single object by pk698 *699 * @param pk the primary key700 * @param con the connection to use701 * @throws TorqueException Any exceptions caught during processing will be702 * rethrown wrapped into a TorqueException.703 * @throws NoRowsException Primary key was not found in database.704 * @throws TooManyRowsException Primary key was not found in database.705 */706publicstaticPortletCategory retrieveByPK(ObjectKey pk, Connection con)
707 throws TorqueException, NoRowsException, TooManyRowsException
708 {
709 Criteria criteria = buildCriteria(pk);
710 List v = doSelect(criteria, con);
711if (v.size() == 0)
712 {
713thrownew NoRowsException("Failed to select a row.");
714 }
715elseif (v.size() > 1)
716 {
717thrownew TooManyRowsException("Failed to select only one row.");
718 }
719else720 {
721return (PortletCategory)v.get(0);
722 }
723 }
724725/***726 * Retrieve a multiple objects by pk727 *728 * @param pks List of primary keys729 * @throws TorqueException Any exceptions caught during processing will be730 * rethrown wrapped into a TorqueException.731 */732publicstatic List retrieveByPKs(List pks)
733 throws TorqueException
734 {
735 Connection db = null;
736 List retVal = null;
737try738 {
739 db = Torque.getConnection(DATABASE_NAME);
740 retVal = retrieveByPKs(pks, db);
741 }
742finally743 {
744 Torque.closeConnection(db);
745 }
746return(retVal);
747 }
748749/***750 * Retrieve a multiple objects by pk751 *752 * @param pks List of primary keys753 * @param dbcon the connection to use754 * @throws TorqueException Any exceptions caught during processing will be755 * rethrown wrapped into a TorqueException.756 */757publicstatic List retrieveByPKs( List pks, Connection dbcon )
758 throws TorqueException
759 {
760 List objs = null;
761if (pks == null || pks.size() == 0)
762 {
763 objs = new LinkedList();
764 }
765else766 {
767 Criteria criteria = new Criteria();
768 criteria.addIn( ID, pks );
769 objs = doSelect(criteria, dbcon);
770 }
771return objs;
772 }
773774775776777778779780781782783/***784 * selects a collection of PortletCategory objects pre-filled with their785 * PortletDbEntry objects.786 *787 * This method is protected by default in order to keep the public788 * api reasonable. You can provide public methods for those you789 * actually need in PortletCategoryPeer.790 *791 * @throws TorqueException Any exceptions caught during processing will be792 * rethrown wrapped into a TorqueException.793 */794protectedstatic List doSelectJoinPortletDbEntry(Criteria c)
795 throws TorqueException
796 {
797// Set the correct dbName if it has not been overridden798// c.getDbName will return the same object if not set to799// another value so == check is okay and faster800if (c.getDbName() == Torque.getDefaultDB())
801 {
802 c.setDbName(DATABASE_NAME);
803 }
804805 PortletCategoryPeer.addSelectColumns(c);
806int offset = numColumns + 1;
807 PortletDbEntryPeer.addSelectColumns(c);
808809810 c.addJoin(PortletCategoryPeer.OWNER,
811 PortletDbEntryPeer.ID);
812813814815 List rows = BasePeer.doSelect(c);
816 List results = new ArrayList();
817818for (int i = 0; i < rows.size(); i++)
819 {
820 Record row = (Record) rows.get(i);
821822 Class omClass = PortletCategoryPeer.getOMClass();
823PortletCategory obj1 = (PortletCategory) PortletCategoryPeer
824 .row2Object(row, 1, omClass);
825 omClass = PortletDbEntryPeer.getOMClass();
826PortletDbEntry obj2 = (PortletDbEntry)PortletDbEntryPeer
827 .row2Object(row, offset, omClass);
828829boolean newObject = true;
830for (int j = 0; j < results.size(); j++)
831 {
832PortletCategory temp_obj1 = (PortletCategory)results.get(j);
833PortletDbEntry temp_obj2 = (PortletDbEntry)temp_obj1.getPortletDbEntry();
834if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
835 {
836 newObject = false;
837 temp_obj2.addPortletCategory(obj1);
838break;
839 }
840 }
841if (newObject)
842 {
843 obj2.initPortletCategorys();
844 obj2.addPortletCategory(obj1);
845 }
846 results.add(obj1);
847 }
848return results;
849 }
850851852853854/***855 * Returns the TableMap related to this peer. This method is not856 * needed for general use but a specific application could have a need.857 *858 * @throws TorqueException Any exceptions caught during processing will be859 * rethrown wrapped into a TorqueException.860 */861protectedstatic TableMap getTableMap()
862 throws TorqueException
863 {
864return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
865 }
866 }