1 23 24 package org.infoglue.cms.controllers.kernel.impl.simple; 25 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.List ; 29 30 import org.apache.log4j.Logger; 31 import org.exolab.castor.jdo.Database; 32 import org.exolab.castor.jdo.OQLQuery; 33 import org.exolab.castor.jdo.QueryResults; 34 import org.infoglue.cms.entities.kernel.BaseEntityVO; 35 import org.infoglue.cms.entities.management.AvailableServiceBinding; 36 import org.infoglue.cms.entities.management.SiteNodeTypeDefinition; 37 import org.infoglue.cms.entities.management.SiteNodeTypeDefinitionVO; 38 import org.infoglue.cms.entities.management.impl.simple.SiteNodeTypeDefinitionImpl; 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 44 45 public class SiteNodeTypeDefinitionController extends BaseController 46 { 47 private final static Logger logger = Logger.getLogger(SiteNodeTypeDefinitionController.class.getName()); 48 49 52 53 public static SiteNodeTypeDefinitionController getController() 54 { 55 return new SiteNodeTypeDefinitionController(); 56 } 57 58 public SiteNodeTypeDefinitionVO getSiteNodeTypeDefinitionVOWithId(Integer siteNodeTypeDefinitionId) throws SystemException, Bug 59 { 60 return (SiteNodeTypeDefinitionVO) getVOWithId(SiteNodeTypeDefinitionImpl.class, siteNodeTypeDefinitionId); 61 } 62 63 public SiteNodeTypeDefinitionVO getSiteNodeTypeDefinitionVOWithId(Integer siteNodeTypeDefinitionId, Database db) throws SystemException, Bug 64 { 65 return (SiteNodeTypeDefinitionVO) getVOWithId(SiteNodeTypeDefinitionImpl.class, siteNodeTypeDefinitionId, db); 66 } 67 68 public SiteNodeTypeDefinitionVO create(SiteNodeTypeDefinitionVO vo) throws ConstraintException, SystemException 69 { 70 SiteNodeTypeDefinition ent = new SiteNodeTypeDefinitionImpl(); 71 ent.setValueObject(vo); 72 ent = (SiteNodeTypeDefinition) createEntity(ent); 73 return ent.getValueObject(); 74 } 75 76 public void delete(SiteNodeTypeDefinitionVO vo) throws ConstraintException, SystemException 77 { 78 deleteEntity(SiteNodeTypeDefinitionImpl.class, vo.getSiteNodeTypeDefinitionId()); 79 } 80 81 public SiteNodeTypeDefinition getSiteNodeTypeDefinitionWithId(Integer siteNodeTypeDefinitionId, Database db) throws SystemException, Bug 82 { 83 return (SiteNodeTypeDefinition) getObjectWithId(SiteNodeTypeDefinitionImpl.class, siteNodeTypeDefinitionId, db); 84 } 85 86 public SiteNodeTypeDefinition getSiteNodeTypeDefinitionWithIdAsReadOnly(Integer siteNodeTypeDefinitionId, Database db) throws SystemException, Bug 87 { 88 return (SiteNodeTypeDefinition) getObjectWithIdAsReadOnly(SiteNodeTypeDefinitionImpl.class, siteNodeTypeDefinitionId, db); 89 } 90 91 public List getSiteNodeTypeDefinitionVOList() throws SystemException, Bug 92 { 93 return getAllVOObjects(SiteNodeTypeDefinitionImpl.class, "siteNodeTypeDefinitionId"); 94 } 95 96 97 105 106 public SiteNodeTypeDefinition getSiteNodeTypeDefinitionWithName(String name, Database db, boolean readOnly) throws SystemException, Bug 107 { 108 SiteNodeTypeDefinition siteNodeTypeDefinition = null; 109 110 try 111 { 112 OQLQuery oql = db.getOQLQuery("SELECT s FROM org.infoglue.cms.entities.management.impl.simple.SiteNodeTypeDefinitionImpl s WHERE s.name = $1"); 113 oql.bind(name); 114 115 QueryResults results = null; 116 if(readOnly) 117 results = oql.execute(Database.ReadOnly); 118 else 119 { 120 this.logger.info("Fetching entity in read/write mode" + name); 121 results = oql.execute(); 122 } 123 124 if (results.hasMore()) 125 { 126 siteNodeTypeDefinition = (SiteNodeTypeDefinition)results.next(); 127 } 128 129 results.close(); 130 oql.close(); 131 } 132 catch(Exception e) 133 { 134 throw new SystemException("An error occurred when we tried to fetch a SiteNodeTypeDefinition based on name. Reason:" + e.getMessage(), e); 135 } 136 137 return siteNodeTypeDefinition; 138 } 139 140 143 144 public void deleteSiteNodeTypeDefinition(Integer siteNodeTypeDefinitionId, Database db) throws SystemException, Bug 145 { 146 try 147 { 148 db.remove(getSiteNodeTypeDefinitionWithId(siteNodeTypeDefinitionId, db)); 149 } 150 catch(Exception e) 151 { 152 throw new SystemException("An error occurred when we tried to delete SiteNodeTypeDefinition in the database. Reason: " + e.getMessage(), e); 153 } 154 } 155 156 public SiteNodeTypeDefinitionVO update(SiteNodeTypeDefinitionVO siteNodeTypeDefinitionVO) throws ConstraintException, SystemException 157 { 158 Database db = CastorDatabaseService.getDatabase(); 159 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 160 161 SiteNodeTypeDefinition siteNodeTypeDefinition = null; 162 163 beginTransaction(db); 164 165 try 166 { 167 siteNodeTypeDefinition = getSiteNodeTypeDefinitionWithId(siteNodeTypeDefinitionVO.getSiteNodeTypeDefinitionId(), db); 169 siteNodeTypeDefinition.setValueObject(siteNodeTypeDefinitionVO); 170 171 ceb.throwIfNotEmpty(); 173 174 commitTransaction(db); 175 } 176 catch(ConstraintException ce) 177 { 178 logger.warn("An error occurred so we should not complete the transaction:" + ce, ce); 179 rollbackTransaction(db); 180 throw ce; 181 } 182 catch(Exception e) 183 { 184 logger.error("An error occurred so we should not complete the transaction:" + e, e); 185 rollbackTransaction(db); 186 throw new SystemException(e.getMessage()); 187 } 188 189 return siteNodeTypeDefinition.getValueObject(); 190 } 191 192 public SiteNodeTypeDefinitionVO update(SiteNodeTypeDefinitionVO siteNodeTypeDefinitionVO, String [] availableServiceBindingValues) throws ConstraintException, SystemException 193 { 194 Database db = CastorDatabaseService.getDatabase(); 195 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 196 197 SiteNodeTypeDefinition siteNodeTypeDefinition = null; 198 199 beginTransaction(db); 200 201 try 202 { 203 List availableServiceBindingList = new ArrayList (); 205 if(availableServiceBindingValues != null) 206 { 207 for (int i=0; i < availableServiceBindingValues.length; i++) 208 { 209 AvailableServiceBinding availableServiceBinding = AvailableServiceBindingController.getController().getAvailableServiceBindingWithId(new Integer (availableServiceBindingValues[i]), db); 210 availableServiceBindingList.add(availableServiceBinding); 211 } 212 } 213 214 siteNodeTypeDefinition = SiteNodeTypeDefinitionController.getController().getSiteNodeTypeDefinitionWithId(siteNodeTypeDefinitionVO.getSiteNodeTypeDefinitionId(), db); 215 siteNodeTypeDefinition.setValueObject(siteNodeTypeDefinitionVO); 216 logger.info("availableServiceBindingList:" + availableServiceBindingList); 217 siteNodeTypeDefinition.setAvailableServiceBindings(availableServiceBindingList); 218 219 ceb.throwIfNotEmpty(); 221 222 commitTransaction(db); 223 } 224 catch(ConstraintException ce) 225 { 226 logger.warn("An error occurred so we should not complete the transaction:" + ce, ce); 227 rollbackTransaction(db); 228 throw ce; 229 } 230 catch(Exception e) 231 { 232 logger.error("An error occurred so we should not complete the transaction:" + e, e); 233 rollbackTransaction(db); 234 throw new SystemException(e.getMessage()); 235 } 236 237 return siteNodeTypeDefinition.getValueObject(); 238 } 239 240 244 245 public List getAvailableServiceBindingVOList(Integer siteNodeTypeDefinitionId) throws ConstraintException, SystemException 246 { 247 Database db = CastorDatabaseService.getDatabase(); 248 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 249 250 List availableServiceBindingVOList = null; 251 252 beginTransaction(db); 253 254 try 255 { 256 268 269 SiteNodeTypeDefinition siteNodeTypeDefinition = getSiteNodeTypeDefinitionWithIdAsReadOnly(siteNodeTypeDefinitionId, db); 270 Collection availableServiceBindingList = siteNodeTypeDefinition.getAvailableServiceBindings(); 271 availableServiceBindingVOList = toVOList(availableServiceBindingList); 272 273 274 ceb.throwIfNotEmpty(); 276 277 commitTransaction(db); 278 } 279 catch(ConstraintException ce) 280 { 281 logger.warn("An error occurred so we should not complete the transaction:" + ce, ce); 282 rollbackTransaction(db); 283 throw ce; 284 } 285 catch(Exception e) 286 { 287 logger.error("An error occurred so we should not complete the transaction:" + e, e); 288 rollbackTransaction(db); 289 throw new SystemException(e.getMessage()); 290 } 291 292 return availableServiceBindingVOList; 293 } 294 295 296 300 301 public List getAvailableServiceBindingVOList(Integer siteNodeTypeDefinitionId, Database db) throws ConstraintException, SystemException 302 { 303 List availableServiceBindingVOList = null; 304 316 317 SiteNodeTypeDefinition siteNodeTypeDefinition = getSiteNodeTypeDefinitionWithIdAsReadOnly(siteNodeTypeDefinitionId, db); 318 Collection availableServiceBindingList = siteNodeTypeDefinition.getAvailableServiceBindings(); 319 availableServiceBindingVOList = toVOList(availableServiceBindingList); 320 321 return availableServiceBindingVOList; 322 } 323 324 328 329 public BaseEntityVO getNewVO() 330 { 331 return new SiteNodeTypeDefinitionVO(); 332 } 333 334 } 335 336 | Popular Tags |