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 Frequency
027: */
028: public abstract class BaseFrequency extends BaseObject implements
029: org.apache.fulcrum.intake.Retrievable {
030: /** The Peer class */
031: private static final FrequencyPeer peer = new FrequencyPeer();
032:
033: /** The value for the frequencyId field */
034: private Integer frequencyId;
035:
036: /** The value for the name field */
037: private String name;
038:
039: /**
040: * Get the FrequencyId
041: *
042: * @return Integer
043: */
044: public Integer getFrequencyId() {
045: return frequencyId;
046: }
047:
048: /**
049: * Set the value of FrequencyId
050: *
051: * @param v new value
052: */
053: public void setFrequencyId(Integer v) throws TorqueException {
054:
055: if (!ObjectUtils.equals(this .frequencyId, v)) {
056: this .frequencyId = v;
057: setModified(true);
058: }
059:
060: // update associated Query
061: if (collQuerys != null) {
062: for (int i = 0; i < collQuerys.size(); i++) {
063: ((Query) collQuerys.get(i))
064: .setSubscriptionFrequencyId(v);
065: }
066: }
067:
068: // update associated RQueryUser
069: if (collRQueryUsers != null) {
070: for (int i = 0; i < collRQueryUsers.size(); i++) {
071: ((RQueryUser) collRQueryUsers.get(i))
072: .setSubscriptionFrequency(v);
073: }
074: }
075: }
076:
077: /**
078: * Get the Name
079: *
080: * @return String
081: */
082: public String getName() {
083: return name;
084: }
085:
086: /**
087: * Set the value of Name
088: *
089: * @param v new value
090: */
091: public void setName(String v) {
092:
093: if (!ObjectUtils.equals(this .name, v)) {
094: this .name = v;
095: setModified(true);
096: }
097:
098: }
099:
100: /**
101: * Collection to store aggregation of collQuerys
102: */
103: protected List collQuerys;
104:
105: /**
106: * Temporary storage of collQuerys to save a possible db hit in
107: * the event objects are add to the collection, but the
108: * complete collection is never requested.
109: */
110: protected void initQuerys() {
111: if (collQuerys == null) {
112: collQuerys = new ArrayList();
113: }
114: }
115:
116: /**
117: * Method called to associate a Query object to this object
118: * through the Query foreign key attribute
119: *
120: * @param l Query
121: * @throws TorqueException
122: */
123: public void addQuery(Query l) throws TorqueException {
124: getQuerys().add(l);
125: l.setFrequency((Frequency) this );
126: }
127:
128: /**
129: * The criteria used to select the current contents of collQuerys
130: */
131: private Criteria lastQuerysCriteria = null;
132:
133: /**
134: * If this collection has already been initialized, returns
135: * the collection. Otherwise returns the results of
136: * getQuerys(new Criteria())
137: *
138: * @return the collection of associated objects
139: * @throws TorqueException
140: */
141: public List getQuerys() throws TorqueException {
142: if (collQuerys == null) {
143: collQuerys = getQuerys(new Criteria(10));
144: }
145: return collQuerys;
146: }
147:
148: /**
149: * If this collection has already been initialized with
150: * an identical criteria, it returns the collection.
151: * Otherwise if this Frequency has previously
152: * been saved, it will retrieve related Querys from storage.
153: * If this Frequency is new, it will return
154: * an empty collection or the current collection, the criteria
155: * is ignored on a new object.
156: *
157: * @throws TorqueException
158: */
159: public List getQuerys(Criteria criteria) throws TorqueException {
160: if (collQuerys == null) {
161: if (isNew()) {
162: collQuerys = new ArrayList();
163: } else {
164: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
165: getFrequencyId());
166: collQuerys = QueryPeer.doSelect(criteria);
167: }
168: } else {
169: // criteria has no effect for a new object
170: if (!isNew()) {
171: // the following code is to determine if a new query is
172: // called for. If the criteria is the same as the last
173: // one, just return the collection.
174: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
175: getFrequencyId());
176: if (!lastQuerysCriteria.equals(criteria)) {
177: collQuerys = QueryPeer.doSelect(criteria);
178: }
179: }
180: }
181: lastQuerysCriteria = criteria;
182:
183: return collQuerys;
184: }
185:
186: /**
187: * If this collection has already been initialized, returns
188: * the collection. Otherwise returns the results of
189: * getQuerys(new Criteria(),Connection)
190: * This method takes in the Connection also as input so that
191: * referenced objects can also be obtained using a Connection
192: * that is taken as input
193: */
194: public List getQuerys(Connection con) throws TorqueException {
195: if (collQuerys == null) {
196: collQuerys = getQuerys(new Criteria(10), con);
197: }
198: return collQuerys;
199: }
200:
201: /**
202: * If this collection has already been initialized with
203: * an identical criteria, it returns the collection.
204: * Otherwise if this Frequency has previously
205: * been saved, it will retrieve related Querys from storage.
206: * If this Frequency is new, it will return
207: * an empty collection or the current collection, the criteria
208: * is ignored on a new object.
209: * This method takes in the Connection also as input so that
210: * referenced objects can also be obtained using a Connection
211: * that is taken as input
212: */
213: public List getQuerys(Criteria criteria, Connection con)
214: throws TorqueException {
215: if (collQuerys == null) {
216: if (isNew()) {
217: collQuerys = new ArrayList();
218: } else {
219: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
220: getFrequencyId());
221: collQuerys = QueryPeer.doSelect(criteria, con);
222: }
223: } else {
224: // criteria has no effect for a new object
225: if (!isNew()) {
226: // the following code is to determine if a new query is
227: // called for. If the criteria is the same as the last
228: // one, just return the collection.
229: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
230: getFrequencyId());
231: if (!lastQuerysCriteria.equals(criteria)) {
232: collQuerys = QueryPeer.doSelect(criteria, con);
233: }
234: }
235: }
236: lastQuerysCriteria = criteria;
237:
238: return collQuerys;
239: }
240:
241: /**
242: * If this collection has already been initialized with
243: * an identical criteria, it returns the collection.
244: * Otherwise if this Frequency is new, it will return
245: * an empty collection; or if this Frequency has previously
246: * been saved, it will retrieve related Querys from storage.
247: *
248: * This method is protected by default in order to keep the public
249: * api reasonable. You can provide public methods for those you
250: * actually need in Frequency.
251: */
252: protected List getQuerysJoinScarabUserImpl(Criteria criteria)
253: throws TorqueException {
254: if (collQuerys == null) {
255: if (isNew()) {
256: collQuerys = new ArrayList();
257: } else {
258: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
259: getFrequencyId());
260: collQuerys = QueryPeer
261: .doSelectJoinScarabUserImpl(criteria);
262: }
263: } else {
264: // the following code is to determine if a new query is
265: // called for. If the criteria is the same as the last
266: // one, just return the collection.
267: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
268: getFrequencyId());
269: if (!lastQuerysCriteria.equals(criteria)) {
270: collQuerys = QueryPeer
271: .doSelectJoinScarabUserImpl(criteria);
272: }
273: }
274: lastQuerysCriteria = criteria;
275:
276: return collQuerys;
277: }
278:
279: /**
280: * If this collection has already been initialized with
281: * an identical criteria, it returns the collection.
282: * Otherwise if this Frequency is new, it will return
283: * an empty collection; or if this Frequency has previously
284: * been saved, it will retrieve related Querys from storage.
285: *
286: * This method is protected by default in order to keep the public
287: * api reasonable. You can provide public methods for those you
288: * actually need in Frequency.
289: */
290: protected List getQuerysJoinScope(Criteria criteria)
291: throws TorqueException {
292: if (collQuerys == null) {
293: if (isNew()) {
294: collQuerys = new ArrayList();
295: } else {
296: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
297: getFrequencyId());
298: collQuerys = QueryPeer.doSelectJoinScope(criteria);
299: }
300: } else {
301: // the following code is to determine if a new query is
302: // called for. If the criteria is the same as the last
303: // one, just return the collection.
304: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
305: getFrequencyId());
306: if (!lastQuerysCriteria.equals(criteria)) {
307: collQuerys = QueryPeer.doSelectJoinScope(criteria);
308: }
309: }
310: lastQuerysCriteria = criteria;
311:
312: return collQuerys;
313: }
314:
315: /**
316: * If this collection has already been initialized with
317: * an identical criteria, it returns the collection.
318: * Otherwise if this Frequency is new, it will return
319: * an empty collection; or if this Frequency has previously
320: * been saved, it will retrieve related Querys from storage.
321: *
322: * This method is protected by default in order to keep the public
323: * api reasonable. You can provide public methods for those you
324: * actually need in Frequency.
325: */
326: protected List getQuerysJoinScarabModule(Criteria criteria)
327: throws TorqueException {
328: if (collQuerys == null) {
329: if (isNew()) {
330: collQuerys = new ArrayList();
331: } else {
332: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
333: getFrequencyId());
334: collQuerys = QueryPeer
335: .doSelectJoinScarabModule(criteria);
336: }
337: } else {
338: // the following code is to determine if a new query is
339: // called for. If the criteria is the same as the last
340: // one, just return the collection.
341: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
342: getFrequencyId());
343: if (!lastQuerysCriteria.equals(criteria)) {
344: collQuerys = QueryPeer
345: .doSelectJoinScarabModule(criteria);
346: }
347: }
348: lastQuerysCriteria = criteria;
349:
350: return collQuerys;
351: }
352:
353: /**
354: * If this collection has already been initialized with
355: * an identical criteria, it returns the collection.
356: * Otherwise if this Frequency is new, it will return
357: * an empty collection; or if this Frequency has previously
358: * been saved, it will retrieve related Querys from storage.
359: *
360: * This method is protected by default in order to keep the public
361: * api reasonable. You can provide public methods for those you
362: * actually need in Frequency.
363: */
364: protected List getQuerysJoinIssueType(Criteria criteria)
365: throws TorqueException {
366: if (collQuerys == null) {
367: if (isNew()) {
368: collQuerys = new ArrayList();
369: } else {
370: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
371: getFrequencyId());
372: collQuerys = QueryPeer.doSelectJoinIssueType(criteria);
373: }
374: } else {
375: // the following code is to determine if a new query is
376: // called for. If the criteria is the same as the last
377: // one, just return the collection.
378: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
379: getFrequencyId());
380: if (!lastQuerysCriteria.equals(criteria)) {
381: collQuerys = QueryPeer.doSelectJoinIssueType(criteria);
382: }
383: }
384: lastQuerysCriteria = criteria;
385:
386: return collQuerys;
387: }
388:
389: /**
390: * If this collection has already been initialized with
391: * an identical criteria, it returns the collection.
392: * Otherwise if this Frequency is new, it will return
393: * an empty collection; or if this Frequency has previously
394: * been saved, it will retrieve related Querys from storage.
395: *
396: * This method is protected by default in order to keep the public
397: * api reasonable. You can provide public methods for those you
398: * actually need in Frequency.
399: */
400: protected List getQuerysJoinMITList(Criteria criteria)
401: throws TorqueException {
402: if (collQuerys == null) {
403: if (isNew()) {
404: collQuerys = new ArrayList();
405: } else {
406: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
407: getFrequencyId());
408: collQuerys = QueryPeer.doSelectJoinMITList(criteria);
409: }
410: } else {
411: // the following code is to determine if a new query is
412: // called for. If the criteria is the same as the last
413: // one, just return the collection.
414: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
415: getFrequencyId());
416: if (!lastQuerysCriteria.equals(criteria)) {
417: collQuerys = QueryPeer.doSelectJoinMITList(criteria);
418: }
419: }
420: lastQuerysCriteria = criteria;
421:
422: return collQuerys;
423: }
424:
425: /**
426: * If this collection has already been initialized with
427: * an identical criteria, it returns the collection.
428: * Otherwise if this Frequency is new, it will return
429: * an empty collection; or if this Frequency has previously
430: * been saved, it will retrieve related Querys from storage.
431: *
432: * This method is protected by default in order to keep the public
433: * api reasonable. You can provide public methods for those you
434: * actually need in Frequency.
435: */
436: protected List getQuerysJoinFrequency(Criteria criteria)
437: throws TorqueException {
438: if (collQuerys == null) {
439: if (isNew()) {
440: collQuerys = new ArrayList();
441: } else {
442: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
443: getFrequencyId());
444: collQuerys = QueryPeer.doSelectJoinFrequency(criteria);
445: }
446: } else {
447: // the following code is to determine if a new query is
448: // called for. If the criteria is the same as the last
449: // one, just return the collection.
450: criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID,
451: getFrequencyId());
452: if (!lastQuerysCriteria.equals(criteria)) {
453: collQuerys = QueryPeer.doSelectJoinFrequency(criteria);
454: }
455: }
456: lastQuerysCriteria = criteria;
457:
458: return collQuerys;
459: }
460:
461: /**
462: * Collection to store aggregation of collRQueryUsers
463: */
464: protected List collRQueryUsers;
465:
466: /**
467: * Temporary storage of collRQueryUsers to save a possible db hit in
468: * the event objects are add to the collection, but the
469: * complete collection is never requested.
470: */
471: protected void initRQueryUsers() {
472: if (collRQueryUsers == null) {
473: collRQueryUsers = new ArrayList();
474: }
475: }
476:
477: /**
478: * Method called to associate a RQueryUser object to this object
479: * through the RQueryUser foreign key attribute
480: *
481: * @param l RQueryUser
482: * @throws TorqueException
483: */
484: public void addRQueryUser(RQueryUser l) throws TorqueException {
485: getRQueryUsers().add(l);
486: l.setFrequency((Frequency) this );
487: }
488:
489: /**
490: * The criteria used to select the current contents of collRQueryUsers
491: */
492: private Criteria lastRQueryUsersCriteria = null;
493:
494: /**
495: * If this collection has already been initialized, returns
496: * the collection. Otherwise returns the results of
497: * getRQueryUsers(new Criteria())
498: *
499: * @return the collection of associated objects
500: * @throws TorqueException
501: */
502: public List getRQueryUsers() throws TorqueException {
503: if (collRQueryUsers == null) {
504: collRQueryUsers = getRQueryUsers(new Criteria(10));
505: }
506: return collRQueryUsers;
507: }
508:
509: /**
510: * If this collection has already been initialized with
511: * an identical criteria, it returns the collection.
512: * Otherwise if this Frequency has previously
513: * been saved, it will retrieve related RQueryUsers from storage.
514: * If this Frequency is new, it will return
515: * an empty collection or the current collection, the criteria
516: * is ignored on a new object.
517: *
518: * @throws TorqueException
519: */
520: public List getRQueryUsers(Criteria criteria)
521: throws TorqueException {
522: if (collRQueryUsers == null) {
523: if (isNew()) {
524: collRQueryUsers = new ArrayList();
525: } else {
526: criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID,
527: getFrequencyId());
528: collRQueryUsers = RQueryUserPeer.doSelect(criteria);
529: }
530: } else {
531: // criteria has no effect for a new object
532: if (!isNew()) {
533: // the following code is to determine if a new query is
534: // called for. If the criteria is the same as the last
535: // one, just return the collection.
536: criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID,
537: getFrequencyId());
538: if (!lastRQueryUsersCriteria.equals(criteria)) {
539: collRQueryUsers = RQueryUserPeer.doSelect(criteria);
540: }
541: }
542: }
543: lastRQueryUsersCriteria = criteria;
544:
545: return collRQueryUsers;
546: }
547:
548: /**
549: * If this collection has already been initialized, returns
550: * the collection. Otherwise returns the results of
551: * getRQueryUsers(new Criteria(),Connection)
552: * This method takes in the Connection also as input so that
553: * referenced objects can also be obtained using a Connection
554: * that is taken as input
555: */
556: public List getRQueryUsers(Connection con) throws TorqueException {
557: if (collRQueryUsers == null) {
558: collRQueryUsers = getRQueryUsers(new Criteria(10), con);
559: }
560: return collRQueryUsers;
561: }
562:
563: /**
564: * If this collection has already been initialized with
565: * an identical criteria, it returns the collection.
566: * Otherwise if this Frequency has previously
567: * been saved, it will retrieve related RQueryUsers from storage.
568: * If this Frequency is new, it will return
569: * an empty collection or the current collection, the criteria
570: * is ignored on a new object.
571: * This method takes in the Connection also as input so that
572: * referenced objects can also be obtained using a Connection
573: * that is taken as input
574: */
575: public List getRQueryUsers(Criteria criteria, Connection con)
576: throws TorqueException {
577: if (collRQueryUsers == null) {
578: if (isNew()) {
579: collRQueryUsers = new ArrayList();
580: } else {
581: criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID,
582: getFrequencyId());
583: collRQueryUsers = RQueryUserPeer
584: .doSelect(criteria, con);
585: }
586: } else {
587: // criteria has no effect for a new object
588: if (!isNew()) {
589: // the following code is to determine if a new query is
590: // called for. If the criteria is the same as the last
591: // one, just return the collection.
592: criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID,
593: getFrequencyId());
594: if (!lastRQueryUsersCriteria.equals(criteria)) {
595: collRQueryUsers = RQueryUserPeer.doSelect(criteria,
596: con);
597: }
598: }
599: }
600: lastRQueryUsersCriteria = criteria;
601:
602: return collRQueryUsers;
603: }
604:
605: /**
606: * If this collection has already been initialized with
607: * an identical criteria, it returns the collection.
608: * Otherwise if this Frequency is new, it will return
609: * an empty collection; or if this Frequency has previously
610: * been saved, it will retrieve related RQueryUsers from storage.
611: *
612: * This method is protected by default in order to keep the public
613: * api reasonable. You can provide public methods for those you
614: * actually need in Frequency.
615: */
616: protected List getRQueryUsersJoinQuery(Criteria criteria)
617: throws TorqueException {
618: if (collRQueryUsers == null) {
619: if (isNew()) {
620: collRQueryUsers = new ArrayList();
621: } else {
622: criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID,
623: getFrequencyId());
624: collRQueryUsers = RQueryUserPeer
625: .doSelectJoinQuery(criteria);
626: }
627: } else {
628: // the following code is to determine if a new query is
629: // called for. If the criteria is the same as the last
630: // one, just return the collection.
631: criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID,
632: getFrequencyId());
633: if (!lastRQueryUsersCriteria.equals(criteria)) {
634: collRQueryUsers = RQueryUserPeer
635: .doSelectJoinQuery(criteria);
636: }
637: }
638: lastRQueryUsersCriteria = criteria;
639:
640: return collRQueryUsers;
641: }
642:
643: /**
644: * If this collection has already been initialized with
645: * an identical criteria, it returns the collection.
646: * Otherwise if this Frequency is new, it will return
647: * an empty collection; or if this Frequency has previously
648: * been saved, it will retrieve related RQueryUsers from storage.
649: *
650: * This method is protected by default in order to keep the public
651: * api reasonable. You can provide public methods for those you
652: * actually need in Frequency.
653: */
654: protected List getRQueryUsersJoinScarabUserImpl(Criteria criteria)
655: throws TorqueException {
656: if (collRQueryUsers == null) {
657: if (isNew()) {
658: collRQueryUsers = new ArrayList();
659: } else {
660: criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID,
661: getFrequencyId());
662: collRQueryUsers = RQueryUserPeer
663: .doSelectJoinScarabUserImpl(criteria);
664: }
665: } else {
666: // the following code is to determine if a new query is
667: // called for. If the criteria is the same as the last
668: // one, just return the collection.
669: criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID,
670: getFrequencyId());
671: if (!lastRQueryUsersCriteria.equals(criteria)) {
672: collRQueryUsers = RQueryUserPeer
673: .doSelectJoinScarabUserImpl(criteria);
674: }
675: }
676: lastRQueryUsersCriteria = criteria;
677:
678: return collRQueryUsers;
679: }
680:
681: /**
682: * If this collection has already been initialized with
683: * an identical criteria, it returns the collection.
684: * Otherwise if this Frequency is new, it will return
685: * an empty collection; or if this Frequency has previously
686: * been saved, it will retrieve related RQueryUsers from storage.
687: *
688: * This method is protected by default in order to keep the public
689: * api reasonable. You can provide public methods for those you
690: * actually need in Frequency.
691: */
692: protected List getRQueryUsersJoinFrequency(Criteria criteria)
693: throws TorqueException {
694: if (collRQueryUsers == null) {
695: if (isNew()) {
696: collRQueryUsers = new ArrayList();
697: } else {
698: criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID,
699: getFrequencyId());
700: collRQueryUsers = RQueryUserPeer
701: .doSelectJoinFrequency(criteria);
702: }
703: } else {
704: // the following code is to determine if a new query is
705: // called for. If the criteria is the same as the last
706: // one, just return the collection.
707: criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID,
708: getFrequencyId());
709: if (!lastRQueryUsersCriteria.equals(criteria)) {
710: collRQueryUsers = RQueryUserPeer
711: .doSelectJoinFrequency(criteria);
712: }
713: }
714: lastRQueryUsersCriteria = criteria;
715:
716: return collRQueryUsers;
717: }
718:
719: private static List fieldNames = null;
720:
721: /**
722: * Generate a list of field names.
723: *
724: * @return a list of field names
725: */
726: public static synchronized List getFieldNames() {
727: if (fieldNames == null) {
728: fieldNames = new ArrayList();
729: fieldNames.add("FrequencyId");
730: fieldNames.add("Name");
731: fieldNames = Collections.unmodifiableList(fieldNames);
732: }
733: return fieldNames;
734: }
735:
736: /**
737: * Retrieves a field from the object by name passed in as a String.
738: *
739: * @param name field name
740: * @return value
741: */
742: public Object getByName(String name) {
743: if (name.equals("FrequencyId")) {
744: return getFrequencyId();
745: }
746: if (name.equals("Name")) {
747: return getName();
748: }
749: return null;
750: }
751:
752: /**
753: * Retrieves a field from the object by name passed in
754: * as a String. The String must be one of the static
755: * Strings defined in this Class' Peer.
756: *
757: * @param name peer name
758: * @return value
759: */
760: public Object getByPeerName(String name) {
761: if (name.equals(FrequencyPeer.FREQUENCY_ID)) {
762: return getFrequencyId();
763: }
764: if (name.equals(FrequencyPeer.FREQUENCY_NAME)) {
765: return getName();
766: }
767: return null;
768: }
769:
770: /**
771: * Retrieves a field from the object by Position as specified
772: * in the xml schema. Zero-based.
773: *
774: * @param pos position in xml schema
775: * @return value
776: */
777: public Object getByPosition(int pos) {
778: if (pos == 0) {
779: return getFrequencyId();
780: }
781: if (pos == 1) {
782: return getName();
783: }
784: return null;
785: }
786:
787: /**
788: * Stores the object in the database. If the object is new,
789: * it inserts it; otherwise an update is performed.
790: *
791: * @throws TorqueException
792: */
793: public void save() throws TorqueException {
794: save(FrequencyPeer.getMapBuilder().getDatabaseMap().getName());
795: }
796:
797: /**
798: * Stores the object in the database. If the object is new,
799: * it inserts it; otherwise an update is performed.
800: * Note: this code is here because the method body is
801: * auto-generated conditionally and therefore needs to be
802: * in this file instead of in the super class, BaseObject.
803: *
804: * @param dbName
805: * @throws TorqueException
806: */
807: public void save(String dbName) throws TorqueException {
808: Connection con = null;
809: try {
810: con = Transaction.begin(dbName);
811: save(con);
812: Transaction.commit(con);
813: } catch (TorqueException e) {
814: Transaction.safeRollback(con);
815: throw e;
816: }
817: }
818:
819: /** flag to prevent endless save loop, if this object is referenced
820: by another object which falls in this transaction. */
821: private boolean alreadyInSave = false;
822:
823: /**
824: * Stores the object in the database. If the object is new,
825: * it inserts it; otherwise an update is performed. This method
826: * is meant to be used as part of a transaction, otherwise use
827: * the save() method and the connection details will be handled
828: * internally
829: *
830: * @param con
831: * @throws TorqueException
832: */
833: public void save(Connection con) throws TorqueException {
834: if (!alreadyInSave) {
835: alreadyInSave = true;
836:
837: // If this object has been modified, then save it to the database.
838: if (isModified()) {
839: if (isNew()) {
840: FrequencyPeer.doInsert((Frequency) this , con);
841: setNew(false);
842: } else {
843: FrequencyPeer.doUpdate((Frequency) this , con);
844: }
845:
846: if (isCacheOnSave()) {
847: FrequencyManager.putInstance(this );
848: }
849: }
850:
851: if (collQuerys != null) {
852: for (int i = 0; i < collQuerys.size(); i++) {
853: ((Query) collQuerys.get(i)).save(con);
854: }
855: }
856:
857: if (collRQueryUsers != null) {
858: for (int i = 0; i < collRQueryUsers.size(); i++) {
859: ((RQueryUser) collRQueryUsers.get(i)).save(con);
860: }
861: }
862: alreadyInSave = false;
863: }
864: }
865:
866: /**
867: * Specify whether to cache the object after saving to the db.
868: * This method returns true
869: */
870: protected boolean isCacheOnSave() {
871: return true;
872: }
873:
874: /**
875: * Set the PrimaryKey using ObjectKey.
876: *
877: * @param key frequencyId ObjectKey
878: */
879: public void setPrimaryKey(ObjectKey key) throws TorqueException {
880: setFrequencyId(new Integer(((NumberKey) key).intValue()));
881: }
882:
883: /**
884: * Set the PrimaryKey using a String.
885: *
886: * @param key
887: */
888: public void setPrimaryKey(String key) throws TorqueException {
889: setFrequencyId(new Integer(key));
890: }
891:
892: /**
893: * returns an id that differentiates this object from others
894: * of its class.
895: */
896: public ObjectKey getPrimaryKey() {
897: return SimpleKey.keyFor(getFrequencyId());
898: }
899:
900: /**
901: * get an id that differentiates this object from others
902: * of its class.
903: */
904: public String getQueryKey() {
905: if (getPrimaryKey() == null) {
906: return "";
907: } else {
908: return getPrimaryKey().toString();
909: }
910: }
911:
912: /**
913: * set an id that differentiates this object from others
914: * of its class.
915: */
916: public void setQueryKey(String key) throws TorqueException {
917: setPrimaryKey(key);
918: }
919:
920: /**
921: * Makes a copy of this object.
922: * It creates a new object filling in the simple attributes.
923: * It then fills all the association collections and sets the
924: * related objects to isNew=true.
925: */
926: public Frequency copy() throws TorqueException {
927: return copyInto(new Frequency());
928: }
929:
930: protected Frequency copyInto(Frequency copyObj)
931: throws TorqueException {
932: copyObj.setFrequencyId(frequencyId);
933: copyObj.setName(name);
934:
935: copyObj.setFrequencyId((Integer) null);
936:
937: List v = getQuerys();
938: if (v != null) {
939: for (int i = 0; i < v.size(); i++) {
940: Query obj = (Query) v.get(i);
941: copyObj.addQuery(obj.copy());
942: }
943: } else {
944: copyObj.collQuerys = null;
945: }
946:
947: v = getRQueryUsers();
948: if (v != null) {
949: for (int i = 0; i < v.size(); i++) {
950: RQueryUser obj = (RQueryUser) v.get(i);
951: copyObj.addRQueryUser(obj.copy());
952: }
953: } else {
954: copyObj.collRQueryUsers = null;
955: }
956: return copyObj;
957: }
958:
959: /**
960: * returns a peer instance associated with this om. Since Peer classes
961: * are not to have any instance attributes, this method returns the
962: * same instance for all member of this class. The method could therefore
963: * be static, but this would prevent one from overriding the behavior.
964: */
965: public FrequencyPeer getPeer() {
966: return peer;
967: }
968:
969: public String toString() {
970: StringBuffer str = new StringBuffer();
971: str.append("Frequency:\n");
972: str.append("FrequencyId = ").append(getFrequencyId()).append(
973: "\n");
974: str.append("Name = ").append(getName()).append("\n");
975: return (str.toString());
976: }
977: }
|