001: // ================================================================
002: // Copyright (c) 2000-2005 CollabNet. All rights reserved.
003: //
004: // Redistribution and use in source and binary forms, with or without
005: // modification, are permitted provided that the following conditions are
006: // met:
007: //
008: // 1. Redistributions of source code must retain the above copyright
009: // notice, this list of conditions and the following disclaimer.
010: //
011: // 2. Redistributions in binary form must reproduce the above copyright
012: // notice, this list of conditions and the following disclaimer in the
013: // documentation and/or other materials provided with the distribution.
014: //
015: // 3. The end-user documentation included with the redistribution, if
016: // any, must include the following acknowlegement: "This product includes
017: // software developed by Collab.Net <http://www.Collab.Net/>."
018: // Alternately, this acknowlegement may appear in the software itself, if
019: // and wherever such third-party acknowlegements normally appear.
020: //
021: // 4. The hosted project names must not be used to endorse or promote
022: // products derived from this software without prior written
023: // permission. For written permission, please contact info@collab.net.
024: //
025: // 5. Products derived from this software may not use the "Tigris" or
026: // "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
027: // prior written permission of Collab.Net.
028: //
029: // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
030: // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
031: // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
032: // IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
033: // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
034: // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
035: // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
036: // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
037: // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
038: // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
039: // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
040: //
041: // ====================================================================
042: //
043: // This software consists of voluntary contributions made by many
044: // individuals on behalf of Collab.Net.
045: package org.tigris.scarab.om;
046:
047: import java.util.List;
048:
049: // Turbine classes
050: import org.apache.torque.TorqueException;
051: import org.apache.torque.om.ObjectKey;
052: import org.apache.torque.util.Criteria;
053:
054: // Scarab classes
055: import org.tigris.scarab.services.cache.ScarabCache;
056: import org.tigris.scarab.tools.localization.L10NKeySet;
057: import org.tigris.scarab.util.ScarabException;
058:
059: /**
060: * You should add additional methods to this class to meet the
061: * application requirements. This class will only be generated as
062: * long as it does not already exist in the output directory.
063: */
064: public class ReportPeer extends BaseReportPeer {
065: private static final String REPORT_PEER = "ReportPeer";
066: private static final String RETRIEVE_BY_PK = "retrieveByPK";
067:
068: /**
069: * Does a saved report exist under the given name.
070: *
071: * @param name a <code>String</code> report name
072: * @return true if a report by the given name exists
073: */
074: public static boolean exists(final String name)
075: throws TorqueException, ScarabException {
076: return retrieveByName(name) != null;
077: }
078:
079: /**
080: * gets the active report saved under the given name
081: *
082: * @param name a <code>String</code> value
083: * @return a <code>Report</code> value
084: * @exception Exception if an error occurs
085: */
086: public static Report retrieveByName(final String name)
087: throws TorqueException, ScarabException {
088: Report report = null;
089: final Criteria crit = new Criteria().add(NAME, name).add(
090: DELETED, false);
091: final List reports = doSelect(crit);
092: if (reports.size() == 1) {
093: report = (Report) reports.get(0);
094: } else if (reports.size() > 1) {
095: throw new ScarabException(
096: L10NKeySet.ExceptionMultipleReports, name);
097: }
098:
099: return report;
100: }
101:
102: /**
103: * Retrieve a single object by pk
104: *
105: * @param pk
106: */
107: public static Report retrieveByPK(ObjectKey pk)
108: throws TorqueException {
109: Report result = null;
110: Object obj = ScarabCache.get(REPORT_PEER, RETRIEVE_BY_PK, pk);
111: if (obj == null) {
112: result = BaseReportPeer.retrieveByPK(pk);
113: ScarabCache.put(result, REPORT_PEER, RETRIEVE_BY_PK, pk);
114: } else {
115: result = (Report) obj;
116: }
117: return result;
118: }
119: }
|