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 NotificationStatus
027: */
028: public abstract class BaseNotificationStatus extends BaseObject
029: implements org.apache.fulcrum.intake.Retrievable {
030: /** The Peer class */
031: private static final NotificationStatusPeer peer = new NotificationStatusPeer();
032:
033: /** The value for the activityId field */
034: private Long activityId;
035:
036: /** The value for the creatorId field */
037: private Integer creatorId;
038:
039: /** The value for the receiverId field */
040: private Integer receiverId;
041:
042: /** The value for the status field */
043: private Integer status;
044:
045: /** The value for the creationDate field */
046: private Date creationDate;
047:
048: /** The value for the changeDate field */
049: private Date changeDate;
050:
051: /** The value for the comment field */
052: private String comment;
053:
054: /**
055: * Get the ActivityId
056: *
057: * @return Long
058: */
059: public Long getActivityId() {
060: return activityId;
061: }
062:
063: /**
064: * Set the value of ActivityId
065: *
066: * @param v new value
067: */
068: public void setActivityId(Long v) throws TorqueException {
069:
070: if (!ObjectUtils.equals(this .activityId, v)) {
071: this .activityId = v;
072: setModified(true);
073: }
074:
075: if (aActivity != null
076: && !ObjectUtils.equals(aActivity.getActivityId(), v)) {
077: aActivity = null;
078: }
079:
080: }
081:
082: /**
083: * Get the CreatorId
084: *
085: * @return Integer
086: */
087: public Integer getCreatorId() {
088: return creatorId;
089: }
090:
091: /**
092: * Set the value of CreatorId
093: *
094: * @param v new value
095: */
096: public void setCreatorId(Integer v) throws TorqueException {
097:
098: if (!ObjectUtils.equals(this .creatorId, v)) {
099: this .creatorId = v;
100: setModified(true);
101: }
102:
103: if (aScarabUser != null
104: && !ObjectUtils.equals(aScarabUser.getUserId(), v)) {
105: aScarabUser = null;
106: }
107:
108: }
109:
110: /**
111: * Get the ReceiverId
112: *
113: * @return Integer
114: */
115: public Integer getReceiverId() {
116: return receiverId;
117: }
118:
119: /**
120: * Set the value of ReceiverId
121: *
122: * @param v new value
123: */
124: public void setReceiverId(Integer v) {
125:
126: if (!ObjectUtils.equals(this .receiverId, v)) {
127: this .receiverId = v;
128: setModified(true);
129: }
130:
131: }
132:
133: /**
134: * Get the Status
135: *
136: * @return Integer
137: */
138: public Integer getStatus() {
139: return status;
140: }
141:
142: /**
143: * Set the value of Status
144: *
145: * @param v new value
146: */
147: public void setStatus(Integer v) {
148:
149: if (!ObjectUtils.equals(this .status, v)) {
150: this .status = v;
151: setModified(true);
152: }
153:
154: }
155:
156: /**
157: * Get the CreationDate
158: *
159: * @return Date
160: */
161: public Date getCreationDate() {
162: return creationDate;
163: }
164:
165: /**
166: * Set the value of CreationDate
167: *
168: * @param v new value
169: */
170: public void setCreationDate(Date v) {
171:
172: if (!ObjectUtils.equals(this .creationDate, v)) {
173: this .creationDate = v;
174: setModified(true);
175: }
176:
177: }
178:
179: /**
180: * Get the ChangeDate
181: *
182: * @return Date
183: */
184: public Date getChangeDate() {
185: return changeDate;
186: }
187:
188: /**
189: * Set the value of ChangeDate
190: *
191: * @param v new value
192: */
193: public void setChangeDate(Date v) {
194:
195: if (!ObjectUtils.equals(this .changeDate, v)) {
196: this .changeDate = v;
197: setModified(true);
198: }
199:
200: }
201:
202: /**
203: * Get the Comment
204: *
205: * @return String
206: */
207: public String getComment() {
208: return comment;
209: }
210:
211: /**
212: * Set the value of Comment
213: *
214: * @param v new value
215: */
216: public void setComment(String v) {
217:
218: if (!ObjectUtils.equals(this .comment, v)) {
219: this .comment = v;
220: setModified(true);
221: }
222:
223: }
224:
225: private ScarabUser aScarabUser;
226:
227: /**
228: * Declares an association between this object and a ScarabUser object
229: *
230: * @param v ScarabUser
231: * @throws TorqueException
232: */
233: public void setScarabUser(ScarabUser v) throws TorqueException {
234: if (v == null) {
235: setCreatorId((Integer) null);
236: } else {
237: setCreatorId(v.getUserId());
238: }
239: aScarabUser = v;
240: }
241:
242: /**
243: * Returns the associated ScarabUser object.
244: * If it was not retrieved before, the object is retrieved from
245: * the database
246: *
247: * @return the associated ScarabUser object
248: * @throws TorqueException
249: */
250: public ScarabUser getScarabUser() throws TorqueException {
251: if (aScarabUser == null
252: && (!ObjectUtils.equals(this .creatorId, null))) {
253: aScarabUser = ScarabUserManager.getInstance(SimpleKey
254: .keyFor(this .creatorId));
255: }
256: return aScarabUser;
257: }
258:
259: /**
260: * Return the associated ScarabUser object
261: * If it was not retrieved before, the object is retrieved from
262: * the database using the passed connection
263: *
264: * @param connection the connection used to retrieve the associated object
265: * from the database, if it was not retrieved before
266: * @return the associated ScarabUser object
267: * @throws TorqueException
268: */
269: public ScarabUser getScarabUser(Connection connection)
270: throws TorqueException {
271: if (aScarabUser == null
272: && (!ObjectUtils.equals(this .creatorId, null))) {
273: aScarabUser = ScarabUserManager.getCachedInstance(SimpleKey
274: .keyFor(this .creatorId));
275: if (aScarabUser == null) {
276: aScarabUser = ScarabUserImplPeer
277: .retrieveScarabUserImplByPK(SimpleKey
278: .keyFor(this .creatorId), connection);
279: ScarabUserManager.putInstance(aScarabUser);
280: }
281: }
282: return aScarabUser;
283: }
284:
285: /**
286: * Provides convenient way to set a relationship based on a
287: * ObjectKey, for example
288: * <code>bar.setFooKey(foo.getPrimaryKey())</code>
289: *
290: */
291: public void setScarabUserKey(ObjectKey key) throws TorqueException {
292:
293: setCreatorId(new Integer(((NumberKey) key).intValue()));
294: }
295:
296: private Activity aActivity;
297:
298: /**
299: * Declares an association between this object and a Activity object
300: *
301: * @param v Activity
302: * @throws TorqueException
303: */
304: public void setActivity(Activity v) throws TorqueException {
305: if (v == null) {
306: setActivityId((Long) null);
307: } else {
308: setActivityId(v.getActivityId());
309: }
310: aActivity = v;
311: }
312:
313: /**
314: * Returns the associated Activity object.
315: * If it was not retrieved before, the object is retrieved from
316: * the database
317: *
318: * @return the associated Activity object
319: * @throws TorqueException
320: */
321: public Activity getActivity() throws TorqueException {
322: if (aActivity == null
323: && (!ObjectUtils.equals(this .activityId, null))) {
324: aActivity = ActivityManager.getInstance(SimpleKey
325: .keyFor(this .activityId));
326: }
327: return aActivity;
328: }
329:
330: /**
331: * Return the associated Activity object
332: * If it was not retrieved before, the object is retrieved from
333: * the database using the passed connection
334: *
335: * @param connection the connection used to retrieve the associated object
336: * from the database, if it was not retrieved before
337: * @return the associated Activity object
338: * @throws TorqueException
339: */
340: public Activity getActivity(Connection connection)
341: throws TorqueException {
342: if (aActivity == null
343: && (!ObjectUtils.equals(this .activityId, null))) {
344: aActivity = ActivityManager.getCachedInstance(SimpleKey
345: .keyFor(this .activityId));
346: if (aActivity == null) {
347: aActivity = ActivityPeer.retrieveByPK(SimpleKey
348: .keyFor(this .activityId), connection);
349: ActivityManager.putInstance(aActivity);
350: }
351: }
352: return aActivity;
353: }
354:
355: /**
356: * Provides convenient way to set a relationship based on a
357: * ObjectKey, for example
358: * <code>bar.setFooKey(foo.getPrimaryKey())</code>
359: *
360: */
361: public void setActivityKey(ObjectKey key) throws TorqueException {
362:
363: setActivityId(new Long(((NumberKey) key).longValue()));
364: }
365:
366: private static List fieldNames = null;
367:
368: /**
369: * Generate a list of field names.
370: *
371: * @return a list of field names
372: */
373: public static synchronized List getFieldNames() {
374: if (fieldNames == null) {
375: fieldNames = new ArrayList();
376: fieldNames.add("ActivityId");
377: fieldNames.add("CreatorId");
378: fieldNames.add("ReceiverId");
379: fieldNames.add("Status");
380: fieldNames.add("CreationDate");
381: fieldNames.add("ChangeDate");
382: fieldNames.add("Comment");
383: fieldNames = Collections.unmodifiableList(fieldNames);
384: }
385: return fieldNames;
386: }
387:
388: /**
389: * Retrieves a field from the object by name passed in as a String.
390: *
391: * @param name field name
392: * @return value
393: */
394: public Object getByName(String name) {
395: if (name.equals("ActivityId")) {
396: return getActivityId();
397: }
398: if (name.equals("CreatorId")) {
399: return getCreatorId();
400: }
401: if (name.equals("ReceiverId")) {
402: return getReceiverId();
403: }
404: if (name.equals("Status")) {
405: return getStatus();
406: }
407: if (name.equals("CreationDate")) {
408: return getCreationDate();
409: }
410: if (name.equals("ChangeDate")) {
411: return getChangeDate();
412: }
413: if (name.equals("Comment")) {
414: return getComment();
415: }
416: return null;
417: }
418:
419: /**
420: * Retrieves a field from the object by name passed in
421: * as a String. The String must be one of the static
422: * Strings defined in this Class' Peer.
423: *
424: * @param name peer name
425: * @return value
426: */
427: public Object getByPeerName(String name) {
428: if (name.equals(NotificationStatusPeer.ACTIVITY_ID)) {
429: return getActivityId();
430: }
431: if (name.equals(NotificationStatusPeer.CREATOR_ID)) {
432: return getCreatorId();
433: }
434: if (name.equals(NotificationStatusPeer.RECEIVER_ID)) {
435: return getReceiverId();
436: }
437: if (name.equals(NotificationStatusPeer.STATUS)) {
438: return getStatus();
439: }
440: if (name.equals(NotificationStatusPeer.CREATION_DATE)) {
441: return getCreationDate();
442: }
443: if (name.equals(NotificationStatusPeer.CHANGE_DATE)) {
444: return getChangeDate();
445: }
446: if (name.equals(NotificationStatusPeer.STATUS_COMMENT)) {
447: return getComment();
448: }
449: return null;
450: }
451:
452: /**
453: * Retrieves a field from the object by Position as specified
454: * in the xml schema. Zero-based.
455: *
456: * @param pos position in xml schema
457: * @return value
458: */
459: public Object getByPosition(int pos) {
460: if (pos == 0) {
461: return getActivityId();
462: }
463: if (pos == 1) {
464: return getCreatorId();
465: }
466: if (pos == 2) {
467: return getReceiverId();
468: }
469: if (pos == 3) {
470: return getStatus();
471: }
472: if (pos == 4) {
473: return getCreationDate();
474: }
475: if (pos == 5) {
476: return getChangeDate();
477: }
478: if (pos == 6) {
479: return getComment();
480: }
481: return null;
482: }
483:
484: /**
485: * Stores the object in the database. If the object is new,
486: * it inserts it; otherwise an update is performed.
487: *
488: * @throws TorqueException
489: */
490: public void save() throws TorqueException {
491: save(NotificationStatusPeer.getMapBuilder().getDatabaseMap()
492: .getName());
493: }
494:
495: /**
496: * Stores the object in the database. If the object is new,
497: * it inserts it; otherwise an update is performed.
498: * Note: this code is here because the method body is
499: * auto-generated conditionally and therefore needs to be
500: * in this file instead of in the super class, BaseObject.
501: *
502: * @param dbName
503: * @throws TorqueException
504: */
505: public void save(String dbName) throws TorqueException {
506: Connection con = null;
507: try {
508: con = Transaction.begin(dbName);
509: save(con);
510: Transaction.commit(con);
511: } catch (TorqueException e) {
512: Transaction.safeRollback(con);
513: throw e;
514: }
515: }
516:
517: /** flag to prevent endless save loop, if this object is referenced
518: by another object which falls in this transaction. */
519: private boolean alreadyInSave = false;
520:
521: /**
522: * Stores the object in the database. If the object is new,
523: * it inserts it; otherwise an update is performed. This method
524: * is meant to be used as part of a transaction, otherwise use
525: * the save() method and the connection details will be handled
526: * internally
527: *
528: * @param con
529: * @throws TorqueException
530: */
531: public void save(Connection con) throws TorqueException {
532: if (!alreadyInSave) {
533: alreadyInSave = true;
534:
535: // If this object has been modified, then save it to the database.
536: if (isModified()) {
537: if (isNew()) {
538: NotificationStatusPeer.doInsert(
539: (NotificationStatus) this , con);
540: setNew(false);
541: } else {
542: NotificationStatusPeer.doUpdate(
543: (NotificationStatus) this , con);
544: }
545:
546: if (isCacheOnSave()) {
547: NotificationStatusManager.putInstance(this );
548: }
549: }
550:
551: alreadyInSave = false;
552: }
553: }
554:
555: /**
556: * Specify whether to cache the object after saving to the db.
557: * This method returns true
558: */
559: protected boolean isCacheOnSave() {
560: return true;
561: }
562:
563: private final SimpleKey[] pks = new SimpleKey[3];
564: private final ComboKey comboPK = new ComboKey(pks);
565:
566: /**
567: * Set the PrimaryKey with an ObjectKey
568: *
569: * @param key
570: */
571: public void setPrimaryKey(ObjectKey key) throws TorqueException {
572: SimpleKey[] keys = (SimpleKey[]) key.getValue();
573: SimpleKey tmpKey = null;
574: setActivityId(new Long(((NumberKey) keys[0]).longValue()));
575: setCreatorId(new Integer(((NumberKey) keys[1]).intValue()));
576: setReceiverId(new Integer(((NumberKey) keys[2]).intValue()));
577: }
578:
579: /**
580: * Set the PrimaryKey using SimpleKeys.
581: *
582: * @param activityId Long
583: * @param creatorId Integer
584: * @param receiverId Integer
585: */
586: public void setPrimaryKey(Long activityId, Integer creatorId,
587: Integer receiverId) throws TorqueException {
588: setActivityId(activityId);
589: setCreatorId(creatorId);
590: setReceiverId(receiverId);
591: }
592:
593: /**
594: * Set the PrimaryKey using a String.
595: */
596: public void setPrimaryKey(String key) throws TorqueException {
597: setPrimaryKey(new ComboKey(key));
598: }
599:
600: /**
601: * returns an id that differentiates this object from others
602: * of its class.
603: */
604: public ObjectKey getPrimaryKey() {
605: pks[0] = SimpleKey.keyFor(getActivityId());
606: pks[1] = SimpleKey.keyFor(getCreatorId());
607: pks[2] = SimpleKey.keyFor(getReceiverId());
608: return comboPK;
609: }
610:
611: /**
612: * get an id that differentiates this object from others
613: * of its class.
614: */
615: public String getQueryKey() {
616: if (getPrimaryKey() == null) {
617: return "";
618: } else {
619: return getPrimaryKey().toString();
620: }
621: }
622:
623: /**
624: * set an id that differentiates this object from others
625: * of its class.
626: */
627: public void setQueryKey(String key) throws TorqueException {
628: setPrimaryKey(key);
629: }
630:
631: /**
632: * Makes a copy of this object.
633: * It creates a new object filling in the simple attributes.
634: * It then fills all the association collections and sets the
635: * related objects to isNew=true.
636: */
637: public NotificationStatus copy() throws TorqueException {
638: return copyInto(new NotificationStatus());
639: }
640:
641: protected NotificationStatus copyInto(NotificationStatus copyObj)
642: throws TorqueException {
643: copyObj.setActivityId(activityId);
644: copyObj.setCreatorId(creatorId);
645: copyObj.setReceiverId(receiverId);
646: copyObj.setStatus(status);
647: copyObj.setCreationDate(creationDate);
648: copyObj.setChangeDate(changeDate);
649: copyObj.setComment(comment);
650:
651: copyObj.setActivityId((Long) null);
652: copyObj.setCreatorId((Integer) null);
653: copyObj.setReceiverId((Integer) null);
654:
655: return copyObj;
656: }
657:
658: /**
659: * returns a peer instance associated with this om. Since Peer classes
660: * are not to have any instance attributes, this method returns the
661: * same instance for all member of this class. The method could therefore
662: * be static, but this would prevent one from overriding the behavior.
663: */
664: public NotificationStatusPeer getPeer() {
665: return peer;
666: }
667:
668: public String toString() {
669: StringBuffer str = new StringBuffer();
670: str.append("NotificationStatus:\n");
671: str.append("ActivityId = ").append(getActivityId())
672: .append("\n");
673: str.append("CreatorId = ").append(getCreatorId()).append("\n");
674: str.append("ReceiverId = ").append(getReceiverId())
675: .append("\n");
676: str.append("Status = ").append(getStatus()).append("\n");
677: str.append("CreationDate = ").append(getCreationDate()).append(
678: "\n");
679: str.append("ChangeDate = ").append(getChangeDate())
680: .append("\n");
681: str.append("Comment = ").append(getComment()).append("\n");
682: return (str.toString());
683: }
684: }
|