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