1 package org.tigris.scarab.om; 2 3 48 49 import java.io.Serializable ; 50 import java.util.List ; 51 import java.util.LinkedList ; 52 53 import org.apache.torque.TorqueException; 54 import org.apache.torque.om.Persistent; 55 import org.apache.torque.manager.CacheListener; 56 import org.apache.torque.util.Criteria; 57 import org.tigris.scarab.util.Log; 58 59 65 public class IssueManager 66 extends BaseIssueManager 67 implements CacheListener 68 { 69 private static final String ISSUE = 70 "Issue"; 71 protected static final String GET_ISSUE_BY_ID = 72 "getIssueById"; 73 74 79 public IssueManager() 80 throws TorqueException 81 { 82 super(); 83 setRegion(getClassName().replace('.', '_')); 84 } 85 86 91 public static Issue getIssueById(String id, String defaultCode) 92 { 93 Issue issue = null; 94 if (id != null) 95 { 96 id = id.trim(); 97 if (id.length() != 0 && defaultCode != null) 98 { 99 char firstChar = id.charAt(0); 100 if ('0' <= firstChar && firstChar <= '9') 101 { 102 id = defaultCode + id; 103 } 104 } 105 issue = IssueManager.getIssueById(id); 106 } 107 return issue; 108 } 109 110 114 public static Issue getIssueById(String id) 115 { 116 if (id == null || id.length() == 0) 117 { 118 return null; 119 } 120 Issue.FederatedId fid = new Issue.FederatedId(id); 121 return getIssueById(fid); 122 } 123 124 public static Issue getIssueById(Issue.FederatedId fid) 125 { 126 return IssueManager.getIssueByIdImpl(fid); 127 } 128 129 public static Issue getIssueByIdImpl(Issue.FederatedId fid) 130 { 131 Issue result = null; 132 Object obj = getMethodResult().get(ISSUE, GET_ISSUE_BY_ID, fid); 133 if (obj != null) 134 { 135 try 136 { 137 Issue cachedById = (Issue)obj; 138 Issue cachedByPk = getInstance(cachedById.getIssueId()); 139 if (cachedById.getFederatedId().equals(cachedByPk.getFederatedId())) 142 { 143 result = cachedByPk; 144 } 145 else 146 { 147 getMethodResult().remove(ISSUE, GET_ISSUE_BY_ID, fid); 148 } 149 } 150 catch (TorqueException e) 151 { 152 Log.get().error("", e); 153 } 154 } 155 156 if (result == null) 157 { 158 Criteria crit = new Criteria(5) 159 .add(IssuePeer.ID_PREFIX, fid.getPrefix()) 160 .add(IssuePeer.ID_COUNT, fid.getCount()); 161 crit.setIgnoreCase(true); 162 163 if ( fid.getDomain() != null) 164 { 165 crit.add(IssuePeer.ID_DOMAIN, fid.getDomain()); 166 } 167 168 try 169 { 170 List issues = IssuePeer.doSelect(crit); 171 if (!issues.isEmpty()) 172 { 173 result = (Issue)issues.get(0); 174 IssueManager.putInstance(result); 175 getMethodResult().put(result, ISSUE, GET_ISSUE_BY_ID, fid); 176 } 177 } 178 catch (Exception e) 179 { 180 Log.get().error("", e); 181 } 183 } 184 185 return result; 186 } 187 188 protected Persistent putInstanceImpl(Persistent om) 189 throws TorqueException 190 { 191 Persistent oldOm = super.putInstanceImpl(om); 192 Serializable obj = (Serializable )om; 194 getMethodResult().removeAll(obj, Issue.GET_MODULE_ATTRVALUES_MAP); 195 getMethodResult().remove(obj, Issue.GET_USER_ATTRIBUTEVALUES); 196 return oldOm; 197 } 198 199 200 203 protected void registerAsListener() 204 { 205 AttributeValueManager.addCacheListener(this); 206 AttachmentManager.addCacheListener(this); 207 DependManager.addCacheListener(this); 208 ActivityManager.addCacheListener(this); 209 AttributeManager.addCacheListener(this); 210 RModuleAttributeManager.addCacheListener(this); 211 } 212 213 214 217 public void addedObject(Persistent om) 218 { 219 if (om instanceof AttributeValue) 220 { 221 AttributeValue castom = (AttributeValue)om; 222 Long key = castom.getIssueId(); 223 try 224 { 225 Serializable obj = getInstance(key); 226 if (obj != null) 227 { 228 getMethodResult().remove(obj, Issue.GET_MODULE_ATTRVALUES_MAP); 229 getMethodResult().remove(obj, Issue.GET_USER_ATTRIBUTEVALUES); 230 } 231 } 232 catch(TorqueException e) 233 { 234 Log.get().warn("Invalid Issue id ", e); 235 } 236 } 237 else if (om instanceof Attachment) 238 { 239 Attachment castom = (Attachment)om; 240 try 241 { 242 Serializable obj = getInstance(castom.getIssueId()); 243 if (obj != null) 244 { 245 getMethodResult().remove(obj, Issue.GET_URLS); 246 getMethodResult().removeAll(obj, Issue.GET_COMMENTS); 247 getMethodResult().removeAll(obj, 248 Issue.GET_EXISTING_ATTACHMENTS); 249 } 250 } 251 catch(TorqueException e) 252 { 253 Log.get().warn("Invalid Issue id ", e); 254 } 255 } 256 else if (om instanceof Depend) 257 { 258 Depend castom = (Depend)om; 259 Long key = castom.getObserverId(); 260 try 261 { 262 Serializable obj = getInstance(key); 263 if (obj != null) 264 { 265 getMethodResult().removeAll(obj, Issue.GET_PARENTS); 266 } 267 key = castom.getObservedId(); 268 obj = getInstance(key); 269 if (obj != null) 270 { 271 getMethodResult().removeAll(obj, Issue.GET_CHILDREN); 272 } 273 } 274 catch(TorqueException e) 275 { 276 Log.get().warn("Invalid Issue id ", e); 277 } 278 } 279 else if (om instanceof Activity) 280 { 281 Activity castom = (Activity)om; 282 Long key = castom.getIssueId(); 283 try 284 { 285 Serializable obj = getInstance(key); 286 if (obj != null) 287 { 288 getMethodResult().removeAll(obj, Issue.GET_ACTIVITY); 289 } 290 } 291 catch(TorqueException e) 292 { 293 Log.get().warn("Invalid Issue id ", e); 294 } 295 } 296 else if (om instanceof Attribute) 297 { 298 getMethodResult().clear(); 299 } 300 else if (om instanceof RModuleAttribute) 301 { 302 getMethodResult().clear(); 303 } 304 } 305 306 public void refreshedObject(Persistent om) 307 { 308 addedObject(om); 309 } 310 311 312 public List getInterestedFields() 313 { 314 List interestedCacheFields = new LinkedList (); 315 interestedCacheFields.add(AttributeValuePeer.ISSUE_ID); 316 interestedCacheFields.add(AttachmentPeer.ISSUE_ID); 317 interestedCacheFields.add(DependPeer.OBSERVER_ID); 318 interestedCacheFields.add(DependPeer.OBSERVED_ID); 319 interestedCacheFields.add(AttributePeer.ATTRIBUTE_ID); 320 interestedCacheFields.add(RModuleAttributePeer.MODULE_ID); 321 return interestedCacheFields; 322 } 323 } 324 325 326 327 328 329 | Popular Tags |