1packageorg.apache.jetspeed.om.dbpsml;
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.dbpsml.map.*;
323334/***35 * This class was autogenerated by Torque on:36 *37 * [Thu Apr 22 23:12:36 EDT 2004]38 *39 */40publicabstractclassBaseJetspeedUserProfilePeer41extends 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 = "JETSPEED_USER_PROFILE";
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(JetspeedUserProfileMapBuilder.CLASS_NAME);
59 }
6061/*** the column name for the PSML_ID field */62publicstaticfinal String PSML_ID;
63/*** the column name for the USER_NAME field */64publicstaticfinal String USER_NAME;
65/*** the column name for the MEDIA_TYPE field */66publicstaticfinal String MEDIA_TYPE;
67/*** the column name for the LANGUAGE field */68publicstaticfinal String LANGUAGE;
69/*** the column name for the COUNTRY field */70publicstaticfinal String COUNTRY;
71/*** the column name for the PAGE field */72publicstaticfinal String PAGE;
73/*** the column name for the PROFILE field */74publicstaticfinal String PROFILE;
7576static77 {
78 PSML_ID = "JETSPEED_USER_PROFILE.PSML_ID";
79 USER_NAME = "JETSPEED_USER_PROFILE.USER_NAME";
80 MEDIA_TYPE = "JETSPEED_USER_PROFILE.MEDIA_TYPE";
81 LANGUAGE = "JETSPEED_USER_PROFILE.LANGUAGE";
82 COUNTRY = "JETSPEED_USER_PROFILE.COUNTRY";
83 PAGE = "JETSPEED_USER_PROFILE.PAGE";
84 PROFILE = "JETSPEED_USER_PROFILE.PROFILE";
85if (Torque.isInit())
86 {
87try88 {
89 getMapBuilder();
90 }
91catch (Exception e)
92 {
93 log.error("Could not initialize Peer", e);
94 }
95 }
96else97 {
98 Torque.registerMapBuilder(JetspeedUserProfileMapBuilder.CLASS_NAME);
99 }
100 }
101102/*** number of columns for this peer */103publicstaticfinalint numColumns = 7;
104105/*** A class that can be returned by this peer. */106protectedstaticfinal String CLASSNAME_DEFAULT =
107"org.apache.jetspeed.om.dbpsml.JetspeedUserProfile";
108109/*** A class that can be returned by this peer. */110protectedstaticfinal Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
111112/***113 * Class object initialization method.114 *115 * @param className name of the class to initialize116 * @return the initialized class117 */118privatestatic Class initClass(String className)
119 {
120 Class c = null;
121try122 {
123 c = Class.forName(className);
124 }
125catch (Throwable t)
126 {
127 log.error("A FATAL ERROR has occurred which should not "128 + "have happened under any circumstance. Please notify "129 + "the Torque developers <turbine-torque-dev@jakarta.apache.org> "130 + "and give as many details as possible (including the error "131 + "stack trace).", t);
132133// Error objects should always be propogated.134if (t instanceof Error)
135 {
136throw (Error) t.fillInStackTrace();
137 }
138 }
139return c;
140 }
141142/***143 * Get the list of objects for a ResultSet. Please not that your144 * resultset MUST return columns in the right order. You can use145 * getFieldNames() in BaseObject to get the correct sequence.146 *147 * @param results the ResultSet148 * @return the list of objects149 * @throws TorqueException Any exceptions caught during processing will be150 * rethrown wrapped into a TorqueException.151 */152publicstatic List resultSet2Objects(java.sql.ResultSet results)
153 throws TorqueException
154 {
155try156 {
157 QueryDataSet qds = null;
158 List rows = null;
159try160 {
161 qds = new QueryDataSet(results);
162 rows = getSelectResults(qds);
163 }
164finally165 {
166if (qds != null)
167 {
168 qds.close();
169 }
170 }
171172return populateObjects(rows);
173 }
174catch (SQLException e)
175 {
176thrownew TorqueException(e);
177 }
178catch (DataSetException e)
179 {
180thrownew TorqueException(e);
181 }
182 }
183184185186/***187 * Method to do inserts.188 *189 * @param criteria object used to create the INSERT statement.190 * @throws TorqueException Any exceptions caught during processing will be191 * rethrown wrapped into a TorqueException.192 */193publicstatic ObjectKey doInsert(Criteria criteria)
194 throws TorqueException
195 {
196returnBaseJetspeedUserProfilePeer197 .doInsert(criteria, (Connection) null);
198 }
199200/***201 * Method to do inserts. This method is to be used during a transaction,202 * otherwise use the doInsert(Criteria) method. It will take care of203 * the connection details internally.204 *205 * @param criteria object used to create the INSERT statement.206 * @param con the connection to use207 * @throws TorqueException Any exceptions caught during processing will be208 * rethrown wrapped into a TorqueException.209 */210publicstatic ObjectKey doInsert(Criteria criteria, Connection con)
211 throws TorqueException
212 {
213214// Set the correct dbName if it has not been overridden215// criteria.getDbName will return the same object if not set to216// another value so == check is okay and faster217if (criteria.getDbName() == Torque.getDefaultDB())
218 {
219 criteria.setDbName(DATABASE_NAME);
220 }
221if (con == null)
222 {
223return BasePeer.doInsert(criteria);
224 }
225else226 {
227return BasePeer.doInsert(criteria, con);
228 }
229 }
230231/***232 * Add all the columns needed to create a new object.233 *234 * @param criteria object containing the columns to add.235 * @throws TorqueException Any exceptions caught during processing will be236 * rethrown wrapped into a TorqueException.237 */238publicstaticvoid addSelectColumns(Criteria criteria)
239 throws TorqueException
240 {
241 criteria.addSelectColumn(PSML_ID);
242 criteria.addSelectColumn(USER_NAME);
243 criteria.addSelectColumn(MEDIA_TYPE);
244 criteria.addSelectColumn(LANGUAGE);
245 criteria.addSelectColumn(COUNTRY);
246 criteria.addSelectColumn(PAGE);
247 criteria.addSelectColumn(PROFILE);
248 }
249250/***251 * Create a new object of type cls from a resultset row starting252 * from a specified offset. This is done so that you can select253 * other rows than just those needed for this object. You may254 * for example want to create two objects from the same row.255 *256 * @throws TorqueException Any exceptions caught during processing will be257 * rethrown wrapped into a TorqueException.258 */259publicstaticJetspeedUserProfile row2Object(Record row,
260int offset,
261 Class cls)
262 throws TorqueException
263 {
264try265 {
266JetspeedUserProfile obj = (JetspeedUserProfile) cls.newInstance();
267 JetspeedUserProfilePeer.populateObject(row, offset, obj);
268 obj.setModified(false);
269 obj.setNew(false);
270271return obj;
272 }
273catch (InstantiationException e)
274 {
275thrownew TorqueException(e);
276 }
277catch (IllegalAccessException e)
278 {
279thrownew TorqueException(e);
280 }
281 }
282283/***284 * Populates an object from a resultset row starting285 * from a specified offset. This is done so that you can select286 * other rows than just those needed for this object. You may287 * for example want to create two objects from the same row.288 *289 * @throws TorqueException Any exceptions caught during processing will be290 * rethrown wrapped into a TorqueException.291 */292publicstaticvoid populateObject(Record row,
293int offset,
294JetspeedUserProfile obj)
295 throws TorqueException
296 {
297try298 {
299 obj.setPsmlId(row.getValue(offset + 0).asInt());
300 obj.setUserName(row.getValue(offset + 1).asString());
301 obj.setMediaType(row.getValue(offset + 2).asString());
302 obj.setLanguage(row.getValue(offset + 3).asString());
303 obj.setCountry(row.getValue(offset + 4).asString());
304 obj.setPage(row.getValue(offset + 5).asString());
305 obj.setProfile(row.getValue(offset + 6).asBytes());
306 }
307catch (DataSetException e)
308 {
309thrownew TorqueException(e);
310 }
311 }
312313/***314 * Method to do selects.315 *316 * @param criteria object used to create the SELECT statement.317 * @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) throws TorqueException
322 {
323return populateObjects(doSelectVillageRecords(criteria));
324 }
325326/***327 * Method to do selects within a transaction.328 *329 * @param criteria object used to create the SELECT statement.330 * @param con the connection to use331 * @return List of selected Objects332 * @throws TorqueException Any exceptions caught during processing will be333 * rethrown wrapped into a TorqueException.334 */335publicstatic List doSelect(Criteria criteria, Connection con)
336 throws TorqueException
337 {
338return populateObjects(doSelectVillageRecords(criteria, con));
339 }
340341/***342 * Grabs the raw Village records to be formed into objects.343 * This method handles connections internally. The Record objects344 * returned by this method should be considered readonly. Do not345 * alter the data and call save(), your results may vary, but are346 * certainly likely to result in hard to track MT bugs.347 *348 * @throws TorqueException Any exceptions caught during processing will be349 * rethrown wrapped into a TorqueException.350 */351publicstatic List doSelectVillageRecords(Criteria criteria)
352 throws TorqueException
353 {
354returnBaseJetspeedUserProfilePeer355 .doSelectVillageRecords(criteria, (Connection) null);
356 }
357358/***359 * Grabs the raw Village records to be formed into objects.360 * This method should be used for transactions361 *362 * @param con the connection to use363 * @throws TorqueException Any exceptions caught during processing will be364 * rethrown wrapped into a TorqueException.365 */366publicstatic List doSelectVillageRecords(Criteria criteria, Connection con)
367 throws TorqueException
368 {
369if (criteria.getSelectColumns().size() == 0)
370 {
371 addSelectColumns(criteria);
372 }
373374375// Set the correct dbName if it has not been overridden376// criteria.getDbName will return the same object if not set to377// another value so == check is okay and faster378if (criteria.getDbName() == Torque.getDefaultDB())
379 {
380 criteria.setDbName(DATABASE_NAME);
381 }
382// BasePeer returns a List of Value (Village) arrays. The array383// order follows the order columns were placed in the Select clause.384if (con == null)
385 {
386return BasePeer.doSelect(criteria);
387 }
388else389 {
390return BasePeer.doSelect(criteria, con);
391 }
392 }
393394/***395 * The returned List will contain objects of the default type or396 * objects that inherit from the default.397 *398 * @throws TorqueException Any exceptions caught during processing will be399 * rethrown wrapped into a TorqueException.400 */401publicstatic List populateObjects(List records)
402 throws TorqueException
403 {
404 List results = new ArrayList(records.size());
405406// populate the object(s)407for (int i = 0; i < records.size(); i++)
408 {
409 Record row = (Record) records.get(i);
410 results.add(JetspeedUserProfilePeer.row2Object(row, 1,
411 JetspeedUserProfilePeer.getOMClass()));
412 }
413return results;
414 }
415416417/***418 * The class that the Peer will make instances of.419 * If the BO is abstract then you must implement this method420 * in the BO.421 *422 * @throws TorqueException Any exceptions caught during processing will be423 * rethrown wrapped into a TorqueException.424 */425publicstatic Class getOMClass()
426 throws TorqueException
427 {
428return CLASS_DEFAULT;
429 }
430431/***432 * Method to do updates.433 *434 * @param criteria object containing data that is used to create the UPDATE435 * statement.436 * @throws TorqueException Any exceptions caught during processing will be437 * rethrown wrapped into a TorqueException.438 */439publicstaticvoid doUpdate(Criteria criteria) throws TorqueException
440 {
441BaseJetspeedUserProfilePeer442 .doUpdate(criteria, (Connection) null);
443 }
444445/***446 * Method to do updates. This method is to be used during a transaction,447 * otherwise use the doUpdate(Criteria) method. It will take care of448 * the connection details internally.449 *450 * @param criteria object containing data that is used to create the UPDATE451 * statement.452 * @param con the connection to use453 * @throws TorqueException Any exceptions caught during processing will be454 * rethrown wrapped into a TorqueException.455 */456publicstaticvoid doUpdate(Criteria criteria, Connection con)
457 throws TorqueException
458 {
459 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
460 selectCriteria.put(PSML_ID, criteria.remove(PSML_ID));
461462// Set the correct dbName if it has not been overridden463// criteria.getDbName will return the same object if not set to464// another value so == check is okay and faster465if (criteria.getDbName() == Torque.getDefaultDB())
466 {
467 criteria.setDbName(DATABASE_NAME);
468 }
469if (con == null)
470 {
471 BasePeer.doUpdate(selectCriteria, criteria);
472 }
473else474 {
475 BasePeer.doUpdate(selectCriteria, criteria, con);
476 }
477 }
478479/***480 * Method to do deletes.481 *482 * @param criteria object containing data that is used DELETE from database.483 * @throws TorqueException Any exceptions caught during processing will be484 * rethrown wrapped into a TorqueException.485 */486publicstaticvoid doDelete(Criteria criteria) throws TorqueException
487 {
488BaseJetspeedUserProfilePeer489 .doDelete(criteria, (Connection) null);
490 }
491492/***493 * Method to do deletes. This method is to be used during a transaction,494 * otherwise use the doDelete(Criteria) method. It will take care of495 * the connection details internally.496 *497 * @param criteria object containing data that is used DELETE from database.498 * @param con the connection to use499 * @throws TorqueException Any exceptions caught during processing will be500 * rethrown wrapped into a TorqueException.501 */502publicstaticvoid doDelete(Criteria criteria, Connection con)
503 throws TorqueException
504 {
505506// Set the correct dbName if it has not been overridden507// criteria.getDbName will return the same object if not set to508// another value so == check is okay and faster509if (criteria.getDbName() == Torque.getDefaultDB())
510 {
511 criteria.setDbName(DATABASE_NAME);
512 }
513if (con == null)
514 {
515 BasePeer.doDelete(criteria);
516 }
517else518 {
519 BasePeer.doDelete(criteria, con);
520 }
521 }
522523/***524 * Method to do selects525 *526 * @throws TorqueException Any exceptions caught during processing will be527 * rethrown wrapped into a TorqueException.528 */529publicstatic List doSelect(JetspeedUserProfile obj) throws TorqueException
530 {
531return doSelect(buildCriteria(obj));
532 }
533534/***535 * Method to do inserts536 *537 * @throws TorqueException Any exceptions caught during processing will be538 * rethrown wrapped into a TorqueException.539 */540publicstaticvoid doInsert(JetspeedUserProfile obj) throws TorqueException
541 {
542 obj.setPrimaryKey(doInsert(buildCriteria(obj)));
543 obj.setNew(false);
544 obj.setModified(false);
545 }
546547/***548 * @param obj the data object to update in the database.549 * @throws TorqueException Any exceptions caught during processing will be550 * rethrown wrapped into a TorqueException.551 */552publicstaticvoid doUpdate(JetspeedUserProfile obj) throws TorqueException
553 {
554 doUpdate(buildCriteria(obj));
555 obj.setModified(false);
556 }
557558/***559 * @param obj the data object to delete in the database.560 * @throws TorqueException Any exceptions caught during processing will be561 * rethrown wrapped into a TorqueException.562 */563publicstaticvoid doDelete(JetspeedUserProfile obj) throws TorqueException
564 {
565 doDelete(buildCriteria(obj));
566 }
567568/***569 * Method to do inserts. This method is to be used during a transaction,570 * otherwise use the doInsert(JetspeedUserProfile) method. It will take571 * care of the connection details internally.572 *573 * @param obj the data object to insert into the database.574 * @param con the connection to use575 * @throws TorqueException Any exceptions caught during processing will be576 * rethrown wrapped into a TorqueException.577 */578publicstaticvoid doInsert(JetspeedUserProfile obj, Connection con)
579 throws TorqueException
580 {
581 obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
582 obj.setNew(false);
583 obj.setModified(false);
584 }
585586/***587 * Method to do update. This method is to be used during a transaction,588 * otherwise use the doUpdate(JetspeedUserProfile) method. It will take589 * care of the connection details internally.590 *591 * @param obj the data object to update in the database.592 * @param con the connection to use593 * @throws TorqueException Any exceptions caught during processing will be594 * rethrown wrapped into a TorqueException.595 */596publicstaticvoid doUpdate(JetspeedUserProfile obj, Connection con)
597 throws TorqueException
598 {
599 doUpdate(buildCriteria(obj), con);
600 obj.setModified(false);
601 }
602603/***604 * Method to delete. This method is to be used during a transaction,605 * otherwise use the doDelete(JetspeedUserProfile) method. It will take606 * care of the connection details internally.607 *608 * @param obj the data object to delete in the database.609 * @param con the connection to use610 * @throws TorqueException Any exceptions caught during processing will be611 * rethrown wrapped into a TorqueException.612 */613publicstaticvoid doDelete(JetspeedUserProfile obj, Connection con)
614 throws TorqueException
615 {
616 doDelete(buildCriteria(obj), con);
617 }
618619/***620 * Method to do deletes.621 *622 * @param pk ObjectKey that is used DELETE from database.623 * @throws TorqueException Any exceptions caught during processing will be624 * rethrown wrapped into a TorqueException.625 */626publicstaticvoid doDelete(ObjectKey pk) throws TorqueException
627 {
628BaseJetspeedUserProfilePeer629 .doDelete(pk, (Connection) null);
630 }
631632/***633 * Method to delete. This method is to be used during a transaction,634 * otherwise use the doDelete(ObjectKey) method. It will take635 * care of the connection details internally.636 *637 * @param pk the primary key for the object to delete in the database.638 * @param con the connection to use639 * @throws TorqueException Any exceptions caught during processing will be640 * rethrown wrapped into a TorqueException.641 */642publicstaticvoid doDelete(ObjectKey pk, Connection con)
643 throws TorqueException
644 {
645 doDelete(buildCriteria(pk), con);
646 }
647648/*** Build a Criteria object from an ObjectKey */649publicstatic Criteria buildCriteria( ObjectKey pk )
650 {
651 Criteria criteria = new Criteria();
652 criteria.add(PSML_ID, pk);
653return criteria;
654 }
655656/*** Build a Criteria object from the data object for this peer */657publicstatic Criteria buildCriteria( JetspeedUserProfile obj )
658 {
659 Criteria criteria = new Criteria(DATABASE_NAME);
660if (!obj.isNew())
661 criteria.add(PSML_ID, obj.getPsmlId());
662 criteria.add(USER_NAME, obj.getUserName());
663 criteria.add(MEDIA_TYPE, obj.getMediaType());
664 criteria.add(LANGUAGE, obj.getLanguage());
665 criteria.add(COUNTRY, obj.getCountry());
666 criteria.add(PAGE, obj.getPage());
667 criteria.add(PROFILE, obj.getProfile());
668return criteria;
669 }
670671672/***673 * Retrieve a single object by pk674 *675 * @param pk the primary key676 * @throws TorqueException Any exceptions caught during processing will be677 * rethrown wrapped into a TorqueException.678 * @throws NoRowsException Primary key was not found in database.679 * @throws TooManyRowsException Primary key was not found in database.680 */681publicstaticJetspeedUserProfile retrieveByPK(int pk)
682 throws TorqueException, NoRowsException, TooManyRowsException
683 {
684return retrieveByPK(SimpleKey.keyFor(pk));
685 }
686687/***688 * Retrieve a single object by pk689 *690 * @param pk the primary key691 * @throws TorqueException Any exceptions caught during processing will be692 * rethrown wrapped into a TorqueException.693 * @throws NoRowsException Primary key was not found in database.694 * @throws TooManyRowsException Primary key was not found in database.695 */696publicstaticJetspeedUserProfile retrieveByPK(ObjectKey pk)
697 throws TorqueException, NoRowsException, TooManyRowsException
698 {
699 Connection db = null;
700JetspeedUserProfile retVal = null;
701try702 {
703 db = Torque.getConnection(DATABASE_NAME);
704 retVal = retrieveByPK(pk, db);
705 }
706finally707 {
708 Torque.closeConnection(db);
709 }
710return(retVal);
711 }
712713/***714 * Retrieve a single object by pk715 *716 * @param pk the primary key717 * @param con the connection to use718 * @throws TorqueException Any exceptions caught during processing will be719 * rethrown wrapped into a TorqueException.720 * @throws NoRowsException Primary key was not found in database.721 * @throws TooManyRowsException Primary key was not found in database.722 */723publicstaticJetspeedUserProfile retrieveByPK(ObjectKey pk, Connection con)
724 throws TorqueException, NoRowsException, TooManyRowsException
725 {
726 Criteria criteria = buildCriteria(pk);
727 List v = doSelect(criteria, con);
728if (v.size() == 0)
729 {
730thrownew NoRowsException("Failed to select a row.");
731 }
732elseif (v.size() > 1)
733 {
734thrownew TooManyRowsException("Failed to select only one row.");
735 }
736else737 {
738return (JetspeedUserProfile)v.get(0);
739 }
740 }
741742/***743 * Retrieve a multiple objects by pk744 *745 * @param pks List of primary keys746 * @throws TorqueException Any exceptions caught during processing will be747 * rethrown wrapped into a TorqueException.748 */749publicstatic List retrieveByPKs(List pks)
750 throws TorqueException
751 {
752 Connection db = null;
753 List retVal = null;
754try755 {
756 db = Torque.getConnection(DATABASE_NAME);
757 retVal = retrieveByPKs(pks, db);
758 }
759finally760 {
761 Torque.closeConnection(db);
762 }
763return(retVal);
764 }
765766/***767 * Retrieve a multiple objects by pk768 *769 * @param pks List of primary keys770 * @param dbcon the connection to use771 * @throws TorqueException Any exceptions caught during processing will be772 * rethrown wrapped into a TorqueException.773 */774publicstatic List retrieveByPKs( List pks, Connection dbcon )
775 throws TorqueException
776 {
777 List objs = null;
778if (pks == null || pks.size() == 0)
779 {
780 objs = new LinkedList();
781 }
782else783 {
784 Criteria criteria = new Criteria();
785 criteria.addIn( PSML_ID, pks );
786 objs = doSelect(criteria, dbcon);
787 }
788return objs;
789 }
790791792793794795796797798799800/***801 * Returns the TableMap related to this peer. This method is not802 * needed for general use but a specific application could have a need.803 *804 * @throws TorqueException Any exceptions caught during processing will be805 * rethrown wrapped into a TorqueException.806 */807protectedstatic TableMap getTableMap()
808 throws TorqueException
809 {
810return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
811 }
812 }