001: package org.tigris.scarab.om;
002:
003: import java.math.BigDecimal;
004: import java.sql.Connection;
005: import java.util.ArrayList;
006: import java.util.Collections;
007: import java.util.Date;
008: import java.util.List;
009:
010: import org.apache.commons.lang.ObjectUtils;
011: import org.apache.fulcrum.intake.Retrievable;
012: import org.apache.torque.TorqueException;
013: import org.apache.torque.om.BaseObject;
014: import org.apache.torque.om.ComboKey;
015: import org.apache.torque.om.DateKey;
016: import org.apache.torque.om.NumberKey;
017: import org.apache.torque.om.ObjectKey;
018: import org.apache.torque.om.SimpleKey;
019: import org.apache.torque.om.StringKey;
020: import org.apache.torque.om.Persistent;
021: import org.apache.torque.util.Criteria;
022: import org.apache.torque.util.Transaction;
023:
024: /**
025: * You should not use this class directly. It should not even be
026: * extended all references should be to ActivitySetType
027: */
028: public abstract class BaseActivitySetType extends BaseObject implements
029: org.apache.fulcrum.intake.Retrievable {
030: /** The Peer class */
031: private static final ActivitySetTypePeer peer = new ActivitySetTypePeer();
032:
033: /** The value for the typeId field */
034: private Integer typeId;
035:
036: /** The value for the name field */
037: private String name;
038:
039: /**
040: * Get the TypeId
041: *
042: * @return Integer
043: */
044: public Integer getTypeId() {
045: return typeId;
046: }
047:
048: /**
049: * Set the value of TypeId
050: *
051: * @param v new value
052: */
053: public void setTypeId(Integer v) throws TorqueException {
054:
055: if (!ObjectUtils.equals(this .typeId, v)) {
056: this .typeId = v;
057: setModified(true);
058: }
059:
060: // update associated ActivitySet
061: if (collActivitySets != null) {
062: for (int i = 0; i < collActivitySets.size(); i++) {
063: ((ActivitySet) collActivitySets.get(i)).setTypeId(v);
064: }
065: }
066: }
067:
068: /**
069: * Get the Name
070: *
071: * @return String
072: */
073: public String getName() {
074: return name;
075: }
076:
077: /**
078: * Set the value of Name
079: *
080: * @param v new value
081: */
082: public void setName(String v) {
083:
084: if (!ObjectUtils.equals(this .name, v)) {
085: this .name = v;
086: setModified(true);
087: }
088:
089: }
090:
091: /**
092: * Collection to store aggregation of collActivitySets
093: */
094: protected List collActivitySets;
095:
096: /**
097: * Temporary storage of collActivitySets to save a possible db hit in
098: * the event objects are add to the collection, but the
099: * complete collection is never requested.
100: */
101: protected void initActivitySets() {
102: if (collActivitySets == null) {
103: collActivitySets = new ArrayList();
104: }
105: }
106:
107: /**
108: * Method called to associate a ActivitySet object to this object
109: * through the ActivitySet foreign key attribute
110: *
111: * @param l ActivitySet
112: * @throws TorqueException
113: */
114: public void addActivitySet(ActivitySet l) throws TorqueException {
115: getActivitySets().add(l);
116: l.setActivitySetType((ActivitySetType) this );
117: }
118:
119: /**
120: * The criteria used to select the current contents of collActivitySets
121: */
122: private Criteria lastActivitySetsCriteria = null;
123:
124: /**
125: * If this collection has already been initialized, returns
126: * the collection. Otherwise returns the results of
127: * getActivitySets(new Criteria())
128: *
129: * @return the collection of associated objects
130: * @throws TorqueException
131: */
132: public List getActivitySets() throws TorqueException {
133: if (collActivitySets == null) {
134: collActivitySets = getActivitySets(new Criteria(10));
135: }
136: return collActivitySets;
137: }
138:
139: /**
140: * If this collection has already been initialized with
141: * an identical criteria, it returns the collection.
142: * Otherwise if this ActivitySetType has previously
143: * been saved, it will retrieve related ActivitySets from storage.
144: * If this ActivitySetType is new, it will return
145: * an empty collection or the current collection, the criteria
146: * is ignored on a new object.
147: *
148: * @throws TorqueException
149: */
150: public List getActivitySets(Criteria criteria)
151: throws TorqueException {
152: if (collActivitySets == null) {
153: if (isNew()) {
154: collActivitySets = new ArrayList();
155: } else {
156: criteria.add(ActivitySetPeer.TYPE_ID, getTypeId());
157: collActivitySets = ActivitySetPeer.doSelect(criteria);
158: }
159: } else {
160: // criteria has no effect for a new object
161: if (!isNew()) {
162: // the following code is to determine if a new query is
163: // called for. If the criteria is the same as the last
164: // one, just return the collection.
165: criteria.add(ActivitySetPeer.TYPE_ID, getTypeId());
166: if (!lastActivitySetsCriteria.equals(criteria)) {
167: collActivitySets = ActivitySetPeer
168: .doSelect(criteria);
169: }
170: }
171: }
172: lastActivitySetsCriteria = criteria;
173:
174: return collActivitySets;
175: }
176:
177: /**
178: * If this collection has already been initialized, returns
179: * the collection. Otherwise returns the results of
180: * getActivitySets(new Criteria(),Connection)
181: * This method takes in the Connection also as input so that
182: * referenced objects can also be obtained using a Connection
183: * that is taken as input
184: */
185: public List getActivitySets(Connection con) throws TorqueException {
186: if (collActivitySets == null) {
187: collActivitySets = getActivitySets(new Criteria(10), con);
188: }
189: return collActivitySets;
190: }
191:
192: /**
193: * If this collection has already been initialized with
194: * an identical criteria, it returns the collection.
195: * Otherwise if this ActivitySetType has previously
196: * been saved, it will retrieve related ActivitySets from storage.
197: * If this ActivitySetType is new, it will return
198: * an empty collection or the current collection, the criteria
199: * is ignored on a new object.
200: * This method takes in the Connection also as input so that
201: * referenced objects can also be obtained using a Connection
202: * that is taken as input
203: */
204: public List getActivitySets(Criteria criteria, Connection con)
205: throws TorqueException {
206: if (collActivitySets == null) {
207: if (isNew()) {
208: collActivitySets = new ArrayList();
209: } else {
210: criteria.add(ActivitySetPeer.TYPE_ID, getTypeId());
211: collActivitySets = ActivitySetPeer.doSelect(criteria,
212: con);
213: }
214: } else {
215: // criteria has no effect for a new object
216: if (!isNew()) {
217: // the following code is to determine if a new query is
218: // called for. If the criteria is the same as the last
219: // one, just return the collection.
220: criteria.add(ActivitySetPeer.TYPE_ID, getTypeId());
221: if (!lastActivitySetsCriteria.equals(criteria)) {
222: collActivitySets = ActivitySetPeer.doSelect(
223: criteria, con);
224: }
225: }
226: }
227: lastActivitySetsCriteria = criteria;
228:
229: return collActivitySets;
230: }
231:
232: /**
233: * If this collection has already been initialized with
234: * an identical criteria, it returns the collection.
235: * Otherwise if this ActivitySetType is new, it will return
236: * an empty collection; or if this ActivitySetType has previously
237: * been saved, it will retrieve related ActivitySets from storage.
238: *
239: * This method is protected by default in order to keep the public
240: * api reasonable. You can provide public methods for those you
241: * actually need in ActivitySetType.
242: */
243: protected List getActivitySetsJoinScarabUserImpl(Criteria criteria)
244: throws TorqueException {
245: if (collActivitySets == null) {
246: if (isNew()) {
247: collActivitySets = new ArrayList();
248: } else {
249: criteria.add(ActivitySetPeer.TYPE_ID, getTypeId());
250: collActivitySets = ActivitySetPeer
251: .doSelectJoinScarabUserImpl(criteria);
252: }
253: } else {
254: // the following code is to determine if a new query is
255: // called for. If the criteria is the same as the last
256: // one, just return the collection.
257: criteria.add(ActivitySetPeer.TYPE_ID, getTypeId());
258: if (!lastActivitySetsCriteria.equals(criteria)) {
259: collActivitySets = ActivitySetPeer
260: .doSelectJoinScarabUserImpl(criteria);
261: }
262: }
263: lastActivitySetsCriteria = criteria;
264:
265: return collActivitySets;
266: }
267:
268: /**
269: * If this collection has already been initialized with
270: * an identical criteria, it returns the collection.
271: * Otherwise if this ActivitySetType is new, it will return
272: * an empty collection; or if this ActivitySetType has previously
273: * been saved, it will retrieve related ActivitySets from storage.
274: *
275: * This method is protected by default in order to keep the public
276: * api reasonable. You can provide public methods for those you
277: * actually need in ActivitySetType.
278: */
279: protected List getActivitySetsJoinActivitySetType(Criteria criteria)
280: throws TorqueException {
281: if (collActivitySets == null) {
282: if (isNew()) {
283: collActivitySets = new ArrayList();
284: } else {
285: criteria.add(ActivitySetPeer.TYPE_ID, getTypeId());
286: collActivitySets = ActivitySetPeer
287: .doSelectJoinActivitySetType(criteria);
288: }
289: } else {
290: // the following code is to determine if a new query is
291: // called for. If the criteria is the same as the last
292: // one, just return the collection.
293: criteria.add(ActivitySetPeer.TYPE_ID, getTypeId());
294: if (!lastActivitySetsCriteria.equals(criteria)) {
295: collActivitySets = ActivitySetPeer
296: .doSelectJoinActivitySetType(criteria);
297: }
298: }
299: lastActivitySetsCriteria = criteria;
300:
301: return collActivitySets;
302: }
303:
304: /**
305: * If this collection has already been initialized with
306: * an identical criteria, it returns the collection.
307: * Otherwise if this ActivitySetType is new, it will return
308: * an empty collection; or if this ActivitySetType has previously
309: * been saved, it will retrieve related ActivitySets from storage.
310: *
311: * This method is protected by default in order to keep the public
312: * api reasonable. You can provide public methods for those you
313: * actually need in ActivitySetType.
314: */
315: protected List getActivitySetsJoinAttachment(Criteria criteria)
316: throws TorqueException {
317: if (collActivitySets == null) {
318: if (isNew()) {
319: collActivitySets = new ArrayList();
320: } else {
321: criteria.add(ActivitySetPeer.TYPE_ID, getTypeId());
322: collActivitySets = ActivitySetPeer
323: .doSelectJoinAttachment(criteria);
324: }
325: } else {
326: // the following code is to determine if a new query is
327: // called for. If the criteria is the same as the last
328: // one, just return the collection.
329: criteria.add(ActivitySetPeer.TYPE_ID, getTypeId());
330: if (!lastActivitySetsCriteria.equals(criteria)) {
331: collActivitySets = ActivitySetPeer
332: .doSelectJoinAttachment(criteria);
333: }
334: }
335: lastActivitySetsCriteria = criteria;
336:
337: return collActivitySets;
338: }
339:
340: private static List fieldNames = null;
341:
342: /**
343: * Generate a list of field names.
344: *
345: * @return a list of field names
346: */
347: public static synchronized List getFieldNames() {
348: if (fieldNames == null) {
349: fieldNames = new ArrayList();
350: fieldNames.add("TypeId");
351: fieldNames.add("Name");
352: fieldNames = Collections.unmodifiableList(fieldNames);
353: }
354: return fieldNames;
355: }
356:
357: /**
358: * Retrieves a field from the object by name passed in as a String.
359: *
360: * @param name field name
361: * @return value
362: */
363: public Object getByName(String name) {
364: if (name.equals("TypeId")) {
365: return getTypeId();
366: }
367: if (name.equals("Name")) {
368: return getName();
369: }
370: return null;
371: }
372:
373: /**
374: * Retrieves a field from the object by name passed in
375: * as a String. The String must be one of the static
376: * Strings defined in this Class' Peer.
377: *
378: * @param name peer name
379: * @return value
380: */
381: public Object getByPeerName(String name) {
382: if (name.equals(ActivitySetTypePeer.TYPE_ID)) {
383: return getTypeId();
384: }
385: if (name.equals(ActivitySetTypePeer.NAME)) {
386: return getName();
387: }
388: return null;
389: }
390:
391: /**
392: * Retrieves a field from the object by Position as specified
393: * in the xml schema. Zero-based.
394: *
395: * @param pos position in xml schema
396: * @return value
397: */
398: public Object getByPosition(int pos) {
399: if (pos == 0) {
400: return getTypeId();
401: }
402: if (pos == 1) {
403: return getName();
404: }
405: return null;
406: }
407:
408: /**
409: * Stores the object in the database. If the object is new,
410: * it inserts it; otherwise an update is performed.
411: *
412: * @throws TorqueException
413: */
414: public void save() throws TorqueException {
415: save(ActivitySetTypePeer.getMapBuilder().getDatabaseMap()
416: .getName());
417: }
418:
419: /**
420: * Stores the object in the database. If the object is new,
421: * it inserts it; otherwise an update is performed.
422: * Note: this code is here because the method body is
423: * auto-generated conditionally and therefore needs to be
424: * in this file instead of in the super class, BaseObject.
425: *
426: * @param dbName
427: * @throws TorqueException
428: */
429: public void save(String dbName) throws TorqueException {
430: Connection con = null;
431: try {
432: con = Transaction.begin(dbName);
433: save(con);
434: Transaction.commit(con);
435: } catch (TorqueException e) {
436: Transaction.safeRollback(con);
437: throw e;
438: }
439: }
440:
441: /** flag to prevent endless save loop, if this object is referenced
442: by another object which falls in this transaction. */
443: private boolean alreadyInSave = false;
444:
445: /**
446: * Stores the object in the database. If the object is new,
447: * it inserts it; otherwise an update is performed. This method
448: * is meant to be used as part of a transaction, otherwise use
449: * the save() method and the connection details will be handled
450: * internally
451: *
452: * @param con
453: * @throws TorqueException
454: */
455: public void save(Connection con) throws TorqueException {
456: if (!alreadyInSave) {
457: alreadyInSave = true;
458:
459: // If this object has been modified, then save it to the database.
460: if (isModified()) {
461: if (isNew()) {
462: ActivitySetTypePeer.doInsert(
463: (ActivitySetType) this , con);
464: setNew(false);
465: } else {
466: ActivitySetTypePeer.doUpdate(
467: (ActivitySetType) this , con);
468: }
469:
470: if (isCacheOnSave()) {
471: ActivitySetTypeManager.putInstance(this );
472: }
473: }
474:
475: if (collActivitySets != null) {
476: for (int i = 0; i < collActivitySets.size(); i++) {
477: ((ActivitySet) collActivitySets.get(i)).save(con);
478: }
479: }
480: alreadyInSave = false;
481: }
482: }
483:
484: /**
485: * Specify whether to cache the object after saving to the db.
486: * This method returns true
487: */
488: protected boolean isCacheOnSave() {
489: return true;
490: }
491:
492: /**
493: * Set the PrimaryKey using ObjectKey.
494: *
495: * @param key typeId ObjectKey
496: */
497: public void setPrimaryKey(ObjectKey key) throws TorqueException {
498: setTypeId(new Integer(((NumberKey) key).intValue()));
499: }
500:
501: /**
502: * Set the PrimaryKey using a String.
503: *
504: * @param key
505: */
506: public void setPrimaryKey(String key) throws TorqueException {
507: setTypeId(new Integer(key));
508: }
509:
510: /**
511: * returns an id that differentiates this object from others
512: * of its class.
513: */
514: public ObjectKey getPrimaryKey() {
515: return SimpleKey.keyFor(getTypeId());
516: }
517:
518: /**
519: * get an id that differentiates this object from others
520: * of its class.
521: */
522: public String getQueryKey() {
523: if (getPrimaryKey() == null) {
524: return "";
525: } else {
526: return getPrimaryKey().toString();
527: }
528: }
529:
530: /**
531: * set an id that differentiates this object from others
532: * of its class.
533: */
534: public void setQueryKey(String key) throws TorqueException {
535: setPrimaryKey(key);
536: }
537:
538: /**
539: * Makes a copy of this object.
540: * It creates a new object filling in the simple attributes.
541: * It then fills all the association collections and sets the
542: * related objects to isNew=true.
543: */
544: public ActivitySetType copy() throws TorqueException {
545: return copyInto(new ActivitySetType());
546: }
547:
548: protected ActivitySetType copyInto(ActivitySetType copyObj)
549: throws TorqueException {
550: copyObj.setTypeId(typeId);
551: copyObj.setName(name);
552:
553: copyObj.setTypeId((Integer) null);
554:
555: List v = getActivitySets();
556: if (v != null) {
557: for (int i = 0; i < v.size(); i++) {
558: ActivitySet obj = (ActivitySet) v.get(i);
559: copyObj.addActivitySet(obj.copy());
560: }
561: } else {
562: copyObj.collActivitySets = null;
563: }
564: return copyObj;
565: }
566:
567: /**
568: * returns a peer instance associated with this om. Since Peer classes
569: * are not to have any instance attributes, this method returns the
570: * same instance for all member of this class. The method could therefore
571: * be static, but this would prevent one from overriding the behavior.
572: */
573: public ActivitySetTypePeer getPeer() {
574: return peer;
575: }
576:
577: public String toString() {
578: StringBuffer str = new StringBuffer();
579: str.append("ActivitySetType:\n");
580: str.append("TypeId = ").append(getTypeId()).append("\n");
581: str.append("Name = ").append(getName()).append("\n");
582: return (str.toString());
583: }
584: }
|