001: package org.tigris.scarab.om;
002:
003: /* ================================================================
004: * Copyright (c) 2000-2005 CollabNet. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are
008: * met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * 3. The end-user documentation included with the redistribution, if
018: * any, must include the following acknowlegement: "This product includes
019: * software developed by CollabNet <http://www.Collab.Net/>."
020: * Alternately, this acknowlegement may appear in the software itself, if
021: * and wherever such third-party acknowlegements normally appear.
022: *
023: * 4. The hosted project names must not be used to endorse or promote
024: * products derived from this software without prior written
025: * permission. For written permission, please contact info@collab.net.
026: *
027: * 5. Products derived from this software may not use the "Tigris" or
028: * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
029: * prior written permission of CollabNet.
030: *
031: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
032: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
033: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034: * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
035: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
036: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
037: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
038: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
039: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
040: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
041: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
042: *
043: * ====================================================================
044: *
045: * This software consists of voluntary contributions made by many
046: * individuals on behalf of CollabNet.
047: */
048:
049: import java.util.List;
050: import org.apache.torque.TorqueException;
051: import org.apache.torque.util.Criteria;
052: import org.apache.torque.om.ObjectKey;
053:
054: // Local classes
055: import org.tigris.scarab.services.cache.ScarabCache;
056:
057: /**
058: * This is the peer class for an IssueType
059: *
060: * @author <a href="mailto:jon@collab.net">Jon S. Stevens</a>
061: * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
062: * @version $Id: IssueTypePeer.java 9977 2005-12-09 00:40:59Z hair $
063: */
064: public class IssueTypePeer extends BaseIssueTypePeer {
065: private static final Integer ROOT_KEY = new Integer(0);
066:
067: private static final String ISSUE_TYPE_PEER = "IssueTypePeer";
068: private static final String GET_ALL_ISSUE_TYPES = "getAllIssueTypes";
069:
070: private static final String RETRIEVE_BY_PK = "retrieveByPK";
071:
072: public static Integer getRootKey() {
073: return ROOT_KEY;
074: }
075:
076: /**
077: * Retrieve a single object by pk
078: * FIXME: is this method implementation (with the caching) still done this way? -jss
079: * @param pk
080: */
081: public static IssueType retrieveByPK(ObjectKey pk)
082: throws TorqueException {
083: IssueType result = null;
084: Object obj = ScarabCache.get(ISSUE_TYPE_PEER, RETRIEVE_BY_PK,
085: pk);
086: if (obj == null) {
087: result = BaseIssueTypePeer.retrieveByPK(pk);
088: ScarabCache
089: .put(result, ISSUE_TYPE_PEER, RETRIEVE_BY_PK, pk);
090: } else {
091: result = (IssueType) obj;
092: }
093: return result;
094: }
095:
096: /**
097: * Gets a List of all of the Issue types in the database,
098: * That are not template types.
099: */
100: public static List getAllIssueTypes(boolean deleted,
101: String sortColumn, String sortPolarity)
102: throws TorqueException {
103: List result = null;
104: Boolean b = deleted ? Boolean.TRUE : Boolean.FALSE;
105: Object obj = ScarabCache.get(ISSUE_TYPE_PEER,
106: GET_ALL_ISSUE_TYPES, b);
107: if (obj == null) {
108: Criteria c = new Criteria();
109: c.add(IssueTypePeer.PARENT_ID, 0);
110: c.add(IssueTypePeer.ISSUE_TYPE_ID, 0, Criteria.NOT_EQUAL);
111: if (deleted) {
112: c.add(IssueTypePeer.DELETED, 1);
113: } else {
114: c.add(IssueTypePeer.DELETED, 0);
115: }
116: if (sortColumn != null && sortColumn.equals("desc")) {
117: addSortOrder(c, IssueTypePeer.DESCRIPTION, sortPolarity);
118: } else {
119: // sort on name
120: addSortOrder(c, IssueTypePeer.NAME, sortPolarity);
121: }
122: result = doSelect(c);
123: ScarabCache.put(result, ISSUE_TYPE_PEER,
124: GET_ALL_ISSUE_TYPES, b);
125: } else {
126: result = (List) obj;
127: }
128: return result;
129: }
130:
131: public static List getAllIssueTypes(boolean includeDeleted)
132: throws TorqueException {
133: return getAllIssueTypes(includeDeleted, "name", "asc");
134: }
135:
136: public static List getDefaultIssueTypes() throws TorqueException {
137: Criteria c = new Criteria();
138: c.add(IssueTypePeer.PARENT_ID, 0);
139: c.add(IssueTypePeer.DELETED, 0);
140: c.add(IssueTypePeer.ISDEFAULT, 1);
141: c.add(IssueTypePeer.ISSUE_TYPE_ID, 0, Criteria.NOT_EQUAL);
142: return IssueTypePeer.doSelect(c);
143: }
144:
145: private static Criteria addSortOrder(Criteria crit,
146: String sortColumn, String sortPolarity) {
147: if (sortPolarity != null && sortPolarity.equals("desc")) {
148: crit.addDescendingOrderByColumn(sortColumn);
149: } else {
150: crit.addAscendingOrderByColumn(sortColumn);
151: }
152: return crit;
153: }
154:
155: /**
156: * Checks to see if the name already exists an issue type. if one
157: * does unique will be false unless the given id matches the issue type
158: * that already has the given name.
159: *
160: * @param name a <code>String</code> value
161: * @param id an <code>ObjectKey</code> value
162: * @return a <code>boolean</code> value
163: * @exception Exception if an error occurs
164: */
165: public static boolean isUnique(String name, Integer id)
166: throws TorqueException {
167: boolean unique = true;
168: name = name.trim();
169: Criteria crit = new Criteria().add(IssueTypePeer.NAME, name);
170: crit.setIgnoreCase(true);
171: List types = IssueTypePeer.doSelect(crit);
172: if (types.size() > 0) {
173: for (int i = 0; i < types.size(); i++) {
174: IssueType it = (IssueType) types.get(i);
175: if ((id == null || (id != null && !it.getIssueTypeId()
176: .equals(id)))
177: && it.getName().trim().toLowerCase().equals(
178: name.toLowerCase())) {
179: unique = false;
180: }
181: }
182: }
183: return unique;
184: }
185: }
|