KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.tigris.scarab.om;
2
3 /* ================================================================
4  * Copyright (c) 2000-2003 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by CollabNet <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of CollabNet.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of CollabNet.
47  */

48
49 import java.util.List JavaDoc;
50 import org.apache.torque.TorqueException;
51 import org.apache.torque.util.Criteria;
52 import org.apache.torque.om.ObjectKey;
53
54 // Local classes
55
import org.tigris.scarab.services.cache.ScarabCache;
56
57 /**
58  * This is the peer class for an IssueType
59  *
60  * @author <a HREF="mailto:jon@collab.net">Jon S. Stevens</a>
61  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
62  * @version $Id: IssueTypePeer.java 7718 2003-04-22 17:32:08Z jmcnally $
63  */

64 public class IssueTypePeer
65     extends org.tigris.scarab.om.BaseIssueTypePeer
66 {
67     private static final Integer JavaDoc ROOT_KEY = new Integer JavaDoc(0);
68
69     private static final String JavaDoc ISSUE_TYPE_PEER =
70         "IssueTypePeer";
71     private static final String JavaDoc GET_ALL_ISSUE_TYPES =
72         "getAllIssueTypes";
73
74     private static final String JavaDoc RETRIEVE_BY_PK =
75         "retrieveByPK";
76
77     public static Integer JavaDoc getRootKey()
78     {
79         return ROOT_KEY;
80     }
81     
82     /**
83      * Retrieve a single object by pk
84      * FIXME: is this method implementation (with the caching) still done this way? -jss
85      * @param pk
86      */

87     public static IssueType retrieveByPK(ObjectKey pk)
88         throws TorqueException
89     {
90         IssueType result = null;
91         Object JavaDoc obj = ScarabCache.get(ISSUE_TYPE_PEER, RETRIEVE_BY_PK, pk);
92         if (obj == null)
93         {
94             result = BaseIssueTypePeer.retrieveByPK(pk);
95             ScarabCache.put(result, ISSUE_TYPE_PEER, RETRIEVE_BY_PK, pk);
96         }
97         else
98         {
99             result = (IssueType)obj;
100         }
101         return result;
102     }
103
104     /**
105      * Gets a List of all of the Issue types in the database,
106      * That are not template types.
107      */

108     public static List JavaDoc getAllIssueTypes(boolean deleted,
109                        String JavaDoc sortColumn, String JavaDoc sortPolarity)
110         throws Exception JavaDoc
111     {
112         List JavaDoc result = null;
113         Boolean JavaDoc b = deleted ? Boolean.TRUE : Boolean.FALSE;
114         Object JavaDoc obj = ScarabCache.get(ISSUE_TYPE_PEER, GET_ALL_ISSUE_TYPES, b);
115         if (obj == null)
116         {
117             Criteria c = new Criteria();
118             c.add(IssueTypePeer.PARENT_ID, 0);
119             c.add(IssueTypePeer.ISSUE_TYPE_ID, 0, Criteria.NOT_EQUAL);
120             if (deleted)
121             {
122                 c.add(IssueTypePeer.DELETED, 1);
123             }
124             else
125             {
126                 c.add(IssueTypePeer.DELETED, 0);
127             }
128             if (sortColumn != null && sortColumn.equals("desc"))
129             {
130                 addSortOrder(c, IssueTypePeer.DESCRIPTION,
131                              sortPolarity);
132             }
133             else
134             {
135                 // sort on name
136
addSortOrder(c, IssueTypePeer.NAME,
137                              sortPolarity);
138             }
139             result = doSelect(c);
140             ScarabCache.put(result, ISSUE_TYPE_PEER, GET_ALL_ISSUE_TYPES, b);
141         }
142         else
143         {
144             result = (List JavaDoc)obj;
145         }
146         return result;
147     }
148
149     public static List JavaDoc getAllIssueTypes(boolean includeDeleted)
150         throws Exception JavaDoc
151     {
152         return getAllIssueTypes(includeDeleted, "name", "asc");
153     }
154
155     public static List JavaDoc getDefaultIssueTypes()
156         throws Exception JavaDoc
157     {
158         Criteria c = new Criteria();
159         c.add(IssueTypePeer.PARENT_ID, 0);
160         c.add(IssueTypePeer.DELETED, 0);
161         c.add(IssueTypePeer.ISDEFAULT, 1);
162         c.add(IssueTypePeer.ISSUE_TYPE_ID, 0, Criteria.NOT_EQUAL);
163         return IssueTypePeer.doSelect(c);
164     }
165
166     private static Criteria addSortOrder(Criteria crit,
167                     String JavaDoc sortColumn, String JavaDoc sortPolarity)
168     {
169         if (sortPolarity != null && sortPolarity.equals("desc"))
170         {
171             crit.addDescendingOrderByColumn(sortColumn);
172         }
173         else
174         {
175             crit.addAscendingOrderByColumn(sortColumn);
176         }
177         return crit;
178     }
179
180     /**
181      * Checks to see if the name already exists an issue type. if one
182      * does unique will be false unless the given id matches the issue type
183      * that already has the given name.
184      *
185      * @param name a <code>String</code> value
186      * @param id an <code>ObjectKey</code> value
187      * @return a <code>boolean</code> value
188      * @exception Exception if an error occurs
189      */

190     public static boolean isUnique(String JavaDoc name, Integer JavaDoc id)
191         throws Exception JavaDoc
192     {
193         boolean unique = true;
194         name = name.trim();
195         Criteria crit = new Criteria().add(IssueTypePeer.NAME, name);
196         crit.setIgnoreCase(true);
197         List JavaDoc types = IssueTypePeer.doSelect(crit);
198         if (types.size() > 0)
199         {
200             for (int i =0; i<types.size();i++)
201             {
202                 IssueType it = (IssueType)types.get(i);
203                 if ((id == null ||
204                      (id != null && !it.getIssueTypeId().equals(id)))
205                     && it.getName().trim().toLowerCase().equals(name.toLowerCase()))
206                 {
207                     unique = false;
208                 }
209             }
210         }
211         return unique;
212     }
213 }
214
Popular Tags