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