+
+ /**
+ * Brings back all auto initializers to the bean initializer
+ * @see #switchOfAutoinitializer()
+ * @param oldAutoInit
+ */
+ protected void switchOnOldAutoInitializer(
+ Map<Class<? extends CdmBase>, AutoPropertyInitializer<CdmBase>> oldAutoInit) {
+ HibernateBeanInitializer initializer = (HibernateBeanInitializer)this.appContext.getBean("defaultBeanInitializer");
+ initializer.setBeanAutoInitializers(oldAutoInit);
+ }
+
+ /**
+ * Removes all auto initializers from the bean initializer
+ *
+ * @see #switchOnOldAutoInitializer(Map)
+ * @return
+ */
+ protected Map<Class<? extends CdmBase>, AutoPropertyInitializer<CdmBase>> switchOfAutoinitializer() {
+ HibernateBeanInitializer initializer = (HibernateBeanInitializer)this.appContext.getBean("defaultBeanInitializer");
+ Map<Class<? extends CdmBase>, AutoPropertyInitializer<CdmBase>> oldAutoInitializers = initializer.getBeanAutoInitializers();
+ Map<Class<? extends CdmBase>, AutoPropertyInitializer<CdmBase>> map = new HashMap<Class<? extends CdmBase>, AutoPropertyInitializer<CdmBase>>();
+ initializer.setBeanAutoInitializers(map);
+ return oldAutoInitializers;
+ }
+
+ /**
+ * @param cacheStrategy
+ * @param entitiesToUpdate
+ * @param entity
+ */
+ /**
+ * @param cacheStrategy
+ * @param entitiesToUpdate
+ * @param entity
+ */
+ private void updateTitleCacheForSingleEntity(
+ IIdentifiableEntityCacheStrategy<T> cacheStrategy,
+ List<T> entitiesToUpdate, T entity) {
+
+ assert (entity.isProtectedTitleCache() == false );
+
+ //exclude recursive inreferences
+ if (entity.isInstanceOf(Reference.class)){
+ Reference<?> ref = CdmBase.deproxy(entity, Reference.class);
+ if (ref.getInReference() != null && ref.getInReference().equals(ref)){
+ return;
+ }
+ }
+
+
+ //define the correct cache strategy
+ IIdentifiableEntityCacheStrategy entityCacheStrategy = cacheStrategy;
+ if (entityCacheStrategy == null){
+ entityCacheStrategy = entity.getCacheStrategy();
+ //FIXME find out why the wrong cache strategy is loaded here, see #1876
+ if (entity instanceof Reference){
+ entityCacheStrategy = ReferenceFactory.newReference(((Reference)entity).getType()).getCacheStrategy();
+ }
+ }
+ entity.setCacheStrategy(entityCacheStrategy);
+
+
+ //old titleCache
+ entity.setProtectedTitleCache(true);
+ String oldTitleCache = entity.getTitleCache();
+ entity.setTitleCache(oldTitleCache, false); //before we had entity.setProtectedTitleCache(false) but this deleted the titleCache itself
+
+ //NonViralNames and Reference have more caches //TODO handle in NameService
+ String oldNameCache = null;
+ String oldFullTitleCache = null;
+ String oldAbbrevTitleCache = null;
+ if (entity instanceof NonViralName ){
+ NonViralName<?> nvn = (NonViralName) entity;
+ if (!nvn.isProtectedNameCache()){
+ nvn.setProtectedNameCache(true);
+ oldNameCache = nvn.getNameCache();
+ nvn.setProtectedNameCache(false);
+ }
+ if (!nvn.isProtectedFullTitleCache()){
+ nvn.setProtectedFullTitleCache(true);
+ oldFullTitleCache = nvn.getFullTitleCache();
+ nvn.setProtectedFullTitleCache(false);
+ }
+ }else if (entity instanceof Reference){
+ Reference<?> ref = (Reference<?>) entity;
+ if (!ref.isProtectedAbbrevTitleCache()){
+ ref.setProtectedAbbrevTitleCache(true);
+ oldAbbrevTitleCache = ref.getAbbrevTitleCache();
+ ref.setProtectedAbbrevTitleCache(false);
+ }
+ }
+ setOtherCachesNull(entity); //TODO find better solution
+
+ String newTitleCache = entityCacheStrategy.getTitleCache(entity);
+ if (oldTitleCache == null || oldTitleCache != null && ! oldTitleCache.equals(newTitleCache) ){
+ entity.setTitleCache(null, false);
+ String newCache = entity.getTitleCache();
+ if (newCache == null){
+ logger.warn("newCache should never be null");
+ }
+ if (oldTitleCache == null){
+ logger.info("oldTitleCache should never be null");
+ }
+ if (entity instanceof NonViralName){
+ NonViralName<?> nvn = (NonViralName) entity;
+ nvn.getNameCache();
+ nvn.getFullTitleCache();
+ }
+ if (entity instanceof Reference){
+ Reference<?> ref = (Reference<?>) entity;
+ ref.getAbbrevTitleCache();
+ }
+ entitiesToUpdate.add(entity);
+ }else if (entity instanceof NonViralName){
+ NonViralName<?> nvn = (NonViralName) entity;
+ String newNameCache = nvn.getNameCache();
+ String newFullTitleCache = nvn.getFullTitleCache();
+ if (oldNameCache == null || (oldNameCache != null && !oldNameCache.equals(newNameCache))){
+ entitiesToUpdate.add(entity);
+ }else if (oldFullTitleCache == null || (oldFullTitleCache != null && !oldFullTitleCache.equals(newFullTitleCache))){
+ entitiesToUpdate.add(entity);
+ }
+ }else if (entity instanceof Reference){
+ Reference<?> ref = (Reference<?>) entity;
+ String newAbbrevTitleCache = ref.getAbbrevTitleCache();
+ if (oldAbbrevTitleCache == null || (oldAbbrevTitleCache != null && !oldAbbrevTitleCache.equals(newAbbrevTitleCache))){
+ entitiesToUpdate.add(entity);
+ }
+ }
+ }