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.*;
3233343536/***37 * This class was autogenerated by Torque on:38 *39 * [Thu Apr 22 23:12:36 EDT 2004]40 *41 */42publicabstractclassBasePortletMediatypePeer43extends BasePeer
44 {
4546/*** the default database name for this class */47publicstaticfinal String DATABASE_NAME = "default";
4849/*** the table name for this class */50publicstaticfinal String TABLE_NAME = "PORTLET_MEDIATYPE";
5152/***53 * @return the map builder for this peer54 * @throws TorqueException Any exceptions caught during processing will be55 * rethrown wrapped into a TorqueException.56 */57publicstatic MapBuilder getMapBuilder()
58 throws TorqueException
59 {
60return getMapBuilder(PortletMediatypeMapBuilder.CLASS_NAME);
61 }
6263/*** the column name for the ID field */64publicstaticfinal String ID;
65/*** the column name for the MEDIA_ID field */66publicstaticfinal String MEDIA_ID;
6768static69 {
70 ID = "PORTLET_MEDIATYPE.ID";
71 MEDIA_ID = "PORTLET_MEDIATYPE.MEDIA_ID";
72if (Torque.isInit())
73 {
74try75 {
76 getMapBuilder();
77 }
78catch (Exception e)
79 {
80 log.error("Could not initialize Peer", e);
81 }
82 }
83else84 {
85 Torque.registerMapBuilder(PortletMediatypeMapBuilder.CLASS_NAME);
86 }
87 }
8889/*** number of columns for this peer */90publicstaticfinalint numColumns = 2;
9192/*** A class that can be returned by this peer. */93protectedstaticfinal String CLASSNAME_DEFAULT =
94"org.apache.jetspeed.om.dbregistry.PortletMediatype";
9596/*** A class that can be returned by this peer. */97protectedstaticfinal Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
9899/***100 * Class object initialization method.101 *102 * @param className name of the class to initialize103 * @return the initialized class104 */105privatestatic Class initClass(String className)
106 {
107 Class c = null;
108try109 {
110 c = Class.forName(className);
111 }
112catch (Throwable t)
113 {
114 log.error("A FATAL ERROR has occurred which should not "115 + "have happened under any circumstance. Please notify "116 + "the Torque developers <turbine-torque-dev@jakarta.apache.org> "117 + "and give as many details as possible (including the error "118 + "stack trace).", t);
119120// Error objects should always be propogated.121if (t instanceof Error)
122 {
123throw (Error) t.fillInStackTrace();
124 }
125 }
126return c;
127 }
128129/***130 * Get the list of objects for a ResultSet. Please not that your131 * resultset MUST return columns in the right order. You can use132 * getFieldNames() in BaseObject to get the correct sequence.133 *134 * @param results the ResultSet135 * @return the list of objects136 * @throws TorqueException Any exceptions caught during processing will be137 * rethrown wrapped into a TorqueException.138 */139publicstatic List resultSet2Objects(java.sql.ResultSet results)
140 throws TorqueException
141 {
142try143 {
144 QueryDataSet qds = null;
145 List rows = null;
146try147 {
148 qds = new QueryDataSet(results);
149 rows = getSelectResults(qds);
150 }
151finally152 {
153if (qds != null)
154 {
155 qds.close();
156 }
157 }
158159return populateObjects(rows);
160 }
161catch (SQLException e)
162 {
163thrownew TorqueException(e);
164 }
165catch (DataSetException e)
166 {
167thrownew TorqueException(e);
168 }
169 }
170171172173/***174 * Method to do inserts.175 *176 * @param criteria object used to create the INSERT statement.177 * @throws TorqueException Any exceptions caught during processing will be178 * rethrown wrapped into a TorqueException.179 */180publicstatic ObjectKey doInsert(Criteria criteria)
181 throws TorqueException
182 {
183returnBasePortletMediatypePeer184 .doInsert(criteria, (Connection) null);
185 }
186187/***188 * Method to do inserts. This method is to be used during a transaction,189 * otherwise use the doInsert(Criteria) method. It will take care of190 * the connection details internally.191 *192 * @param criteria object used to create the INSERT statement.193 * @param con the connection to use194 * @throws TorqueException Any exceptions caught during processing will be195 * rethrown wrapped into a TorqueException.196 */197publicstatic ObjectKey doInsert(Criteria criteria, Connection con)
198 throws TorqueException
199 {
200201// Set the correct dbName if it has not been overridden202// criteria.getDbName will return the same object if not set to203// another value so == check is okay and faster204if (criteria.getDbName() == Torque.getDefaultDB())
205 {
206 criteria.setDbName(DATABASE_NAME);
207 }
208if (con == null)
209 {
210return BasePeer.doInsert(criteria);
211 }
212else213 {
214return BasePeer.doInsert(criteria, con);
215 }
216 }
217218/***219 * Add all the columns needed to create a new object.220 *221 * @param criteria object containing the columns to add.222 * @throws TorqueException Any exceptions caught during processing will be223 * rethrown wrapped into a TorqueException.224 */225publicstaticvoid addSelectColumns(Criteria criteria)
226 throws TorqueException
227 {
228 criteria.addSelectColumn(ID);
229 criteria.addSelectColumn(MEDIA_ID);
230 }
231232/***233 * Create a new object of type cls from a resultset row starting234 * from a specified offset. This is done so that you can select235 * other rows than just those needed for this object. You may236 * for example want to create two objects from the same row.237 *238 * @throws TorqueException Any exceptions caught during processing will be239 * rethrown wrapped into a TorqueException.240 */241publicstaticPortletMediatype row2Object(Record row,
242int offset,
243 Class cls)
244 throws TorqueException
245 {
246try247 {
248PortletMediatype obj = (PortletMediatype) cls.newInstance();
249 PortletMediatypePeer.populateObject(row, offset, obj);
250 obj.setModified(false);
251 obj.setNew(false);
252253return obj;
254 }
255catch (InstantiationException e)
256 {
257thrownew TorqueException(e);
258 }
259catch (IllegalAccessException e)
260 {
261thrownew TorqueException(e);
262 }
263 }
264265/***266 * Populates an object from a resultset row starting267 * from a specified offset. This is done so that you can select268 * other rows than just those needed for this object. You may269 * for example want to create two objects from the same row.270 *271 * @throws TorqueException Any exceptions caught during processing will be272 * rethrown wrapped into a TorqueException.273 */274publicstaticvoid populateObject(Record row,
275int offset,
276PortletMediatype obj)
277 throws TorqueException
278 {
279try280 {
281 obj.setId(row.getValue(offset + 0).asLong());
282 obj.setMediaId(row.getValue(offset + 1).asLong());
283 }
284catch (DataSetException e)
285 {
286thrownew TorqueException(e);
287 }
288 }
289290/***291 * Method to do selects.292 *293 * @param criteria object used to create the SELECT statement.294 * @return List of selected Objects295 * @throws TorqueException Any exceptions caught during processing will be296 * rethrown wrapped into a TorqueException.297 */298publicstatic List doSelect(Criteria criteria) throws TorqueException
299 {
300return populateObjects(doSelectVillageRecords(criteria));
301 }
302303/***304 * Method to do selects within a transaction.305 *306 * @param criteria object used to create the SELECT statement.307 * @param con the connection to use308 * @return List of selected Objects309 * @throws TorqueException Any exceptions caught during processing will be310 * rethrown wrapped into a TorqueException.311 */312publicstatic List doSelect(Criteria criteria, Connection con)
313 throws TorqueException
314 {
315return populateObjects(doSelectVillageRecords(criteria, con));
316 }
317318/***319 * Grabs the raw Village records to be formed into objects.320 * This method handles connections internally. The Record objects321 * returned by this method should be considered readonly. Do not322 * alter the data and call save(), your results may vary, but are323 * certainly likely to result in hard to track MT bugs.324 *325 * @throws TorqueException Any exceptions caught during processing will be326 * rethrown wrapped into a TorqueException.327 */328publicstatic List doSelectVillageRecords(Criteria criteria)
329 throws TorqueException
330 {
331returnBasePortletMediatypePeer332 .doSelectVillageRecords(criteria, (Connection) null);
333 }
334335/***336 * Grabs the raw Village records to be formed into objects.337 * This method should be used for transactions338 *339 * @param con the connection to use340 * @throws TorqueException Any exceptions caught during processing will be341 * rethrown wrapped into a TorqueException.342 */343publicstatic List doSelectVillageRecords(Criteria criteria, Connection con)
344 throws TorqueException
345 {
346if (criteria.getSelectColumns().size() == 0)
347 {
348 addSelectColumns(criteria);
349 }
350351352// Set the correct dbName if it has not been overridden353// criteria.getDbName will return the same object if not set to354// another value so == check is okay and faster355if (criteria.getDbName() == Torque.getDefaultDB())
356 {
357 criteria.setDbName(DATABASE_NAME);
358 }
359// BasePeer returns a List of Value (Village) arrays. The array360// order follows the order columns were placed in the Select clause.361if (con == null)
362 {
363return BasePeer.doSelect(criteria);
364 }
365else366 {
367return BasePeer.doSelect(criteria, con);
368 }
369 }
370371/***372 * The returned List will contain objects of the default type or373 * objects that inherit from the default.374 *375 * @throws TorqueException Any exceptions caught during processing will be376 * rethrown wrapped into a TorqueException.377 */378publicstatic List populateObjects(List records)
379 throws TorqueException
380 {
381 List results = new ArrayList(records.size());
382383// populate the object(s)384for (int i = 0; i < records.size(); i++)
385 {
386 Record row = (Record) records.get(i);
387 results.add(PortletMediatypePeer.row2Object(row, 1,
388 PortletMediatypePeer.getOMClass()));
389 }
390return results;
391 }
392393394/***395 * The class that the Peer will make instances of.396 * If the BO is abstract then you must implement this method397 * in the BO.398 *399 * @throws TorqueException Any exceptions caught during processing will be400 * rethrown wrapped into a TorqueException.401 */402publicstatic Class getOMClass()
403 throws TorqueException
404 {
405return CLASS_DEFAULT;
406 }
407408/***409 * Method to do updates.410 *411 * @param criteria object containing data that is used to create the UPDATE412 * statement.413 * @throws TorqueException Any exceptions caught during processing will be414 * rethrown wrapped into a TorqueException.415 */416publicstaticvoid doUpdate(Criteria criteria) throws TorqueException
417 {
418BasePortletMediatypePeer419 .doUpdate(criteria, (Connection) null);
420 }
421422/***423 * Method to do updates. This method is to be used during a transaction,424 * otherwise use the doUpdate(Criteria) method. It will take care of425 * the connection details internally.426 *427 * @param criteria object containing data that is used to create the UPDATE428 * statement.429 * @param con the connection to use430 * @throws TorqueException Any exceptions caught during processing will be431 * rethrown wrapped into a TorqueException.432 */433publicstaticvoid doUpdate(Criteria criteria, Connection con)
434 throws TorqueException
435 {
436 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
437438// Set the correct dbName if it has not been overridden439// criteria.getDbName will return the same object if not set to440// another value so == check is okay and faster441if (criteria.getDbName() == Torque.getDefaultDB())
442 {
443 criteria.setDbName(DATABASE_NAME);
444 }
445if (con == null)
446 {
447 BasePeer.doUpdate(selectCriteria, criteria);
448 }
449else450 {
451 BasePeer.doUpdate(selectCriteria, criteria, con);
452 }
453 }
454455/***456 * Method to do deletes.457 *458 * @param criteria object containing data that is used DELETE from database.459 * @throws TorqueException Any exceptions caught during processing will be460 * rethrown wrapped into a TorqueException.461 */462publicstaticvoid doDelete(Criteria criteria) throws TorqueException
463 {
464BasePortletMediatypePeer465 .doDelete(criteria, (Connection) null);
466 }
467468/***469 * Method to do deletes. This method is to be used during a transaction,470 * otherwise use the doDelete(Criteria) method. It will take care of471 * the connection details internally.472 *473 * @param criteria object containing data that is used DELETE from database.474 * @param con the connection to use475 * @throws TorqueException Any exceptions caught during processing will be476 * rethrown wrapped into a TorqueException.477 */478publicstaticvoid doDelete(Criteria criteria, Connection con)
479 throws TorqueException
480 {
481482// Set the correct dbName if it has not been overridden483// criteria.getDbName will return the same object if not set to484// another value so == check is okay and faster485if (criteria.getDbName() == Torque.getDefaultDB())
486 {
487 criteria.setDbName(DATABASE_NAME);
488 }
489if (con == null)
490 {
491 BasePeer.doDelete(criteria);
492 }
493else494 {
495 BasePeer.doDelete(criteria, con);
496 }
497 }
498499/***500 * Method to do selects501 *502 * @throws TorqueException Any exceptions caught during processing will be503 * rethrown wrapped into a TorqueException.504 */505publicstatic List doSelect(PortletMediatype obj) throws TorqueException
506 {
507return doSelect(buildCriteria(obj));
508 }
509510/***511 * Method to do inserts512 *513 * @throws TorqueException Any exceptions caught during processing will be514 * rethrown wrapped into a TorqueException.515 */516publicstaticvoid doInsert(PortletMediatype obj) throws TorqueException
517 {
518 doInsert(buildCriteria(obj));
519 obj.setNew(false);
520 obj.setModified(false);
521 }
522523/***524 * @param obj the data object to update in the database.525 * @throws TorqueException Any exceptions caught during processing will be526 * rethrown wrapped into a TorqueException.527 */528publicstaticvoid doUpdate(PortletMediatype obj) throws TorqueException
529 {
530 doUpdate(buildCriteria(obj));
531 obj.setModified(false);
532 }
533534/***535 * @param obj the data object to delete in the database.536 * @throws TorqueException Any exceptions caught during processing will be537 * rethrown wrapped into a TorqueException.538 */539publicstaticvoid doDelete(PortletMediatype obj) throws TorqueException
540 {
541 doDelete(buildCriteria(obj));
542 }
543544/***545 * Method to do inserts. This method is to be used during a transaction,546 * otherwise use the doInsert(PortletMediatype) method. It will take547 * care of the connection details internally.548 *549 * @param obj the data object to insert into the database.550 * @param con the connection to use551 * @throws TorqueException Any exceptions caught during processing will be552 * rethrown wrapped into a TorqueException.553 */554publicstaticvoid doInsert(PortletMediatype obj, Connection con)
555 throws TorqueException
556 {
557 doInsert(buildCriteria(obj), con);
558 obj.setNew(false);
559 obj.setModified(false);
560 }
561562/***563 * Method to do update. This method is to be used during a transaction,564 * otherwise use the doUpdate(PortletMediatype) method. It will take565 * care of the connection details internally.566 *567 * @param obj the data object to update in the database.568 * @param con the connection to use569 * @throws TorqueException Any exceptions caught during processing will be570 * rethrown wrapped into a TorqueException.571 */572publicstaticvoid doUpdate(PortletMediatype obj, Connection con)
573 throws TorqueException
574 {
575 doUpdate(buildCriteria(obj), con);
576 obj.setModified(false);
577 }
578579/***580 * Method to delete. This method is to be used during a transaction,581 * otherwise use the doDelete(PortletMediatype) method. It will take582 * care of the connection details internally.583 *584 * @param obj the data object to delete in the database.585 * @param con the connection to use586 * @throws TorqueException Any exceptions caught during processing will be587 * rethrown wrapped into a TorqueException.588 */589publicstaticvoid doDelete(PortletMediatype obj, Connection con)
590 throws TorqueException
591 {
592 doDelete(buildCriteria(obj), con);
593 }
594595/***596 * Method to do deletes.597 *598 * @param pk ObjectKey that is used DELETE from database.599 * @throws TorqueException Any exceptions caught during processing will be600 * rethrown wrapped into a TorqueException.601 */602publicstaticvoid doDelete(ObjectKey pk) throws TorqueException
603 {
604BasePortletMediatypePeer605 .doDelete(pk, (Connection) null);
606 }
607608/***609 * Method to delete. This method is to be used during a transaction,610 * otherwise use the doDelete(ObjectKey) method. It will take611 * care of the connection details internally.612 *613 * @param pk the primary key for the object to delete in the database.614 * @param con the connection to use615 * @throws TorqueException Any exceptions caught during processing will be616 * rethrown wrapped into a TorqueException.617 */618publicstaticvoid doDelete(ObjectKey pk, Connection con)
619 throws TorqueException
620 {
621 doDelete(buildCriteria(pk), con);
622 }
623624/*** Build a Criteria object from an ObjectKey */625publicstatic Criteria buildCriteria( ObjectKey pk )
626 {
627 Criteria criteria = new Criteria();
628 SimpleKey[] keys = (SimpleKey[])pk.getValue();
629return criteria;
630 }
631632/*** Build a Criteria object from the data object for this peer */633publicstatic Criteria buildCriteria( PortletMediatype obj )
634 {
635 Criteria criteria = new Criteria(DATABASE_NAME);
636 criteria.add(ID, obj.getId());
637 criteria.add(MEDIA_ID, obj.getMediaId());
638return criteria;
639 }
640641642643644645646647648649650/***651 * selects a collection of PortletMediatype objects pre-filled with their652 * PortletDbEntry objects.653 *654 * This method is protected by default in order to keep the public655 * api reasonable. You can provide public methods for those you656 * actually need in PortletMediatypePeer.657 *658 * @throws TorqueException Any exceptions caught during processing will be659 * rethrown wrapped into a TorqueException.660 */661protectedstatic List doSelectJoinPortletDbEntry(Criteria c)
662 throws TorqueException
663 {
664// Set the correct dbName if it has not been overridden665// c.getDbName will return the same object if not set to666// another value so == check is okay and faster667if (c.getDbName() == Torque.getDefaultDB())
668 {
669 c.setDbName(DATABASE_NAME);
670 }
671672 PortletMediatypePeer.addSelectColumns(c);
673int offset = numColumns + 1;
674 PortletDbEntryPeer.addSelectColumns(c);
675676677 c.addJoin(PortletMediatypePeer.ID,
678 PortletDbEntryPeer.ID);
679680681682 List rows = BasePeer.doSelect(c);
683 List results = new ArrayList();
684685for (int i = 0; i < rows.size(); i++)
686 {
687 Record row = (Record) rows.get(i);
688689 Class omClass = PortletMediatypePeer.getOMClass();
690PortletMediatype obj1 = (PortletMediatype) PortletMediatypePeer
691 .row2Object(row, 1, omClass);
692 omClass = PortletDbEntryPeer.getOMClass();
693PortletDbEntry obj2 = (PortletDbEntry)PortletDbEntryPeer
694 .row2Object(row, offset, omClass);
695696boolean newObject = true;
697for (int j = 0; j < results.size(); j++)
698 {
699PortletMediatype temp_obj1 = (PortletMediatype)results.get(j);
700PortletDbEntry temp_obj2 = (PortletDbEntry)temp_obj1.getPortletDbEntry();
701if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
702 {
703 newObject = false;
704 temp_obj2.addPortletMediatype(obj1);
705break;
706 }
707 }
708if (newObject)
709 {
710 obj2.initPortletMediatypes();
711 obj2.addPortletMediatype(obj1);
712 }
713 results.add(obj1);
714 }
715return results;
716 }
717718719720721/***722 * selects a collection of PortletMediatype objects pre-filled with their723 * Mediatype objects.724 *725 * This method is protected by default in order to keep the public726 * api reasonable. You can provide public methods for those you727 * actually need in PortletMediatypePeer.728 *729 * @throws TorqueException Any exceptions caught during processing will be730 * rethrown wrapped into a TorqueException.731 */732protectedstatic List doSelectJoinMediatype(Criteria c)
733 throws TorqueException
734 {
735// Set the correct dbName if it has not been overridden736// c.getDbName will return the same object if not set to737// another value so == check is okay and faster738if (c.getDbName() == Torque.getDefaultDB())
739 {
740 c.setDbName(DATABASE_NAME);
741 }
742743 PortletMediatypePeer.addSelectColumns(c);
744int offset = numColumns + 1;
745 MediatypePeer.addSelectColumns(c);
746747748 c.addJoin(PortletMediatypePeer.MEDIA_ID,
749 MediatypePeer.ID);
750751752753 List rows = BasePeer.doSelect(c);
754 List results = new ArrayList();
755756for (int i = 0; i < rows.size(); i++)
757 {
758 Record row = (Record) rows.get(i);
759760 Class omClass = PortletMediatypePeer.getOMClass();
761PortletMediatype obj1 = (PortletMediatype) PortletMediatypePeer
762 .row2Object(row, 1, omClass);
763 omClass = MediatypePeer.getOMClass();
764Mediatype obj2 = (Mediatype)MediatypePeer
765 .row2Object(row, offset, omClass);
766767boolean newObject = true;
768for (int j = 0; j < results.size(); j++)
769 {
770PortletMediatype temp_obj1 = (PortletMediatype)results.get(j);
771Mediatype temp_obj2 = (Mediatype)temp_obj1.getMediatype();
772if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
773 {
774 newObject = false;
775 temp_obj2.addPortletMediatype(obj1);
776break;
777 }
778 }
779if (newObject)
780 {
781 obj2.initPortletMediatypes();
782 obj2.addPortletMediatype(obj1);
783 }
784 results.add(obj1);
785 }
786return results;
787 }
788789790791792/***793 * Returns the TableMap related to this peer. This method is not794 * needed for general use but a specific application could have a need.795 *796 * @throws TorqueException Any exceptions caught during processing will be797 * rethrown wrapped into a TorqueException.798 */799protectedstatic TableMap getTableMap()
800 throws TorqueException
801 {
802return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
803 }
804 }