1 package org.tigris.scarab.om; 2 3 48 49 import java.util.List ; 50 import org.apache.torque.TorqueException; 51 import org.apache.torque.util.Criteria; 52 import org.apache.torque.om.ObjectKey; 53 54 import org.tigris.scarab.services.cache.ScarabCache; 56 57 64 public class IssueTypePeer 65 extends org.tigris.scarab.om.BaseIssueTypePeer 66 { 67 private static final Integer ROOT_KEY = new Integer (0); 68 69 private static final String ISSUE_TYPE_PEER = 70 "IssueTypePeer"; 71 private static final String GET_ALL_ISSUE_TYPES = 72 "getAllIssueTypes"; 73 74 private static final String RETRIEVE_BY_PK = 75 "retrieveByPK"; 76 77 public static Integer getRootKey() 78 { 79 return ROOT_KEY; 80 } 81 82 87 public static IssueType retrieveByPK(ObjectKey pk) 88 throws TorqueException 89 { 90 IssueType result = null; 91 Object 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 108 public static List getAllIssueTypes(boolean deleted, 109 String sortColumn, String sortPolarity) 110 throws Exception 111 { 112 List result = null; 113 Boolean b = deleted ? Boolean.TRUE : Boolean.FALSE; 114 Object 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 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 )obj; 145 } 146 return result; 147 } 148 149 public static List getAllIssueTypes(boolean includeDeleted) 150 throws Exception 151 { 152 return getAllIssueTypes(includeDeleted, "name", "asc"); 153 } 154 155 public static List getDefaultIssueTypes() 156 throws Exception 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 sortColumn, String 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 190 public static boolean isUnique(String name, Integer id) 191 throws Exception 192 { 193 boolean unique = true; 194 name = name.trim(); 195 Criteria crit = new Criteria().add(IssueTypePeer.NAME, name); 196 crit.setIgnoreCase(true); 197 List 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 |