1 package org.tigris.scarab.om; 2 3 48 49 import java.util.List ; 50 import java.util.LinkedList ; 51 import java.util.ArrayList ; 52 import java.util.Iterator ; 53 import java.io.Serializable ; 54 55 import org.apache.torque.TorqueException; 56 import org.apache.torque.om.Persistent; 57 import org.apache.torque.util.Criteria; 58 import org.apache.torque.manager.CacheListener; 59 import org.tigris.scarab.util.Log; 60 61 67 public class ModuleManager 68 extends BaseModuleManager 69 implements CacheListener 70 { 71 76 public ModuleManager() 77 throws TorqueException 78 { 79 super(); 80 setRegion(getClassName().replace('.', '_')); 81 } 82 83 protected Module getInstanceImpl() 84 { 85 return new ScarabModule(); 86 } 87 88 94 public static Module getInstance(String moduleDomain, 95 String moduleRealName, 96 String moduleCode) 97 throws TorqueException 98 { 99 return getManager().getInstanceImpl(moduleDomain, moduleRealName, 100 moduleCode); 101 } 102 103 109 protected Module getInstanceImpl(String moduleDomain, 110 String moduleRealName, 111 String moduleCode) 112 throws TorqueException 113 { 114 Criteria crit = new Criteria(); 115 crit.add(ScarabModulePeer.MODULE_NAME, moduleDomain); 116 crit.add(ScarabModulePeer.MODULE_NAME, moduleRealName); 117 crit.add(ScarabModulePeer.MODULE_CODE, moduleCode); 118 List result = ScarabModulePeer.doSelect(crit); 119 if (result.size() != 1) 120 { 121 throw new TorqueException ("Selected: " + result.size() + 122 " rows. Expected 1."); } 124 return (Module) result.get(0); 125 } 126 127 136 public static List getInstancesFromIssueList(List issues) 137 throws TorqueException 138 { 139 if (issues == null) 140 { 141 throw new IllegalArgumentException ("Null issue list is not allowed."); } 143 144 List modules = new ArrayList (); 145 Iterator i = issues.iterator(); 146 if (i.hasNext()) 147 { 148 Issue issue = (Issue)i.next(); 149 if (issue != null) 150 { 151 Module module = issue.getModule(); 152 if (module != null && !modules.contains(module)) 153 { 154 modules.add(module); 155 } 156 } 157 else 158 { 159 throw new TorqueException("Null issue in list is not allowed."); } 161 } 162 return modules; 163 } 164 165 166 169 protected void registerAsListener() 170 { 171 RModuleIssueTypeManager.addCacheListener(this); 172 RModuleAttributeManager.addCacheListener(this); 173 AttributeGroupManager.addCacheListener(this); 174 RModuleOptionManager.addCacheListener(this); 175 AttributeManager.addCacheListener(this); 176 AttributeOptionManager.addCacheListener(this); 177 IssueTypeManager.addCacheListener(this); 178 } 179 180 183 public void addedObject(Persistent om) 184 { 185 if (om instanceof RModuleAttribute) 186 { 187 RModuleAttribute castom = (RModuleAttribute)om; 188 Integer key = castom.getModuleId(); 189 try 190 { 191 Serializable obj = getInstance(key); 192 if (obj != null) 193 { 194 getMethodResult().removeAll(obj, 195 AbstractScarabModule.GET_R_MODULE_ATTRIBUTES); 196 } 197 } 198 catch(TorqueException e) 199 { 200 Log.get().warn("Invalid Module id ", e); 201 } 202 } 203 else if (om instanceof RModuleOption) 204 { 205 RModuleOption castom = (RModuleOption)om; 206 Integer key = castom.getModuleId(); 207 try 208 { 209 Serializable obj = getInstance(key); 210 if (obj != null) 211 { 212 getMethodResult().removeAll(obj, 213 AbstractScarabModule.GET_LEAF_R_MODULE_OPTIONS); 214 } 215 } 216 catch(TorqueException e) 217 { 218 Log.get().warn("Invalid Module id ", e); 219 } 220 } 221 else if (om instanceof RModuleIssueType) 222 { 223 RModuleIssueType castom = (RModuleIssueType)om; 224 Integer key = castom.getModuleId(); 225 try 226 { 227 Serializable obj = getInstance(key); 228 if (obj != null) 229 { 230 getMethodResult().remove(obj, 231 AbstractScarabModule.GET_NAV_ISSUE_TYPES); 232 } 233 } 234 catch(TorqueException e) 235 { 236 Log.get().warn("Invalid Module id ", e); 237 } 238 } 239 else if (om instanceof IssueType) 240 { 241 getMethodResult().clear(); 242 } 243 else if (om instanceof Attribute) 244 { 245 getMethodResult().clear(); 246 } 247 else if (om instanceof AttributeOption) 248 { 249 getMethodResult().clear(); 250 } 251 } 252 253 public void refreshedObject(Persistent om) 254 { 255 addedObject(om); 256 } 257 258 259 public List getInterestedFields() 260 { 261 List interestedCacheFields = new LinkedList (); 262 interestedCacheFields.add(RModuleOptionPeer.MODULE_ID); 263 interestedCacheFields.add(RModuleAttributePeer.MODULE_ID); 264 interestedCacheFields.add(RModuleIssueTypePeer.MODULE_ID); 265 interestedCacheFields.add(AttributeGroupPeer.MODULE_ID); 266 interestedCacheFields.add(AttributePeer.ATTRIBUTE_ID); 267 interestedCacheFields.add(AttributeOptionPeer.OPTION_ID); 268 interestedCacheFields.add(IssueTypePeer.ISSUE_TYPE_ID); 269 return interestedCacheFields; 270 } 271 } 272 | Popular Tags |