KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > ReportPeer


1 package org.tigris.scarab.om;
2
3 import java.util.List JavaDoc;
4
5 // Turbine classes
6
import org.apache.torque.TorqueException;
7 import org.apache.torque.om.ObjectKey;
8 import org.apache.torque.util.Criteria;
9
10 // Scarab classes
11
import org.tigris.scarab.services.cache.ScarabCache;
12 import org.tigris.scarab.tools.localization.L10NKeySet;
13 import org.tigris.scarab.util.ScarabException;
14
15
16 /**
17  * You should add additional methods to this class to meet the
18  * application requirements. This class will only be generated as
19  * long as it does not already exist in the output directory.
20  */

21 public class ReportPeer
22     extends org.tigris.scarab.om.BaseReportPeer
23 {
24     private static final String JavaDoc REPORT_PEER =
25         "ReportPeer";
26     private static final String JavaDoc RETRIEVE_BY_PK =
27         "retrieveByPK";
28
29     /**
30      * Does a saved report exist under the given name.
31      *
32      * @param name a <code>String</code> report name
33      * @return true if a report by the given name exists
34      */

35     public static boolean exists(String JavaDoc name)
36         throws Exception JavaDoc
37     {
38         return retrieveByName(name) != null;
39     }
40
41     /**
42      * gets the active report saved under the given name
43      *
44      * @param name a <code>String</code> value
45      * @return a <code>Report</code> value
46      * @exception Exception if an error occurs
47      */

48     public static Report retrieveByName(String JavaDoc name)
49         throws Exception JavaDoc
50     {
51         Report report = null;
52         Criteria crit = new Criteria()
53             .add(NAME, name)
54             .add(DELETED, false);
55         List JavaDoc reports = doSelect(crit);
56         if (reports.size() == 1)
57         {
58             report = (Report)reports.get(0);
59         }
60         else if (reports.size() > 1)
61         {
62             throw new ScarabException(L10NKeySet.ExceptionMultipleReports,
63                                       name);
64         }
65         
66         return report;
67     }
68
69     /**
70      * Retrieve a single object by pk
71      *
72      * @param pk
73      */

74     public static Report retrieveByPK(ObjectKey pk)
75         throws TorqueException
76     {
77         Report result = null;
78         Object JavaDoc obj = ScarabCache.get(REPORT_PEER, RETRIEVE_BY_PK, pk);
79         if (obj == null)
80         {
81             result = BaseReportPeer.retrieveByPK(pk);
82             ScarabCache.put(result, REPORT_PEER, RETRIEVE_BY_PK, pk);
83         }
84         else
85         {
86             result = (Report)obj;
87         }
88         return result;
89     }
90 }
91
Popular Tags