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 NotificationFilter
027: */
028: public abstract class BaseNotificationFilter extends BaseObject
029: implements org.apache.fulcrum.intake.Retrievable {
030: /** The Peer class */
031: private static final NotificationFilterPeer peer = new NotificationFilterPeer();
032:
033: /** The value for the moduleId field */
034: private Integer moduleId;
035:
036: /** The value for the userId field */
037: private Integer userId;
038:
039: /** The value for the activityType field */
040: private String activityType;
041:
042: /** The value for the managerId field */
043: private Integer managerId = new Integer(0);
044:
045: /** The value for the filterState field */
046: private boolean filterState = false;
047:
048: /** The value for the sendSelf field */
049: private boolean sendSelf = false;
050:
051: /** The value for the sendFailures field */
052: private boolean sendFailures = false;
053:
054: /**
055: * Get the ModuleId
056: *
057: * @return Integer
058: */
059: public Integer getModuleId() {
060: return moduleId;
061: }
062:
063: /**
064: * Set the value of ModuleId
065: *
066: * @param v new value
067: */
068: public void setModuleId(Integer v) throws TorqueException {
069:
070: if (!ObjectUtils.equals(this .moduleId, v)) {
071: this .moduleId = v;
072: setModified(true);
073: }
074:
075: if (aModule != null
076: && !ObjectUtils.equals(aModule.getModuleId(), v)) {
077: aModule = null;
078: }
079:
080: }
081:
082: /**
083: * Get the UserId
084: *
085: * @return Integer
086: */
087: public Integer getUserId() {
088: return userId;
089: }
090:
091: /**
092: * Set the value of UserId
093: *
094: * @param v new value
095: */
096: public void setUserId(Integer v) throws TorqueException {
097:
098: if (!ObjectUtils.equals(this .userId, v)) {
099: this .userId = 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 ActivityType
112: *
113: * @return String
114: */
115: public String getActivityType() {
116: return activityType;
117: }
118:
119: /**
120: * Set the value of ActivityType
121: *
122: * @param v new value
123: */
124: public void setActivityType(String v) {
125:
126: if (!ObjectUtils.equals(this .activityType, v)) {
127: this .activityType = v;
128: setModified(true);
129: }
130:
131: }
132:
133: /**
134: * Get the ManagerId
135: *
136: * @return Integer
137: */
138: public Integer getManagerId() {
139: return managerId;
140: }
141:
142: /**
143: * Set the value of ManagerId
144: *
145: * @param v new value
146: */
147: public void setManagerId(Integer v) {
148:
149: if (!ObjectUtils.equals(this .managerId, v)) {
150: this .managerId = v;
151: setModified(true);
152: }
153:
154: }
155:
156: /**
157: * Get the FilterState
158: *
159: * @return boolean
160: */
161: public boolean getFilterState() {
162: return filterState;
163: }
164:
165: /**
166: * Set the value of FilterState
167: *
168: * @param v new value
169: */
170: public void setFilterState(boolean v) {
171:
172: if (this .filterState != v) {
173: this .filterState = v;
174: setModified(true);
175: }
176:
177: }
178:
179: /**
180: * Get the SendSelf
181: *
182: * @return boolean
183: */
184: public boolean getSendSelf() {
185: return sendSelf;
186: }
187:
188: /**
189: * Set the value of SendSelf
190: *
191: * @param v new value
192: */
193: public void setSendSelf(boolean v) {
194:
195: if (this .sendSelf != v) {
196: this .sendSelf = v;
197: setModified(true);
198: }
199:
200: }
201:
202: /**
203: * Get the SendFailures
204: *
205: * @return boolean
206: */
207: public boolean getSendFailures() {
208: return sendFailures;
209: }
210:
211: /**
212: * Set the value of SendFailures
213: *
214: * @param v new value
215: */
216: public void setSendFailures(boolean v) {
217:
218: if (this .sendFailures != v) {
219: this .sendFailures = 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: setUserId((Integer) null);
236: } else {
237: setUserId(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 .userId, null))) {
253: aScarabUser = ScarabUserManager.getInstance(SimpleKey
254: .keyFor(this .userId));
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 .userId, null))) {
273: aScarabUser = ScarabUserManager.getCachedInstance(SimpleKey
274: .keyFor(this .userId));
275: if (aScarabUser == null) {
276: aScarabUser = ScarabUserImplPeer
277: .retrieveScarabUserImplByPK(SimpleKey
278: .keyFor(this .userId), 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: setUserId(new Integer(((NumberKey) key).intValue()));
294: }
295:
296: private Module aModule;
297:
298: /**
299: * Declares an association between this object and a Module object
300: *
301: * @param v Module
302: * @throws TorqueException
303: */
304: public void setModule(Module v) throws TorqueException {
305: if (v == null) {
306: setModuleId((Integer) null);
307: } else {
308: setModuleId(v.getModuleId());
309: }
310: aModule = v;
311: }
312:
313: /**
314: * Returns the associated Module object.
315: * If it was not retrieved before, the object is retrieved from
316: * the database
317: *
318: * @return the associated Module object
319: * @throws TorqueException
320: */
321: public Module getModule() throws TorqueException {
322: if (aModule == null
323: && (!ObjectUtils.equals(this .moduleId, null))) {
324: aModule = ModuleManager.getInstance(SimpleKey
325: .keyFor(this .moduleId));
326: }
327: return aModule;
328: }
329:
330: /**
331: * Return the associated Module 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 Module object
338: * @throws TorqueException
339: */
340: public Module getModule(Connection connection)
341: throws TorqueException {
342: if (aModule == null
343: && (!ObjectUtils.equals(this .moduleId, null))) {
344: aModule = ModuleManager.getCachedInstance(SimpleKey
345: .keyFor(this .moduleId));
346: if (aModule == null) {
347: aModule = ScarabModulePeer.retrieveByPK(SimpleKey
348: .keyFor(this .moduleId), connection);
349: ModuleManager.putInstance(aModule);
350: }
351: }
352: return aModule;
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 setModuleKey(ObjectKey key) throws TorqueException {
362:
363: setModuleId(new Integer(((NumberKey) key).intValue()));
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("ModuleId");
377: fieldNames.add("UserId");
378: fieldNames.add("ActivityType");
379: fieldNames.add("ManagerId");
380: fieldNames.add("FilterState");
381: fieldNames.add("SendSelf");
382: fieldNames.add("SendFailures");
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("ModuleId")) {
396: return getModuleId();
397: }
398: if (name.equals("UserId")) {
399: return getUserId();
400: }
401: if (name.equals("ActivityType")) {
402: return getActivityType();
403: }
404: if (name.equals("ManagerId")) {
405: return getManagerId();
406: }
407: if (name.equals("FilterState")) {
408: return Boolean.valueOf(getFilterState());
409: }
410: if (name.equals("SendSelf")) {
411: return Boolean.valueOf(getSendSelf());
412: }
413: if (name.equals("SendFailures")) {
414: return Boolean.valueOf(getSendFailures());
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(NotificationFilterPeer.MODULE_ID)) {
429: return getModuleId();
430: }
431: if (name.equals(NotificationFilterPeer.USER_ID)) {
432: return getUserId();
433: }
434: if (name.equals(NotificationFilterPeer.ACTIVITY_TYPE)) {
435: return getActivityType();
436: }
437: if (name.equals(NotificationFilterPeer.MANAGER_ID)) {
438: return getManagerId();
439: }
440: if (name.equals(NotificationFilterPeer.FILTER_STATE)) {
441: return Boolean.valueOf(getFilterState());
442: }
443: if (name.equals(NotificationFilterPeer.SEND_SELF)) {
444: return Boolean.valueOf(getSendSelf());
445: }
446: if (name.equals(NotificationFilterPeer.SEND_FAILURES)) {
447: return Boolean.valueOf(getSendFailures());
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 getModuleId();
462: }
463: if (pos == 1) {
464: return getUserId();
465: }
466: if (pos == 2) {
467: return getActivityType();
468: }
469: if (pos == 3) {
470: return getManagerId();
471: }
472: if (pos == 4) {
473: return Boolean.valueOf(getFilterState());
474: }
475: if (pos == 5) {
476: return Boolean.valueOf(getSendSelf());
477: }
478: if (pos == 6) {
479: return Boolean.valueOf(getSendFailures());
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(NotificationFilterPeer.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: NotificationFilterPeer.doInsert(
539: (NotificationFilter) this , con);
540: setNew(false);
541: } else {
542: NotificationFilterPeer.doUpdate(
543: (NotificationFilter) this , con);
544: }
545:
546: if (isCacheOnSave()) {
547: NotificationFilterManager.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[4];
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: setModuleId(new Integer(((NumberKey) keys[0]).intValue()));
575: setUserId(new Integer(((NumberKey) keys[1]).intValue()));
576: setActivityType(keys[2].toString());
577: setManagerId(new Integer(((NumberKey) keys[3]).intValue()));
578: }
579:
580: /**
581: * Set the PrimaryKey using SimpleKeys.
582: *
583: * @param moduleId Integer
584: * @param userId Integer
585: * @param activityType String
586: * @param managerId Integer
587: */
588: public void setPrimaryKey(Integer moduleId, Integer userId,
589: String activityType, Integer managerId)
590: throws TorqueException {
591: setModuleId(moduleId);
592: setUserId(userId);
593: setActivityType(activityType);
594: setManagerId(managerId);
595: }
596:
597: /**
598: * Set the PrimaryKey using a String.
599: */
600: public void setPrimaryKey(String key) throws TorqueException {
601: setPrimaryKey(new ComboKey(key));
602: }
603:
604: /**
605: * returns an id that differentiates this object from others
606: * of its class.
607: */
608: public ObjectKey getPrimaryKey() {
609: pks[0] = SimpleKey.keyFor(getModuleId());
610: pks[1] = SimpleKey.keyFor(getUserId());
611: pks[2] = SimpleKey.keyFor(getActivityType());
612: pks[3] = SimpleKey.keyFor(getManagerId());
613: return comboPK;
614: }
615:
616: /**
617: * get an id that differentiates this object from others
618: * of its class.
619: */
620: public String getQueryKey() {
621: if (getPrimaryKey() == null) {
622: return "";
623: } else {
624: return getPrimaryKey().toString();
625: }
626: }
627:
628: /**
629: * set an id that differentiates this object from others
630: * of its class.
631: */
632: public void setQueryKey(String key) throws TorqueException {
633: setPrimaryKey(key);
634: }
635:
636: /**
637: * Makes a copy of this object.
638: * It creates a new object filling in the simple attributes.
639: * It then fills all the association collections and sets the
640: * related objects to isNew=true.
641: */
642: public NotificationFilter copy() throws TorqueException {
643: return copyInto(new NotificationFilter());
644: }
645:
646: protected NotificationFilter copyInto(NotificationFilter copyObj)
647: throws TorqueException {
648: copyObj.setModuleId(moduleId);
649: copyObj.setUserId(userId);
650: copyObj.setActivityType(activityType);
651: copyObj.setManagerId(managerId);
652: copyObj.setFilterState(filterState);
653: copyObj.setSendSelf(sendSelf);
654: copyObj.setSendFailures(sendFailures);
655:
656: copyObj.setModuleId((Integer) null);
657: copyObj.setUserId((Integer) null);
658: copyObj.setActivityType((String) null);
659: copyObj.setManagerId((Integer) null);
660:
661: return copyObj;
662: }
663:
664: /**
665: * returns a peer instance associated with this om. Since Peer classes
666: * are not to have any instance attributes, this method returns the
667: * same instance for all member of this class. The method could therefore
668: * be static, but this would prevent one from overriding the behavior.
669: */
670: public NotificationFilterPeer getPeer() {
671: return peer;
672: }
673:
674: public String toString() {
675: StringBuffer str = new StringBuffer();
676: str.append("NotificationFilter:\n");
677: str.append("ModuleId = ").append(getModuleId()).append("\n");
678: str.append("UserId = ").append(getUserId()).append("\n");
679: str.append("ActivityType = ").append(getActivityType()).append(
680: "\n");
681: str.append("ManagerId = ").append(getManagerId()).append("\n");
682: str.append("FilterState = ").append(getFilterState()).append(
683: "\n");
684: str.append("SendSelf = ").append(getSendSelf()).append("\n");
685: str.append("SendFailures = ").append(getSendFailures()).append(
686: "\n");
687: return (str.toString());
688: }
689: }
|