1 23 24 package org.infoglue.cms.controllers.kernel.impl.simple; 25 26 import java.util.Collection ; 27 import java.util.List ; 28 29 import org.apache.log4j.Logger; 30 import org.exolab.castor.jdo.Database; 31 import org.exolab.castor.jdo.OQLQuery; 32 import org.exolab.castor.jdo.QueryResults; 33 import org.infoglue.cms.entities.kernel.BaseEntityVO; 34 import org.infoglue.cms.entities.management.AvailableServiceBinding; 35 import org.infoglue.cms.entities.management.AvailableServiceBindingVO; 36 import org.infoglue.cms.entities.management.SiteNodeTypeDefinition; 37 import org.infoglue.cms.entities.management.impl.simple.AvailableServiceBindingImpl; 38 import org.infoglue.cms.entities.management.impl.simple.ServiceDefinitionImpl; 39 import org.infoglue.cms.exception.Bug; 40 import org.infoglue.cms.exception.ConstraintException; 41 import org.infoglue.cms.exception.SystemException; 42 import org.infoglue.cms.util.ConstraintExceptionBuffer; 43 import org.infoglue.deliver.util.CacheController; 44 45 50 51 public class AvailableServiceBindingController extends BaseController 52 { 53 private final static Logger logger = Logger.getLogger(AvailableServiceBindingController.class.getName()); 54 55 58 59 public static AvailableServiceBindingController getController() 60 { 61 return new AvailableServiceBindingController(); 62 } 63 64 public AvailableServiceBindingVO getAvailableServiceBindingVOWithId(Integer availableServiceBindingId) throws SystemException, Bug 65 { 66 return (AvailableServiceBindingVO)getVOWithId(AvailableServiceBindingImpl.class, availableServiceBindingId); 67 } 68 69 70 public AvailableServiceBindingVO create(AvailableServiceBindingVO vo) throws ConstraintException, SystemException 71 { 72 AvailableServiceBinding ent = new AvailableServiceBindingImpl(); 73 ent.setValueObject(vo); 74 ent = (AvailableServiceBinding) createEntity(ent); 75 return ent.getValueObject(); 76 } 77 78 82 83 public void delete(AvailableServiceBindingVO availableServiceBindingVO) throws ConstraintException, SystemException 84 { 85 Database db = CastorDatabaseService.getDatabase(); 86 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 87 88 beginTransaction(db); 89 90 try 91 { 92 AvailableServiceBinding availableServiceBinding = getAvailableServiceBindingWithId(availableServiceBindingVO.getAvailableServiceBindingId(), db); 93 if(availableServiceBinding.getServiceBindings() != null && availableServiceBinding.getServiceBindings().size() > 0) 94 { 95 throw new ConstraintException("AvailableServiceBinding.deleteAction", "3100"); 96 } 97 } 98 catch(ConstraintException ce) 99 { 100 throw ce; 101 } 102 catch(SystemException se) 103 { 104 throw se; 105 } 106 catch(Exception e) 107 { 108 throw new SystemException("An error occurred in AvailableServiceBindingController.delete(). Reason:" + e.getMessage(), e); 109 } 110 finally 111 { 112 commitTransaction(db); 113 } 114 115 deleteEntity(AvailableServiceBindingImpl.class, availableServiceBindingVO.getAvailableServiceBindingId()); 116 } 117 118 119 public AvailableServiceBinding getAvailableServiceBindingWithId(Integer availableServiceBindingId, Database db) throws SystemException, Bug 120 { 121 return (AvailableServiceBinding) getObjectWithId(AvailableServiceBindingImpl.class, availableServiceBindingId, db); 122 } 123 124 125 public AvailableServiceBinding getReadOnlyAvailableServiceBindingWithId(Integer availableServiceBindingId, Database db) throws SystemException, Bug 126 { 127 return (AvailableServiceBinding) getObjectWithIdAsReadOnly(AvailableServiceBindingImpl.class, availableServiceBindingId, db); 128 } 129 130 public List getAvailableServiceBindingVOList() throws SystemException, Bug 131 { 132 return getAllVOObjects(AvailableServiceBindingImpl.class, "availableServiceBindingId"); 133 } 134 135 136 142 143 public AvailableServiceBindingVO getAvailableServiceBindingVOWithName(String name) throws SystemException, Bug 144 { 145 String key = "" + name; 146 logger.info("key:" + key); 147 AvailableServiceBindingVO availableServiceBindingVO = (AvailableServiceBindingVO)CacheController.getCachedObject("availableServiceBindingCache", key); 148 if(availableServiceBindingVO != null) 149 { 150 logger.info("There was an cached availableServiceBindingVO:" + availableServiceBindingVO); 151 } 152 else 153 { 154 155 Database db = CastorDatabaseService.getDatabase(); 156 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 157 158 beginTransaction(db); 159 160 try 161 { 162 AvailableServiceBinding AvailableServiceBinding = getAvailableServiceBindingWithName(name, db, true); 163 if(AvailableServiceBinding != null) 164 availableServiceBindingVO = AvailableServiceBinding.getValueObject(); 165 166 CacheController.cacheObject("availableServiceBindingCache", key, availableServiceBindingVO); 167 168 commitTransaction(db); 169 } 170 catch(Exception e) 171 { 172 rollbackTransaction(db); 173 throw new SystemException("An error occurred when we tried to fetch a list of AvailableServiceBinding. Reason:" + e.getMessage(), e); 174 } 175 176 } 177 178 return availableServiceBindingVO; 179 } 180 181 182 188 189 public AvailableServiceBindingVO getAvailableServiceBindingVOWithName(String name, Database db) throws SystemException, Bug 190 { 191 String key = "" + name; 192 logger.info("key:" + key); 193 AvailableServiceBindingVO availableServiceBindingVO = (AvailableServiceBindingVO)CacheController.getCachedObject("availableServiceBindingCache", key); 194 if(availableServiceBindingVO != null) 195 { 196 logger.info("There was an cached availableServiceBindingVO:" + availableServiceBindingVO); 197 } 198 else 199 { 200 201 AvailableServiceBinding AvailableServiceBinding = getAvailableServiceBindingWithName(name, db, true); 202 if(AvailableServiceBinding != null) 203 availableServiceBindingVO = AvailableServiceBinding.getValueObject(); 204 205 CacheController.cacheObject("availableServiceBindingCache", key, availableServiceBindingVO); 206 } 207 208 return availableServiceBindingVO; 209 } 210 211 212 221 222 public AvailableServiceBinding getAvailableServiceBindingWithName(String name, Database db, boolean readOnly) throws SystemException, Bug 223 { 224 AvailableServiceBinding availableServiceBinding = null; 225 226 try 227 { 228 OQLQuery oql = db.getOQLQuery("SELECT a FROM org.infoglue.cms.entities.management.impl.simple.AvailableServiceBindingImpl a WHERE a.name = $1"); 229 oql.bind(name); 230 231 QueryResults results = null; 232 233 if(readOnly) 234 results = oql.execute(Database.ReadOnly); 235 else 236 { 237 this.logger.info("Fetching entity in read/write mode:" + name); 238 results = oql.execute(); 239 } 240 241 if(results.hasMore()) 242 { 243 availableServiceBinding = (AvailableServiceBinding)results.next(); 244 } 245 246 results.close(); 247 oql.close(); 248 } 249 catch(Exception e) 250 { 251 throw new SystemException("An error occurred when we tried to fetch a named AvailableServiceBinding. Reason:" + e.getMessage(), e); 252 } 253 254 256 return availableServiceBinding; 257 } 258 259 260 263 264 public List getAssignedAvailableServiceBindings(Integer siteNodeTypeDefinitionId) throws ConstraintException, SystemException 265 { 266 Database db = CastorDatabaseService.getDatabase(); 267 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 268 269 List assignedAvailableServiceBindingVOList = null; 270 271 beginTransaction(db); 272 273 try 274 { 275 SiteNodeTypeDefinition siteNodeTypeDefinition = SiteNodeTypeDefinitionController.getController().getSiteNodeTypeDefinitionWithId(siteNodeTypeDefinitionId, db); 276 Collection assignedAvailableServiceBinding = siteNodeTypeDefinition.getAvailableServiceBindings(); 277 assignedAvailableServiceBindingVOList = AvailableServiceBindingController.toVOList(assignedAvailableServiceBinding); 278 279 ceb.throwIfNotEmpty(); 281 282 commitTransaction(db); 283 } 284 catch(ConstraintException ce) 285 { 286 logger.warn("An error occurred so we should not complete the transaction:" + ce, ce); 287 rollbackTransaction(db); 288 throw ce; 289 } 290 catch(Exception e) 291 { 292 logger.error("An error occurred so we should not complete the transaction:" + e, e); 293 rollbackTransaction(db); 294 throw new SystemException(e.getMessage()); 295 } 296 297 return assignedAvailableServiceBindingVOList; 298 } 299 300 public AvailableServiceBindingVO update(AvailableServiceBindingVO availableServiceBindingVO) throws ConstraintException, SystemException 301 { 302 Database db = CastorDatabaseService.getDatabase(); 303 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 304 305 AvailableServiceBinding availableServiceBinding = null; 306 307 beginTransaction(db); 308 309 try 310 { 311 availableServiceBinding = getAvailableServiceBindingWithId(availableServiceBindingVO.getAvailableServiceBindingId(), db); 313 availableServiceBinding.setValueObject(availableServiceBindingVO); 314 315 ceb.throwIfNotEmpty(); 317 318 commitTransaction(db); 319 } 320 catch(ConstraintException ce) 321 { 322 logger.warn("An error occurred so we should not complete the transaction:" + ce, ce); 323 rollbackTransaction(db); 324 throw ce; 325 } 326 catch(Exception e) 327 { 328 logger.error("An error occurred so we should not complete the transaction:" + e, e); 329 rollbackTransaction(db); 330 throw new SystemException(e.getMessage()); 331 } 332 333 334 return availableServiceBinding.getValueObject(); 335 } 336 337 public AvailableServiceBindingVO update(AvailableServiceBindingVO availableServiceBindingVO, String [] values) throws ConstraintException, SystemException 338 { 339 return (AvailableServiceBindingVO) updateEntity(AvailableServiceBindingImpl.class, (BaseEntityVO)availableServiceBindingVO, "setServiceDefinitions", ServiceDefinitionImpl.class, values ); 340 } 341 342 public AvailableServiceBinding update(Integer availableServiceBindingId, String [] values, Database db) throws ConstraintException, SystemException 343 { 344 AvailableServiceBinding availableServiceBinding = getAvailableServiceBindingWithId(availableServiceBindingId, db); 345 return (AvailableServiceBinding) updateEntity(AvailableServiceBindingImpl.class, (BaseEntityVO)availableServiceBinding.getVO(), "setServiceDefinitions", ServiceDefinitionImpl.class, values ); 346 } 347 348 352 353 public List getServiceDefinitionVOList(Integer availableServiceBindingId) throws ConstraintException, SystemException 354 { 355 Database db = CastorDatabaseService.getDatabase(); 356 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 357 358 List serviceDefinitionVOList = null; 359 360 beginTransaction(db); 361 362 try 363 { 364 serviceDefinitionVOList = getServiceDefinitionVOList(db, availableServiceBindingId); 365 366 ceb.throwIfNotEmpty(); 368 369 commitTransaction(db); 370 } 371 catch(ConstraintException ce) 372 { 373 logger.warn("An error occurred so we should not complete the transaction:" + ce, ce); 374 rollbackTransaction(db); 375 throw ce; 376 } 377 catch(Exception e) 378 { 379 logger.error("An error occurred so we should not complete the transaction:" + e, e); 380 rollbackTransaction(db); 381 throw new SystemException(e.getMessage()); 382 } 383 384 return serviceDefinitionVOList; 385 } 386 387 391 392 public List getServiceDefinitionVOList(Database db, Integer availableServiceBindingId) throws ConstraintException, SystemException 393 { 394 List serviceDefinitionVOList = null; 395 396 AvailableServiceBinding availableServiceBinding = getReadOnlyAvailableServiceBindingWithId(availableServiceBindingId, db); 397 Collection serviceDefinitionList = availableServiceBinding.getServiceDefinitions(); 398 serviceDefinitionVOList = toVOList(serviceDefinitionList); 399 400 return serviceDefinitionVOList; 401 } 402 403 407 408 public BaseEntityVO getNewVO() 409 { 410 return new AvailableServiceBindingVO(); 411 } 412 413 } 414 415 | Popular Tags |