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 DependType
027: */
028: public abstract class BaseDependType extends BaseObject implements
029: org.apache.fulcrum.intake.Retrievable {
030: /** The Peer class */
031: private static final DependTypePeer peer = new DependTypePeer();
032:
033: /** The value for the dependTypeId field */
034: private Integer dependTypeId;
035:
036: /** The value for the name field */
037: private String name;
038:
039: /**
040: * Get the DependTypeId
041: *
042: * @return Integer
043: */
044: public Integer getDependTypeId() {
045: return dependTypeId;
046: }
047:
048: /**
049: * Set the value of DependTypeId
050: *
051: * @param v new value
052: */
053: public void setDependTypeId(Integer v) throws TorqueException {
054:
055: if (!ObjectUtils.equals(this .dependTypeId, v)) {
056: this .dependTypeId = v;
057: setModified(true);
058: }
059:
060: // update associated Depend
061: if (collDepends != null) {
062: for (int i = 0; i < collDepends.size(); i++) {
063: ((Depend) collDepends.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 collDepends
093: */
094: protected List collDepends;
095:
096: /**
097: * Temporary storage of collDepends 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 initDepends() {
102: if (collDepends == null) {
103: collDepends = new ArrayList();
104: }
105: }
106:
107: /**
108: * Method called to associate a Depend object to this object
109: * through the Depend foreign key attribute
110: *
111: * @param l Depend
112: * @throws TorqueException
113: */
114: public void addDepend(Depend l) throws TorqueException {
115: getDepends().add(l);
116: l.setDependType((DependType) this );
117: }
118:
119: /**
120: * The criteria used to select the current contents of collDepends
121: */
122: private Criteria lastDependsCriteria = null;
123:
124: /**
125: * If this collection has already been initialized, returns
126: * the collection. Otherwise returns the results of
127: * getDepends(new Criteria())
128: *
129: * @return the collection of associated objects
130: * @throws TorqueException
131: */
132: public List getDepends() throws TorqueException {
133: if (collDepends == null) {
134: collDepends = getDepends(new Criteria(10));
135: }
136: return collDepends;
137: }
138:
139: /**
140: * If this collection has already been initialized with
141: * an identical criteria, it returns the collection.
142: * Otherwise if this DependType has previously
143: * been saved, it will retrieve related Depends from storage.
144: * If this DependType 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 getDepends(Criteria criteria) throws TorqueException {
151: if (collDepends == null) {
152: if (isNew()) {
153: collDepends = new ArrayList();
154: } else {
155: criteria.add(DependPeer.DEPEND_TYPE_ID,
156: getDependTypeId());
157: collDepends = DependPeer.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(DependPeer.DEPEND_TYPE_ID,
166: getDependTypeId());
167: if (!lastDependsCriteria.equals(criteria)) {
168: collDepends = DependPeer.doSelect(criteria);
169: }
170: }
171: }
172: lastDependsCriteria = criteria;
173:
174: return collDepends;
175: }
176:
177: /**
178: * If this collection has already been initialized, returns
179: * the collection. Otherwise returns the results of
180: * getDepends(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 getDepends(Connection con) throws TorqueException {
186: if (collDepends == null) {
187: collDepends = getDepends(new Criteria(10), con);
188: }
189: return collDepends;
190: }
191:
192: /**
193: * If this collection has already been initialized with
194: * an identical criteria, it returns the collection.
195: * Otherwise if this DependType has previously
196: * been saved, it will retrieve related Depends from storage.
197: * If this DependType 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 getDepends(Criteria criteria, Connection con)
205: throws TorqueException {
206: if (collDepends == null) {
207: if (isNew()) {
208: collDepends = new ArrayList();
209: } else {
210: criteria.add(DependPeer.DEPEND_TYPE_ID,
211: getDependTypeId());
212: collDepends = DependPeer.doSelect(criteria, 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(DependPeer.DEPEND_TYPE_ID,
221: getDependTypeId());
222: if (!lastDependsCriteria.equals(criteria)) {
223: collDepends = DependPeer.doSelect(criteria, con);
224: }
225: }
226: }
227: lastDependsCriteria = criteria;
228:
229: return collDepends;
230: }
231:
232: /**
233: * If this collection has already been initialized with
234: * an identical criteria, it returns the collection.
235: * Otherwise if this DependType is new, it will return
236: * an empty collection; or if this DependType has previously
237: * been saved, it will retrieve related Depends 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 DependType.
242: */
243: protected List getDependsJoinIssueRelatedByObservedId(
244: Criteria criteria) throws TorqueException {
245: if (collDepends == null) {
246: if (isNew()) {
247: collDepends = new ArrayList();
248: } else {
249: criteria.add(DependPeer.DEPEND_TYPE_ID,
250: getDependTypeId());
251: collDepends = DependPeer
252: .doSelectJoinIssueRelatedByObservedId(criteria);
253: }
254: } else {
255: // the following code is to determine if a new query is
256: // called for. If the criteria is the same as the last
257: // one, just return the collection.
258: criteria.add(DependPeer.DEPEND_TYPE_ID, getDependTypeId());
259: if (!lastDependsCriteria.equals(criteria)) {
260: collDepends = DependPeer
261: .doSelectJoinIssueRelatedByObservedId(criteria);
262: }
263: }
264: lastDependsCriteria = criteria;
265:
266: return collDepends;
267: }
268:
269: /**
270: * If this collection has already been initialized with
271: * an identical criteria, it returns the collection.
272: * Otherwise if this DependType is new, it will return
273: * an empty collection; or if this DependType has previously
274: * been saved, it will retrieve related Depends from storage.
275: *
276: * This method is protected by default in order to keep the public
277: * api reasonable. You can provide public methods for those you
278: * actually need in DependType.
279: */
280: protected List getDependsJoinIssueRelatedByObserverId(
281: Criteria criteria) throws TorqueException {
282: if (collDepends == null) {
283: if (isNew()) {
284: collDepends = new ArrayList();
285: } else {
286: criteria.add(DependPeer.DEPEND_TYPE_ID,
287: getDependTypeId());
288: collDepends = DependPeer
289: .doSelectJoinIssueRelatedByObserverId(criteria);
290: }
291: } else {
292: // the following code is to determine if a new query is
293: // called for. If the criteria is the same as the last
294: // one, just return the collection.
295: criteria.add(DependPeer.DEPEND_TYPE_ID, getDependTypeId());
296: if (!lastDependsCriteria.equals(criteria)) {
297: collDepends = DependPeer
298: .doSelectJoinIssueRelatedByObserverId(criteria);
299: }
300: }
301: lastDependsCriteria = criteria;
302:
303: return collDepends;
304: }
305:
306: /**
307: * If this collection has already been initialized with
308: * an identical criteria, it returns the collection.
309: * Otherwise if this DependType is new, it will return
310: * an empty collection; or if this DependType has previously
311: * been saved, it will retrieve related Depends from storage.
312: *
313: * This method is protected by default in order to keep the public
314: * api reasonable. You can provide public methods for those you
315: * actually need in DependType.
316: */
317: protected List getDependsJoinDependType(Criteria criteria)
318: throws TorqueException {
319: if (collDepends == null) {
320: if (isNew()) {
321: collDepends = new ArrayList();
322: } else {
323: criteria.add(DependPeer.DEPEND_TYPE_ID,
324: getDependTypeId());
325: collDepends = DependPeer
326: .doSelectJoinDependType(criteria);
327: }
328: } else {
329: // the following code is to determine if a new query is
330: // called for. If the criteria is the same as the last
331: // one, just return the collection.
332: criteria.add(DependPeer.DEPEND_TYPE_ID, getDependTypeId());
333: if (!lastDependsCriteria.equals(criteria)) {
334: collDepends = DependPeer
335: .doSelectJoinDependType(criteria);
336: }
337: }
338: lastDependsCriteria = criteria;
339:
340: return collDepends;
341: }
342:
343: private static List fieldNames = null;
344:
345: /**
346: * Generate a list of field names.
347: *
348: * @return a list of field names
349: */
350: public static synchronized List getFieldNames() {
351: if (fieldNames == null) {
352: fieldNames = new ArrayList();
353: fieldNames.add("DependTypeId");
354: fieldNames.add("Name");
355: fieldNames = Collections.unmodifiableList(fieldNames);
356: }
357: return fieldNames;
358: }
359:
360: /**
361: * Retrieves a field from the object by name passed in as a String.
362: *
363: * @param name field name
364: * @return value
365: */
366: public Object getByName(String name) {
367: if (name.equals("DependTypeId")) {
368: return getDependTypeId();
369: }
370: if (name.equals("Name")) {
371: return getName();
372: }
373: return null;
374: }
375:
376: /**
377: * Retrieves a field from the object by name passed in
378: * as a String. The String must be one of the static
379: * Strings defined in this Class' Peer.
380: *
381: * @param name peer name
382: * @return value
383: */
384: public Object getByPeerName(String name) {
385: if (name.equals(DependTypePeer.DEPEND_TYPE_ID)) {
386: return getDependTypeId();
387: }
388: if (name.equals(DependTypePeer.DEPEND_TYPE_NAME)) {
389: return getName();
390: }
391: return null;
392: }
393:
394: /**
395: * Retrieves a field from the object by Position as specified
396: * in the xml schema. Zero-based.
397: *
398: * @param pos position in xml schema
399: * @return value
400: */
401: public Object getByPosition(int pos) {
402: if (pos == 0) {
403: return getDependTypeId();
404: }
405: if (pos == 1) {
406: return getName();
407: }
408: return null;
409: }
410:
411: /**
412: * Stores the object in the database. If the object is new,
413: * it inserts it; otherwise an update is performed.
414: *
415: * @throws TorqueException
416: */
417: public void save() throws TorqueException {
418: save(DependTypePeer.getMapBuilder().getDatabaseMap().getName());
419: }
420:
421: /**
422: * Stores the object in the database. If the object is new,
423: * it inserts it; otherwise an update is performed.
424: * Note: this code is here because the method body is
425: * auto-generated conditionally and therefore needs to be
426: * in this file instead of in the super class, BaseObject.
427: *
428: * @param dbName
429: * @throws TorqueException
430: */
431: public void save(String dbName) throws TorqueException {
432: Connection con = null;
433: try {
434: con = Transaction.begin(dbName);
435: save(con);
436: Transaction.commit(con);
437: } catch (TorqueException e) {
438: Transaction.safeRollback(con);
439: throw e;
440: }
441: }
442:
443: /** flag to prevent endless save loop, if this object is referenced
444: by another object which falls in this transaction. */
445: private boolean alreadyInSave = false;
446:
447: /**
448: * Stores the object in the database. If the object is new,
449: * it inserts it; otherwise an update is performed. This method
450: * is meant to be used as part of a transaction, otherwise use
451: * the save() method and the connection details will be handled
452: * internally
453: *
454: * @param con
455: * @throws TorqueException
456: */
457: public void save(Connection con) throws TorqueException {
458: if (!alreadyInSave) {
459: alreadyInSave = true;
460:
461: // If this object has been modified, then save it to the database.
462: if (isModified()) {
463: if (isNew()) {
464: DependTypePeer.doInsert((DependType) this , con);
465: setNew(false);
466: } else {
467: DependTypePeer.doUpdate((DependType) this , con);
468: }
469:
470: if (isCacheOnSave()) {
471: DependTypeManager.putInstance(this );
472: }
473: }
474:
475: if (collDepends != null) {
476: for (int i = 0; i < collDepends.size(); i++) {
477: ((Depend) collDepends.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 dependTypeId ObjectKey
496: */
497: public void setPrimaryKey(ObjectKey key) throws TorqueException {
498: setDependTypeId(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: setDependTypeId(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(getDependTypeId());
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 DependType copy() throws TorqueException {
545: return copyInto(new DependType());
546: }
547:
548: protected DependType copyInto(DependType copyObj)
549: throws TorqueException {
550: copyObj.setDependTypeId(dependTypeId);
551: copyObj.setName(name);
552:
553: copyObj.setDependTypeId((Integer) null);
554:
555: List v = getDepends();
556: if (v != null) {
557: for (int i = 0; i < v.size(); i++) {
558: Depend obj = (Depend) v.get(i);
559: copyObj.addDepend(obj.copy());
560: }
561: } else {
562: copyObj.collDepends = 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 DependTypePeer getPeer() {
574: return peer;
575: }
576:
577: public String toString() {
578: StringBuffer str = new StringBuffer();
579: str.append("DependType:\n");
580: str.append("DependTypeId = ").append(getDependTypeId()).append(
581: "\n");
582: str.append("Name = ").append(getName()).append("\n");
583: return (str.toString());
584: }
585: }
|