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