1 23 24 package org.infoglue.cms.controllers.kernel.impl.simple; 25 26 import org.apache.log4j.Logger; 27 import org.exolab.castor.jdo.CacheManager; 28 import org.exolab.castor.jdo.Database; 29 import org.exolab.castor.persist.spi.CallbackInterceptor; 30 import org.infoglue.cms.entities.content.Content; 31 import org.infoglue.cms.entities.content.ContentVersion; 32 import org.infoglue.cms.entities.content.impl.simple.ContentImpl; 33 import org.infoglue.cms.entities.content.impl.simple.ContentVersionImpl; 34 import org.infoglue.cms.entities.content.impl.simple.DigitalAssetImpl; 35 import org.infoglue.cms.entities.content.impl.simple.MediumContentImpl; 36 import org.infoglue.cms.entities.content.impl.simple.SmallContentImpl; 37 import org.infoglue.cms.entities.kernel.IBaseEntity; 38 import org.infoglue.cms.entities.management.impl.simple.AccessRightGroupImpl; 39 import org.infoglue.cms.entities.management.impl.simple.AccessRightImpl; 40 import org.infoglue.cms.entities.management.impl.simple.AccessRightRoleImpl; 41 import org.infoglue.cms.entities.management.impl.simple.AccessRightUserImpl; 42 import org.infoglue.cms.entities.management.impl.simple.AvailableServiceBindingImpl; 43 import org.infoglue.cms.entities.management.impl.simple.ContentTypeDefinitionImpl; 44 import org.infoglue.cms.entities.management.impl.simple.GroupImpl; 45 import org.infoglue.cms.entities.management.impl.simple.GroupPropertiesImpl; 46 import org.infoglue.cms.entities.management.impl.simple.InterceptionPointImpl; 47 import org.infoglue.cms.entities.management.impl.simple.InterceptorImpl; 48 import org.infoglue.cms.entities.management.impl.simple.LanguageImpl; 49 import org.infoglue.cms.entities.management.impl.simple.RegistryImpl; 50 import org.infoglue.cms.entities.management.impl.simple.RepositoryImpl; 51 import org.infoglue.cms.entities.management.impl.simple.RepositoryLanguageImpl; 52 import org.infoglue.cms.entities.management.impl.simple.RoleImpl; 53 import org.infoglue.cms.entities.management.impl.simple.RolePropertiesImpl; 54 import org.infoglue.cms.entities.management.impl.simple.SystemUserImpl; 55 import org.infoglue.cms.entities.management.impl.simple.TransactionHistoryImpl; 56 import org.infoglue.cms.entities.management.impl.simple.UserPropertiesImpl; 57 import org.infoglue.cms.entities.structure.SiteNode; 58 import org.infoglue.cms.entities.structure.SiteNodeVersion; 59 import org.infoglue.cms.entities.structure.impl.simple.SiteNodeImpl; 60 import org.infoglue.cms.entities.structure.impl.simple.SiteNodeVersionImpl; 61 import org.infoglue.cms.entities.workflow.impl.simple.WorkflowDefinitionImpl; 62 import org.infoglue.cms.exception.Bug; 63 import org.infoglue.cms.util.ChangeNotificationController; 64 import org.infoglue.cms.util.NotificationMessage; 65 import org.infoglue.cms.util.RemoteCacheUpdater; 66 import org.infoglue.deliver.util.CacheController; 67 68 69 76 public class CmsJDOCallback implements CallbackInterceptor 77 { 78 private final static Logger logger = Logger.getLogger(CmsJDOCallback.class.getName()); 79 80 public void using(Object object, Database db) 81 { 82 } 85 86 87 public Class loaded(Object object, short accessMode) throws Exception 88 { 89 return null; 92 } 93 94 95 public void storing(Object object, boolean modified) throws Exception 96 { 97 100 if (TransactionHistoryImpl.class.getName().indexOf(object.getClass().getName()) == -1 && RegistryImpl.class.getName().indexOf(object.getClass().getName()) == -1 && modified) 102 { 103 logger.info("Actually stored it:" + object + ":" + modified); 105 106 String userName = "SYSTEM"; 107 NotificationMessage notificationMessage = new NotificationMessage("CmsJDOCallback", object.getClass().getName(), userName, NotificationMessage.TRANS_UPDATE, getObjectIdentity(object), object.toString()); 108 ChangeNotificationController.getInstance().addNotificationMessage(notificationMessage); 109 if(object.getClass().getName().indexOf("org.infoglue.cms.entities.management") > -1 && !object.getClass().getName().equals(RegistryImpl.class.getName())) 110 RemoteCacheUpdater.getSystemNotificationMessages().add(notificationMessage); 111 112 if(object.getClass().getName().equals(RepositoryImpl.class.getName())) 113 { 114 CacheController.clearCache("repositoryCache"); 115 } 116 else if(object.getClass().getName().equals(InterceptionPointImpl.class.getName())) 117 { 118 CacheController.clearCache("interceptionPointCache"); 119 CacheController.clearCache("interceptorsCache"); 120 CacheController.clearCache("authorizationCache"); 121 } 122 else if(object.getClass().getName().equals(InterceptorImpl.class.getName())) 123 { 124 CacheController.clearCache("interceptionPointCache"); 125 CacheController.clearCache("interceptorsCache"); 126 CacheController.clearCache("authorizationCache"); 127 } 128 else if(object.getClass().getName().equals(AccessRightImpl.class.getName()) || object.getClass().getName().equals(AccessRightRoleImpl.class.getName()) || object.getClass().getName().equals(AccessRightGroupImpl.class.getName()) || object.getClass().getName().equals(AccessRightUserImpl.class.getName())) 129 { 130 CacheController.clearCache("interceptionPointCache"); 131 CacheController.clearCache("interceptorsCache"); 132 CacheController.clearCache("authorizationCache"); 133 } 134 else if(object.getClass().getName().equals(ContentTypeDefinitionImpl.class.getName())) 135 { 136 CacheController.clearCache("contentTypeDefinitionCache"); 137 } 138 else if(object.getClass().getName().equals(ContentImpl.class.getName())) 139 { 140 CacheController.clearCache("childContentCache"); 141 CacheController.clearCache("componentContentsCache"); 142 clearCache(SmallContentImpl.class); 143 clearCache(MediumContentImpl.class); 144 } 145 else if(object.getClass().getName().equals(ContentVersionImpl.class.getName())) 146 { 147 CacheController.clearCache("componentContentsCache"); 148 } 149 else if(object.getClass().getName().equals(RepositoryLanguageImpl.class.getName())) 150 { 151 CacheController.clearCache("masterLanguageCache"); 152 CacheController.clearCache("repositoryLanguageListCache"); 153 } 154 else if(object.getClass().getName().equals(DigitalAssetImpl.class.getName())) 155 { 156 DigitalAssetController.deleteCachedDigitalAssets((Integer )getObjectIdentity(object)); 158 } 159 else if(object.getClass().getName().equals(WorkflowDefinitionImpl.class.getName())) 160 { 161 CacheController.clearCache("workflowCache"); 162 } 163 else if(object.getClass().getName().equals(SystemUserImpl.class.getName())) 164 { 165 CacheController.clearCache("principalCache"); 166 } 167 else if(object.getClass().getName().equals(GroupImpl.class.getName())) 168 { 169 CacheController.clearCache("groupListCache"); 170 CacheController.clearCache("groupVOListCache"); 171 } 172 else if(object.getClass().getName().equals(RoleImpl.class.getName())) 173 { 174 CacheController.clearCache("roleListCache"); 175 CacheController.clearCache("roleVOListCache"); 176 } 177 else if(object.getClass().getName().equals(UserPropertiesImpl.class.getName())) 178 { 179 CacheController.clearCache("principalPropertyValueCache"); 180 CacheController.clearCache("relatedCategoriesCache"); 181 } 182 else if(object.getClass().getName().equals(GroupPropertiesImpl.class.getName())) 183 { 184 CacheController.clearCache("principalPropertyValueCache"); 185 CacheController.clearCache("groupPropertiesCache"); 186 CacheController.clearCache("relatedCategoriesCache"); 187 } 188 else if(object.getClass().getName().equals(RolePropertiesImpl.class.getName())) 189 { 190 CacheController.clearCache("principalPropertyValueCache"); 191 CacheController.clearCache("rolePropertiesCache"); 192 CacheController.clearCache("relatedCategoriesCache"); 193 } 194 else if(object.getClass().getName().equals(AvailableServiceBindingImpl.class.getName())) 195 { 196 CacheController.clearCache("availableServiceBindingCache"); 197 } 198 else if(object.getClass().getName().equals(LanguageImpl.class.getName())) 199 { 200 CacheController.clearCache("languageCache"); 201 } 202 203 } 204 } 205 206 private synchronized void clearCache(Class c) throws Exception 207 { 208 Database db = CastorDatabaseService.getDatabase(); 209 210 try 211 { 212 Class [] types = {c}; 213 Class [] ids = {null}; 214 CacheManager manager = db.getCacheManager(); 215 manager.expireCache(types); 216 } 218 catch(Exception e) 219 { 220 e.printStackTrace(); 221 } 222 finally 223 { 224 db.close(); 225 } 226 } 227 228 public void creating( Object object, Database db ) 229 throws Exception 230 { 231 } 233 234 235 public void created(Object object) throws Exception 236 { 237 239 241 logger.info("created..........................." + object); 246 if (TransactionHistoryImpl.class.getName().indexOf(object.getClass().getName()) == -1 && RegistryImpl.class.getName().indexOf(object.getClass().getName()) == -1) 247 { 248 String userName = "SYSTEM"; 249 NotificationMessage notificationMessage = new NotificationMessage("CMSJDOCallback", object.getClass().getName(), userName, NotificationMessage.TRANS_CREATE, getObjectIdentity(object), object.toString()); 250 ChangeNotificationController.getInstance().addNotificationMessage(notificationMessage); 251 if(object.getClass().getName().indexOf("org.infoglue.cms.entities.management") > -1 && !object.getClass().getName().equals(RegistryImpl.class.getName())) 252 RemoteCacheUpdater.getSystemNotificationMessages().add(notificationMessage); 253 254 if(object.getClass().getName().equals(RepositoryImpl.class.getName())) 255 { 256 CacheController.clearCache("repositoryCache"); 257 } 258 else if(object.getClass().getName().equals(InterceptionPointImpl.class.getName())) 259 { 260 CacheController.clearCache("interceptionPointCache"); 261 CacheController.clearCache("interceptorsCache"); 262 CacheController.clearCache("authorizationCache"); 263 } 264 else if(object.getClass().getName().equals(InterceptorImpl.class.getName())) 265 { 266 CacheController.clearCache("interceptionPointCache"); 267 CacheController.clearCache("interceptorsCache"); 268 CacheController.clearCache("authorizationCache"); 269 } 270 else if(object.getClass().getName().equals(AccessRightImpl.class.getName()) || object.getClass().getName().equals(AccessRightRoleImpl.class.getName()) || object.getClass().getName().equals(AccessRightGroupImpl.class.getName()) || object.getClass().getName().equals(AccessRightUserImpl.class.getName())) 271 { 272 CacheController.clearCache("interceptionPointCache"); 273 CacheController.clearCache("interceptorsCache"); 274 CacheController.clearCache("authorizationCache"); 275 } 276 else if(object.getClass().getName().equals(ContentTypeDefinitionImpl.class.getName())) 277 { 278 CacheController.clearCache("contentTypeDefinitionCache"); 279 } 280 else if(object.getClass().getName().equals(ContentImpl.class.getName())) 281 { 282 CacheController.clearCache("childContentCache"); 283 clearCache(SmallContentImpl.class); 284 clearCache(MediumContentImpl.class); 285 } 286 else if(object.getClass().getName().equals(ContentVersionImpl.class.getName())) 287 { 288 CacheController.clearCache("componentContentsCache"); 289 } 290 else if(object.getClass().getName().equals(RepositoryLanguageImpl.class.getName())) 291 { 292 CacheController.clearCache("masterLanguageCache"); 293 CacheController.clearCache("repositoryLanguageListCache"); 294 } 295 else if(object.getClass().getName().equals(WorkflowDefinitionImpl.class.getName())) 296 { 297 CacheController.clearCache("workflowCache"); 298 } 299 else if(object.getClass().getName().equals(SystemUserImpl.class.getName())) 300 { 301 CacheController.clearCache("principalCache"); 302 } 303 else if(object.getClass().getName().equals(GroupImpl.class.getName())) 304 { 305 CacheController.clearCache("groupListCache"); 306 } 307 else if(object.getClass().getName().equals(RoleImpl.class.getName())) 308 { 309 CacheController.clearCache("roleListCache"); 310 } 311 else if(object.getClass().getName().equals(UserPropertiesImpl.class.getName())) 312 { 313 CacheController.clearCache("principalPropertyValueCache"); 314 CacheController.clearCache("relatedCategoriesCache"); 315 } 316 else if(object.getClass().getName().equals(GroupPropertiesImpl.class.getName())) 317 { 318 CacheController.clearCache("principalPropertyValueCache"); 319 CacheController.clearCache("groupPropertiesCache"); 320 CacheController.clearCache("relatedCategoriesCache"); 321 } 322 else if(object.getClass().getName().equals(RolePropertiesImpl.class.getName())) 323 { 324 CacheController.clearCache("principalPropertyValueCache"); 325 CacheController.clearCache("rolePropertiesCache"); 326 CacheController.clearCache("relatedCategoriesCache"); 327 } 328 else if(object.getClass().getName().equals(AvailableServiceBindingImpl.class.getName())) 329 { 330 CacheController.clearCache("availableServiceBindingCache"); 331 } 332 else if(object.getClass().getName().equals(LanguageImpl.class.getName())) 333 { 334 CacheController.clearCache("languageCache"); 335 } 336 337 338 339 } 341 } 342 343 344 public void removing( Object object ) 345 throws Exception 346 { 347 } 349 350 351 public void removed( Object object ) throws Exception 352 { 353 356 if (TransactionHistoryImpl.class.getName().indexOf(object.getClass().getName()) == -1 && RegistryImpl.class.getName().indexOf(object.getClass().getName()) == -1) 357 { 358 String userName = "SYSTEM"; 359 NotificationMessage notificationMessage = new NotificationMessage("CMSJDOCallback", object.getClass().getName(), userName, NotificationMessage.TRANS_DELETE, getObjectIdentity(object), object.toString()); 360 ChangeNotificationController.getInstance().addNotificationMessage(notificationMessage); 361 if(object.getClass().getName().indexOf("org.infoglue.cms.entities.management") > -1 && !object.getClass().getName().equals(RegistryImpl.class.getName())) 362 RemoteCacheUpdater.getSystemNotificationMessages().add(notificationMessage); 363 364 if(object.getClass().getName().equals(RepositoryImpl.class.getName())) 365 { 366 CacheController.clearCache("repositoryCache"); 367 } 368 else if(object.getClass().getName().equals(InterceptionPointImpl.class.getName())) 369 { 370 CacheController.clearCache("interceptionPointCache"); 371 CacheController.clearCache("interceptorsCache"); 372 CacheController.clearCache("authorizationCache"); 373 } 374 else if(object.getClass().getName().equals(InterceptorImpl.class.getName())) 375 { 376 CacheController.clearCache("interceptionPointCache"); 377 CacheController.clearCache("interceptorsCache"); 378 CacheController.clearCache("authorizationCache"); 379 } 380 else if(object.getClass().getName().equals(AccessRightImpl.class.getName()) || object.getClass().getName().equals(AccessRightRoleImpl.class.getName()) || object.getClass().getName().equals(AccessRightGroupImpl.class.getName()) || object.getClass().getName().equals(AccessRightUserImpl.class.getName())) 381 { 382 CacheController.clearCache("interceptionPointCache"); 383 CacheController.clearCache("interceptorsCache"); 384 CacheController.clearCache("authorizationCache"); 385 } 386 else if(object.getClass().getName().equals(ContentTypeDefinitionImpl.class.getName())) 387 { 388 CacheController.clearCache("contentTypeDefinitionCache"); 389 } 390 else if(object.getClass().getName().equals(ContentImpl.class.getName())) 391 { 392 CacheController.clearCache("childContentCache"); 393 clearCache(SmallContentImpl.class); 394 clearCache(MediumContentImpl.class); 395 396 RegistryController.getController().clearRegistryForReferencedEntity(Content.class.getName(), getObjectIdentity(object).toString()); 397 RegistryController.getController().clearRegistryForReferencingEntityCompletingName(Content.class.getName(), getObjectIdentity(object).toString()); 398 } 399 else if(object.getClass().getName().equals(ContentVersionImpl.class.getName())) 400 { 401 CacheController.clearCache("componentContentsCache"); 402 RegistryController.getController().clearRegistryForReferencingEntityName(ContentVersion.class.getName(), getObjectIdentity(object).toString()); 403 } 404 else if(object.getClass().getName().equals(RepositoryLanguageImpl.class.getName())) 405 { 406 CacheController.clearCache("masterLanguageCache"); 407 CacheController.clearCache("repositoryLanguageListCache"); 408 } 409 else if(object.getClass().getName().equals(DigitalAssetImpl.class.getName())) 410 { 411 DigitalAssetController.deleteCachedDigitalAssets((Integer )getObjectIdentity(object)); 413 } 414 else if(object.getClass().getName().equals(SiteNodeImpl.class.getName())) 415 { 416 RegistryController.getController().clearRegistryForReferencedEntity(SiteNode.class.getName(), getObjectIdentity(object).toString()); 417 RegistryController.getController().clearRegistryForReferencingEntityCompletingName(SiteNode.class.getName(), getObjectIdentity(object).toString()); 418 } 419 else if(object.getClass().getName().equals(SiteNodeVersionImpl.class.getName())) 420 { 421 RegistryController.getController().clearRegistryForReferencingEntityName(SiteNodeVersion.class.getName(), getObjectIdentity(object).toString()); 422 } 423 else if(object.getClass().getName().equals(WorkflowDefinitionImpl.class.getName())) 424 { 425 CacheController.clearCache("workflowCache"); 426 } 427 else if(object.getClass().getName().equals(SystemUserImpl.class.getName())) 428 { 429 CacheController.clearCache("principalCache"); 430 } 431 else if(object.getClass().getName().equals(GroupImpl.class.getName())) 432 { 433 CacheController.clearCache("groupListCache"); 434 } 435 else if(object.getClass().getName().equals(RoleImpl.class.getName())) 436 { 437 CacheController.clearCache("roleListCache"); 438 } 439 else if(object.getClass().getName().equals(UserPropertiesImpl.class.getName())) 440 { 441 CacheController.clearCache("principalPropertyValueCache"); 442 CacheController.clearCache("relatedCategoriesCache"); 443 } 444 else if(object.getClass().getName().equals(GroupPropertiesImpl.class.getName())) 445 { 446 CacheController.clearCache("principalPropertyValueCache"); 447 CacheController.clearCache("groupPropertiesCache"); 448 CacheController.clearCache("relatedCategoriesCache"); 449 } 450 else if(object.getClass().getName().equals(RolePropertiesImpl.class.getName())) 451 { 452 CacheController.clearCache("principalPropertyValueCache"); 453 CacheController.clearCache("rolePropertiesCache"); 454 CacheController.clearCache("relatedCategoriesCache"); 455 } 456 else if(object.getClass().getName().equals(AvailableServiceBindingImpl.class.getName())) 457 { 458 CacheController.clearCache("availableServiceBindingCache"); 459 } 460 else if(object.getClass().getName().equals(LanguageImpl.class.getName())) 461 { 462 CacheController.clearCache("languageCache"); 463 } 464 465 466 } 467 } 468 469 470 public void releasing(Object object, boolean committed) 471 { 472 475 486 487 } 488 489 490 public void updated(Object object) throws Exception 491 { 492 495 499 508 } 509 510 511 private Integer getEntityId(Object entity) throws Bug 512 { 513 Integer entityId = new Integer (-1); 514 515 try 516 { 517 entityId = ((IBaseEntity) entity).getId(); 518 } 519 catch (Exception e) 520 { 521 e.printStackTrace(); 522 throw new Bug("Unable to retrieve object id"); 523 } 524 525 return entityId; 526 } 527 528 private Object getObjectIdentity(Object entity) throws Bug 529 { 530 Object objectIdentity = new Integer (-1); 531 532 try 533 { 534 objectIdentity = ((IBaseEntity) entity).getIdAsObject(); 535 } 536 catch (Exception e) 537 { 538 e.printStackTrace(); 539 throw new Bug("Unable to retrieve object identity"); 540 } 541 542 return objectIdentity; 543 } 544 545 } 546 547 | Popular Tags |