ICdmEntitySession, CdmEntitySession, MockCdmEntitySession : added method to update session
ICdmEntitySessionManager, CdmEntitySessionManager, MockCdmEntitySessionManager : added methods to set active session, dispose and update sessions
ProxyUtils : added utility method
EntityCacherDebugResult : corrected method to determine cache corresponding to entity
CdmTransientEntityCacher : corrected put method
CacheLoader : optimised recursive call
CdmServiceCacher : corrected methods to get from cache and load
CdmServiceRequestExecutor : added update result return calls to load
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
import eu.etaxonomy.taxeditor.remoting.cache.CacheLoader;
+import eu.etaxonomy.taxeditor.remoting.cache.CdmEntityCacheKey;
import eu.etaxonomy.taxeditor.remoting.cache.CdmTransientEntityCacher;
import eu.etaxonomy.taxeditor.service.TermServiceRequestExecutor;
+import eu.etaxonomy.taxeditor.session.CdmEntitySession;
+import eu.etaxonomy.taxeditor.session.CdmEntitySessionManager;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
/**
* Class which uses CDM services to cache cdm entities
* @param <T>
*/
@Component
-public class CdmServiceCacher extends CdmCacher{
+public class CdmServiceCacher extends CdmCacher {
@Autowired
ITermService termService;
+ @Autowired
+ private CdmEntitySessionManager cdmEntitySessionManager;
+
+ private CdmTransientEntityCacher cdmTransientEntityCacher;
+
private CacheLoader cacheLoader;
@Override
return false;
}
+ public void setActiveSession(ICdmEntitySession cdmEntitySession) {
+ if(cdmEntitySession != null && cdmEntitySession instanceof CdmEntitySession) {
+ this.cdmTransientEntityCacher = ((CdmEntitySession) cdmEntitySession).getCacher();
+ } else {
+ this.cdmTransientEntityCacher = null;
+ }
+ }
+
+ @Override
+ public CdmBase getFromCache(CdmBase cdmBase) {
+ CdmBase cachedCdmEntity = null;
+ // first we check in the active session cache if the
+ if(!isCachable(cdmBase) && cdmTransientEntityCacher != null) {
+ CdmEntityCacheKey key = CdmTransientEntityCacher.generateKey(cdmBase);
+ cachedCdmEntity = cdmTransientEntityCacher.getFromCache(key);
+
+ }
+ if(cachedCdmEntity == null) {
+ cachedCdmEntity = super.getFromCache(cdmBase);
+ }
+ return cachedCdmEntity;
+ }
+
/* (non-Javadoc)
* @see eu.etaxonomy.cdm.api.cache.CdmCacher#load(eu.etaxonomy.cdm.model.common.CdmBase)
*/
@Override
public CdmBase load(CdmBase cdmEntity) {
- CdmBase cachedCdmEntity = getFromCache(cdmEntity);
- // NOTE : only when no cached cdm entity exists we
- // load the entire sub-graph, which means that the
- // sub-graph is never updated if the input
- // cdm entity graph is newer
- if(cachedCdmEntity == null && isCachable(cdmEntity)) {
+ CdmBase cachedCdmEntity = getFromCache(cdmEntity.getUuid());
+
+ if(isCachable(cdmEntity)) {
cachedCdmEntity = cacheLoader.load(cdmEntity, true, false);
}
return cachedCdmEntity;
import java.util.Map;
import java.util.Set;
-import javassist.util.proxy.ProxyFactory;
import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;
import org.apache.log4j.Logger;
-import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.springframework.util.ReflectionUtils;
private static boolean isRecursiveEnabled = true;
- private final ICdmCacher cdmCacher;
+ protected final ICdmCacher cdmCacher;
private final Cache cdmlibModelCache;
- private final ICdmCacher cdmServiceCacher;
public CacheLoader(ICdmCacher cdmCacher) {
- this(cdmCacher, null);
- }
-
- public CacheLoader(ICdmCacher cdmCacher, ICdmCacher cdmServiceCacher) {
this.cdmCacher = cdmCacher;
this.cdmlibModelCache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
- this.cdmServiceCacher = cdmServiceCacher;
+
}
return null;
}
-
// start by looking up the cdm entity in the cache
CdmBase cachedCdmEntity = cdmCacher.getFromCache(cdmEntity);
if(cachedCdmEntity == cdmEntity) {
return cachedCdmEntity;
}
-
}
CdmBase loadedCdmBase;
}
- private CdmBase load(CdmBase cdmEntity) {
+ protected CdmBase load(CdmBase cdmEntity) {
logger.info("loading object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId());
cdmEntity = (CdmBase)ProxyUtils.deproxy(cdmEntity);
- // start by looking up the cdm entity in the cache
- CdmBase cachedCdmEntity = cdmCacher.getFromCache(cdmEntity);
+ cdmCacher.put(cdmEntity);
+
+ return cdmCacher.getFromCache(cdmEntity);
- if(cachedCdmEntity != null) {
- // if cdm entity was found in cache then return ...
- logger.info(" - object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + " already exists");
- return cachedCdmEntity;
- } else {
- // ... else save the entity in the cache
- cdmCacher.put(cdmEntity);
- logger.info(" - object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + " put in cache");
- return cdmEntity;
- }
}
+
private CdmBase loadRecursive(CdmBase cdmEntity, Set<Object> alreadyVisitedEntities, boolean update) {
CdmBase cachedCdmEntity = load(cdmEntity);
- if(cdmServiceCacher != null && cdmServiceCacher.exists(cachedCdmEntity)) {
- return cachedCdmEntity;
- }
+
// we want to recursive through the cdmEntity (and not the cachedCdmEntity)
// since there could be new or deleted objects in the cdmEntity sub-graph
} else {
logger.info("object of type " + cdmEntityInSubGraph.getClass().getName() + " with id " + cdmEntityInSubGraph.getId() + " already visited");
}
-
}
}
} else {
throw new CdmClientCacheException("CdmEntity with class " + cdmEntity.getClass().getName() + " is not found in the cdmlib model cache. " +
"The cache may be corrupted or not in sync with the latest model version" );
}
+
return cachedCdmEntity;
}
}
field.setAccessible(true);
Object o = field.get(cdmEntity);
-
- if(o != null && o instanceof HibernateProxy) {
- LazyInitializer hli = ((HibernateProxy)o).getHibernateLazyInitializer();
- if(!hli.isUninitialized()) {
- o = ((HibernateProxy) o).getHibernateLazyInitializer().getImplementation();
- field.set(cdmEntity, o);
- }
- }
-
- if(o != null && o instanceof PersistentCollection) {
- PersistentCollection pc = ((PersistentCollection)o);
- if(pc.wasInitialized()) {
- o = ProxyUtils.getObject(pc);
- field.set(cdmEntity, o);
- }
- }
-
+ o = ProxyUtils.deproxy(o);
+ field.set(cdmEntity, o);
CdmBase cdmEntityInSubGraph = null;
if(update) {
- // making sure that the field in cached cdm entity is always
- // up-to-date by setting to the value of the cdm entity being loaded
- // the only exception to this is found below
- field.set(cachedCdmEntity, o);
- }
- if(o != null
- && !ProxyFactory.isProxyClass(o.getClass())
- && !(o instanceof PersistentCollection) ) {
-
+ // if we are in update mode we have to make the field of the cached entity
+ // up-to-date by setting it to the value of the cdm entity being loaded
+ // NOTE : two exceptions to this are found below
+ field.set(cachedCdmEntity, o);
+ }
+ if(o != null && !ProxyUtils.isProxy(o)) {
if(CdmBase.class.isAssignableFrom(o.getClass())) {
logger.info("found initialised cdm entity '" + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
cdmEntityInSubGraph = (CdmBase)o;
CdmBase cachedCdmEntityInSubGraph = cdmCacher.getFromCache(cdmEntityInSubGraph);
- // the only exception to updating the field to the latest value
- // is the case where the field has been already initialised, cached and
- // is not the same as the one in the cache, in which case we set the value
- // of the field to the one found in the cache
+ Object oldCachedCdmEntityInSubGraph = field.get(cachedCdmEntity);
+ if(ProxyUtils.isProxy(oldCachedCdmEntityInSubGraph)) {
+ LazyInitializer hli =
+ ((HibernateProxy)oldCachedCdmEntityInSubGraph).getHibernateLazyInitializer();
+
+ if(cdmEntityInSubGraph.getId() == ((Integer)hli.getIdentifier()).intValue()) {
+ // exception 1 : is the case where
+ // the earlier value of the field in the cached entity
+ // was a proxy with the same id then we don't need to
+ // update it here as it will be updated on demand,
+ // so we reset it to the earlier proxy
+ field.set(cachedCdmEntity, oldCachedCdmEntityInSubGraph);
+ return null;
+ }
+ }
+
if(cachedCdmEntityInSubGraph != null) {
if(cachedCdmEntityInSubGraph != cdmEntityInSubGraph) {
+ // exception 2 : is the case where
+ // the field has been already initialised, cached and
+ // is not the same as the one in the cache, in which case we set the value
+ // of the field to the one found in the cache
logger.info("setting cached + real value to '" + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
field.set(cachedCdmEntity, cachedCdmEntityInSubGraph);
field.set(cdmEntity, cachedCdmEntityInSubGraph);
} else {
- // hack to stop the recursion, since the field value object in cdmEntity
+ // since the field value object in cdmEntity
// is the same as the field value object in cachedCdmEntity
- cdmEntityInSubGraph = null;
+ // we are sure that the its subgraph is also correctly loaded,
+ // so we can exit the recursion
+ return null;
}
}
-
} else if(o instanceof Map && !alreadyVisitedEntities.contains(o)) {
loadRecursive((Map)o, alreadyVisitedEntities, update);
} else if(o instanceof Collection && !alreadyVisitedEntities.contains(o)) {
import java.io.File;
import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheException;
private static CdmRemoteCacheManager cdmRemoteCacheManager = null;
+ private final Set<CdmTransientEntityCacher> transientEntityCachers = new HashSet<CdmTransientEntityCacher>();
+
public static final Resource CDMLIB_CACHE_MANAGER_CONFIG_RESOURCE =
new ClassPathResource("cdmlib-ehcache.xml");
}
}
+
}
import java.util.Collection;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;
this.cacheId = cacheId;
cache = new Cache(getEntityCacheConfiguration(cacheId));
- CdmRemoteCacheManager.getInstance().getDefaultCacheManager().addCache(cache);
-
this.cdmEntitySessionManager = cdmEntitySessionManager;
- CdmBase fromCache = cdmServiceCacher.getFromCache(UUID.fromString("462a7819-8b00-4190-8313-88b5be81fad5"));
-
- cacheLoader = new CacheLoader(this, cdmServiceCacher);
+ cacheLoader = new CacheLoader(this);
+ }
+ public CdmTransientEntityCacher(Object sessionOwner, ICdmEntitySessionManager cdmEntitySessionManager) {
+ this(generateCacheId(sessionOwner), cdmEntitySessionManager);
}
- public CdmTransientEntityCacher(Object obj, ICdmEntitySessionManager cdmEntitySessionManager) {
- this(obj.getClass().getName() + String.valueOf(obj.hashCode()), cdmEntitySessionManager);
+ public static String generateCacheId(Object sessionOwner) {
+ return sessionOwner.getClass().getName() + String.valueOf(sessionOwner.hashCode());
}
/**
return;
}
CdmEntityCacheKey id = new CdmEntityCacheKey(cdmEntity);
- getCache().put(new Element(id, cdmEntity));
+
+ cachedCdmEntity = getFromCache(id);
+ if(cachedCdmEntity == null) {
+ getCache().put(new Element(id, cdmEntity));
+ logger.info(" - object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + " put in cache");
+ return;
+ }
+ logger.info(" - object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + " already exists");
}
if(cachedCdmEntity == null) {
// ... then try the permanent cache
- cachedCdmEntity = cdmServiceCacher.getFromCache(cdmBase);
+ cachedCdmEntity = cdmServiceCacher.getFromCache(cdmBase.getUuid());
}
return cachedCdmEntity;
public void dispose() {
cache.dispose();
- CdmRemoteCacheManager.getInstance().getDefaultCacheManager().removeCache(cacheId);
+
}
import java.util.Set;
import net.sf.ehcache.Cache;
+import net.sf.ehcache.Element;
import org.apache.log4j.Logger;
import org.hibernate.collection.spi.PersistentCollection;
private String getCachesContainingEntity(CdmBase cdmEntity) {
Cache defaultCache = CdmRemoteCacheManager.getInstance().getDefaultCacheManager().getCache(CdmCacher.DEFAULT_CACHE_NAME);
String caches = "";
- Object dce = defaultCache.get(cdmEntity.getUuid());
- if(dce != null && dce == cdmEntity) {
- caches = CdmCacher.DEFAULT_CACHE_NAME;
- }
- if(!caches.isEmpty()) {
- caches += ", ";
+ Element dce = defaultCache.get(cdmEntity.getUuid());
+ if(dce != null && dce.getObjectValue() == cdmEntity) {
+ caches = "{DC}";
}
+
Object cte = cacher.getFromCache(CdmTransientEntityCacher.generateKey(cdmEntity));
if(cte != null && cte == cdmEntity) {
- caches += cacher.toString();
+ caches += "{TC}";
}
return caches;
}
label = "[" + className + "] " + fieldName + " : " + String.valueOf(((Map)object).size());
} else if(object instanceof CdmBase) {
- label = "[" + className + ",id" + ((CdmBase)object).getId() + "] " + fieldName + " : " + object.toString();
+ label = getCachesContainingEntity((CdmBase)object) + "[" + className + ",id" + ((CdmBase)object).getId() + "] " + fieldName + " : " + object.toString();
} else {
label = "[" + className + "] " + fieldName + " : " + object.toString();
}
return o;
}
+ public static boolean isProxy(Object o) {
+ if(o != null && o instanceof HibernateProxy) {
+ LazyInitializer hli = ((HibernateProxy)o).getHibernateLazyInitializer();
+ if(hli.isUninitialized()) {
+ return true;
+ }
+ }
+
+ if(o != null && o instanceof PersistentCollection) {
+ PersistentCollection pc = ((PersistentCollection)o);
+ if(!pc.wasInitialized()) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
public static void setRoleValueInOwner(Object owner, String role, Object value) {
if(role == null || role.isEmpty()) {
throw new CdmRemotingException("Role cannot be null or an empty string");
import org.springframework.remoting.support.RemoteInvocationResult;
import org.springframework.stereotype.Component;
+import eu.etaxonomy.cdm.api.service.UpdateResult;
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
@Component
if(rir.getValue() != null && !rir.hasException()) {
if(currentRemoteInvocation.getMethodName().equals("merge")) {
rir = new RemoteInvocationResult(cdmEntitySessionManager.load(rir.getValue(), true));
+ } else if(rir.getValue() instanceof UpdateResult){
+ UpdateResult result = (UpdateResult)rir.getValue();
+ if(result.isOk()){
+ cdmEntitySessionManager.update(result.getCdmEntity(), result.getUpdatedObjects());
+ }
} else {
rir = new RemoteInvocationResult(cdmEntitySessionManager.load(rir.getValue(), false));
}
private final List<ICdmEntitySessionEnabled> changeObservers;
+ private final Set<CdmBase> newCdmEntities;
+
public CdmEntitySession(ICdmEntitySessionEnabled sessionOwner, CdmEntitySessionManager cdmEntitySessionManager) {
this.cdmTransientEntityCacher = new CdmTransientEntityCacher(sessionOwner, cdmEntitySessionManager);
this.cdmEntitySessionManager = cdmEntitySessionManager;
this.changeObservers = new ArrayList<ICdmEntitySessionEnabled>();
+ this.newCdmEntities = new HashSet<CdmBase>();
cdmEntitySessionManager.addToOwnerSessionMap(sessionOwner, this);
}
return (T)cdmTransientEntityCacher.load(cdmBase, update);
}
+ @Override
+ public <T extends CdmBase> void update() {
+ List<T> rootEntities = getRootEntities();
+ if(rootEntities != null) {
+ for(T rootEntity : rootEntities) {
+ load(rootEntity, true);
+ }
+ }
+ }
@Override
public <T extends ICdmBase> void update(T cdmBase, Set<CdmBase> affectedObjects) {
CdmPostDataChangeObservableListener.getDefault().unregister(observer);
}
changeObservers.clear();
- cdmEntitySessionManager.dispose(sessionOwner);
+ cdmEntitySessionManager.remove(sessionOwner);
}
return sessionOwner.getRootEntities();
}
+ public CdmTransientEntityCacher getCacher() {
+ return cdmTransientEntityCacher;
+ }
+
+
// $Id$
/**
-* Copyright (C) 2014 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
+ * Copyright (C) 2014 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
package eu.etaxonomy.taxeditor.session;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import eu.etaxonomy.cdm.api.cache.CdmServiceCacher;
import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent.EventType;
/**
* @author cmathew
*/
@Component
public class CdmEntitySessionManager implements ICdmEntitySessionManager {
- private static final Logger logger = Logger.getLogger(CdmEntitySessionManager.class);
+ private static final Logger logger = Logger.getLogger(CdmEntitySessionManager.class);
private final Map<ICdmEntitySessionEnabled, ICdmEntitySession> ownerSessionMap =
- new HashMap<ICdmEntitySessionEnabled, ICdmEntitySession>();
+ new HashMap<ICdmEntitySessionEnabled, ICdmEntitySession>();
private final List<ICdmEntitySessionManagerObserver> sessionObservers = new ArrayList<ICdmEntitySessionManagerObserver>();
private ICdmEntitySession activeSession;
+ @Autowired
+ private CdmServiceCacher cdmServiceCacher;
+
@Override
- public ICdmEntitySession newSession(ICdmEntitySessionEnabled sessionOwner, boolean setAsActive) {
- ICdmEntitySession session = ownerSessionMap.get(sessionOwner);
- if(session == null) {
- session = new CdmEntitySession(sessionOwner, this);
- addToOwnerSessionMap(sessionOwner, session);
+ public ICdmEntitySession newSession(ICdmEntitySessionEnabled sessionOwner, boolean setAsActive) {
+ ICdmEntitySession session = ownerSessionMap.get(sessionOwner);
+ if(session == null) {
+ session = new CdmEntitySession(sessionOwner, this);
+ addToOwnerSessionMap(sessionOwner, session);
- }
+ }
- if(setAsActive) {
- activeSession = session;
+ if(setAsActive) {
+ setActiveSession(session);
- }
+ }
- return session;
- }
+ return session;
+ }
@Override
public ICdmEntitySession getActiveSession() {
return activeSession;
}
+ private void setActiveSession(ICdmEntitySession activeSession) {
+ this.activeSession = activeSession;
+ cdmServiceCacher.setActiveSession(activeSession);
+ }
+
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#getSessions()
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#bind(eu.etaxonomy.taxeditor.session.ISessionEventListener)
- */
- @Override
- public void bind(ICdmEntitySessionEnabled sessionOwner) {
- if(sessionOwner == null) {
- activeSession = null;
- return;
- }
- ICdmEntitySession session = ownerSessionMap.get(sessionOwner);
- if(session == null) {
- session = newSession(sessionOwner,true);
- }
-
- activeSession = session;
-
- }
-
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(T)
- */
- @Override
- public <T extends Object> T load(T obj, boolean update) {
- if(activeSession == null) {
- return obj;
- } else {
- return activeSession.load(obj, update);
- }
- }
-
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(T)
- */
- @Override
- public <T extends CdmBase> T load(T cdmBase, boolean update) {
- if(activeSession == null) {
- return cdmBase;
- }
- return activeSession.load(cdmBase, update);
- }
-
-
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(java.util.Collection)
- */
- @Override
- public <T extends CdmBase> Collection<T> load(Collection<T> cdmBaseList, boolean update) {
- if(activeSession == null) {
- return cdmBaseList;
- }
- return activeSession.load(cdmBaseList, update);
- }
-
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#dispose(eu.etaxonomy.taxeditor.session.ISessionEventListener)
- */
- void dispose(ICdmEntitySessionEnabled owner) {
- ICdmEntitySession session = ownerSessionMap.get(owner);
- if(session == null) {
- logger.info("No Session connected to owner, nothing to dispose");
- return;
- }
- if(session == activeSession) {
- activeSession = null;
- }
- ownerSessionMap.remove(owner);
- notifyObservers();
- }
-
- void addToOwnerSessionMap(ICdmEntitySessionEnabled owner, ICdmEntitySession session) {
- ownerSessionMap.put(owner, session);
- }
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#bind(eu.etaxonomy.taxeditor.session.ISessionEventListener)
+ */
+ @Override
+ public void bind(ICdmEntitySessionEnabled sessionOwner) {
+ if(sessionOwner == null) {
+ setActiveSession(null);
+ return;
+ }
+ ICdmEntitySession session = ownerSessionMap.get(sessionOwner);
+ if(session == null) {
+ session = newSession(sessionOwner,true);
+ }
+
+ setActiveSession(session);
+
+ }
+
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(T)
+ */
+ @Override
+ public <T extends Object> T load(T obj, boolean update) {
+ if(activeSession == null) {
+ return obj;
+ } else {
+ return activeSession.load(obj, update);
+ }
+ }
+
+ @Override
+ public <T extends CdmBase> void update(T cdmBase, Set<CdmBase> affectedObjects) {
+ if(activeSession != null) {
+ activeSession.addEvent(cdmBase, affectedObjects, EventType.UPDATE);
+ }
+ }
+
+ @Override
+ public <T extends CdmBase> void update() {
+ if(activeSession != null) {
+ activeSession.update();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(T)
+ */
+ @Override
+ public <T extends CdmBase> T load(T cdmBase, boolean update) {
+ if(activeSession == null) {
+ return cdmBase;
+ }
+ return activeSession.load(cdmBase, update);
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(java.util.Collection)
+ */
+ @Override
+ public <T extends CdmBase> Collection<T> load(Collection<T> cdmBaseList, boolean update) {
+ if(activeSession == null) {
+ return cdmBaseList;
+ }
+ return activeSession.load(cdmBaseList, update);
+ }
+
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#dispose(eu.etaxonomy.taxeditor.session.ISessionEventListener)
+ */
+ void remove(ICdmEntitySessionEnabled owner) {
+ ICdmEntitySession session = ownerSessionMap.get(owner);
+ if(session == null) {
+ logger.info("No Session connected to owner, nothing to do");
+ return;
+ }
+ if(session == activeSession) {
+ setActiveSession(null);
+ }
+ ownerSessionMap.remove(owner);
+
+ }
+
+ @Override
+ public void dispose(ICdmEntitySessionEnabled owner) {
+ ICdmEntitySession session = ownerSessionMap.get(owner);
+ if(session != null) {
+ session.dispose();
+ }
+ notifyObservers();
+ }
+
+ @Override
+ public void disposeAll() {
+ Set<ICdmEntitySessionEnabled> owners =
+ new HashSet<ICdmEntitySessionEnabled>(ownerSessionMap.keySet());
+ for(ICdmEntitySessionEnabled owner : owners) {
+ ICdmEntitySession session = ownerSessionMap.get(owner);
+ if(session != null) {
+ session.dispose();
+ }
+ }
+ notifyObservers();
+ }
+
+ void addToOwnerSessionMap(ICdmEntitySessionEnabled owner, ICdmEntitySession session) {
+ ownerSessionMap.put(owner, session);
+ }
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#addSessionListener()
}
-
-
-
-
-
}
+
public <T extends CdmBase> T remoteUpdate(IService<T> service, T cdmBase);
-
-
/**
* @param cdmBase
* @param affectedObjects
*/
public <T extends ICdmBase> void update(T cdmBase, CdmBase affectedObject);
+ /**
+ *
+ */
+ public <T extends CdmBase> void update();
+
package eu.etaxonomy.taxeditor.session;
import java.util.Collection;
+import java.util.Set;
import eu.etaxonomy.cdm.model.common.CdmBase;
public void addSessionObserver(ICdmEntitySessionManagerObserver sessionObserver);
- //FIXME:Remoting would be nice to have these methods working,
- // but they can only be useful if we can 'intelligently'
- // get from a model class to the correspoding service class
-// @SuppressWarnings("unchecked")
-// public abstract <T extends CdmBase> void addRootEntity(T cdmBase);
-//
-// @SuppressWarnings("unchecked")
-// public abstract <T extends Object> void addRootEntities(
-// Collection<T> cdmBaseList);
-
-// public abstract void commit();
-//
-// public abstract void commit(ISessionEventListener sessionOwner);
-//
-// public abstract void commit(IService service, CdmBase cdmBase);
public boolean isRemoting();
+ /**
+ * @param owner
+ */
+ public void dispose(ICdmEntitySessionEnabled owner);
+
+ /**
+ *
+ */
+ public void disposeAll();
+
+ /**
+ * @param cdmBase
+ * @param affectedObjects
+ */
+ public <T extends CdmBase> void update(T cdmBase, Set<CdmBase> affectedObjects);
+
+ /**
+ *
+ */
+ public <T extends CdmBase> void update();
+
}
\ No newline at end of file
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#update()
+ */
+ @Override
+ public <T extends CdmBase> void update() {
+ // TODO Auto-generated method stub
+
+ }
+
}
package eu.etaxonomy.taxeditor.session.mock;
import java.util.Collection;
+import java.util.Set;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
return false;
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#dispose(eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled)
+ */
+ @Override
+ public void dispose(ICdmEntitySessionEnabled owner) {
+
+
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#disposeAll()
+ */
+ @Override
+ public void disposeAll() {
+
+
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#update(eu.etaxonomy.cdm.model.common.CdmBase, java.util.Set)
+ */
+ @Override
+ public <T extends CdmBase> void update(T cdmBase, Set<CdmBase> affectedObjects) {
+
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#update()
+ */
+ @Override
+ public <T extends CdmBase> void update() {
+ // TODO Auto-generated method stub
+
+ }
+
}
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r
</property>\r
<property name="httpInvokerRequestExecutor">\r
<bean\r
- class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+ class="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor" />\r
</property>\r
</bean>\r
\r