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