eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmTransientEntityCacher.java -text
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/EntityCacherDebugResult.java -text
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/ICachedCommonService.java -text
+eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/ProxyUtils.java -text
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/server/CDMServerException.java -text
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmPersistentRemoteSource.java -text
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmRemoteSource.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewer.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/reporting/ReportingViewPart.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/sessions/InspectSessionsDialog.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/sessions/SessionsViewPart.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/specimenSearch/SpecimenProviderSelectionComposite.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/specimenSearch/SpecimenProviderSelectionController.java -text
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
import javassist.util.proxy.ProxyFactory;
import net.sf.ehcache.Cache;
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
import org.apache.log4j.Logger;
-import org.hibernate.collection.internal.PersistentList;
-import org.hibernate.collection.internal.PersistentMap;
-import org.hibernate.collection.internal.PersistentSet;
-import org.hibernate.collection.internal.PersistentSortedMap;
-import org.hibernate.collection.internal.PersistentSortedSet;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import eu.etaxonomy.cdm.api.cache.CdmServiceCacher;
import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.cdm.model.common.PersistentMultiLanguageText;
-import eu.etaxonomy.taxeditor.remoting.CdmRemotingException;
-import eu.etaxonomy.taxeditor.remoting.cache.EntityCacherDebugResult.CdmEntityInfo;
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
/**
if(o != null && o instanceof PersistentCollection) {
PersistentCollection pc = ((PersistentCollection)o);
if(pc.wasInitialized()) {
- o = getObject(pc);
+ o = ProxyUtils.getObject(pc);
field.set(cdmEntity, o);
}
}
}
- /******* Debugging section follows *******/
-
- private CdmBase debug(CdmBase cdmEntity) {
- logger.info("debugging object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId());
-
- // start by looking up the cdm entity in the cache
- CdmBase cachedCdmEntity = 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 {
- return cdmEntity;
- }
- }
-
- public EntityCacherDebugResult debug(CdmBase cdmEntity, boolean recursive) {
- if(cdmEntity == null) {
- return null;
- }
- EntityCacherDebugResult entityCacherDebugResult = new EntityCacherDebugResult();
-
- if(isRecursiveEnabled && recursive) {
- logger.info("---- starting recursive debug for cdm entity " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId());
- Set<CdmBase> alreadyVisitedEntities = new HashSet<CdmBase>();
- CdmBase cb = debugRecursive(cdmEntity, alreadyVisitedEntities, entityCacherDebugResult);
- alreadyVisitedEntities.clear();
- logger.info("---- ending recursive debug for cdm entity " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + "\n");
- }
-
- return entityCacherDebugResult;
-
- }
-
- private <T extends Object> T debugRecursive(T obj, Set<CdmBase> alreadyVisitedEntities, EntityCacherDebugResult entityCacherDebugResult) {
- if(obj == null) {
- return null;
- }
- if(obj instanceof CdmBase) {
- return (T) debugRecursive((CdmBase)obj, alreadyVisitedEntities, entityCacherDebugResult);
- } else if (obj instanceof Map) {
- return (T) debug((Map<T,T>)obj, alreadyVisitedEntities, entityCacherDebugResult);
- } else if (obj instanceof Collection) {
- return (T) debug((Collection<T>)obj, alreadyVisitedEntities, entityCacherDebugResult);
- }
-
- logger.info("No caching yet for type " + obj.getClass().getName());
-
- return obj;
- }
-
- private <T extends Object> Map<T,T> debug(Map<T,T> map, Set<CdmBase> alreadyVisitedEntities, EntityCacherDebugResult entityCacherDebugResult){
- if(map == null || map.isEmpty()) {
- return map;
- }
-
- int originalMapSize = map.size();
- Object[] result = new Object[ map.size() * 2 ];
- Iterator<Map.Entry<T,T>> iter = map.entrySet().iterator();
- int i=0;
- while ( iter.hasNext() ) {
- Map.Entry<T,T> e = iter.next();
- result[i++] = e.getKey();
- result[i++] = e.getValue();
- }
-
- for(i=0; i<result.length;i++) {
- if(alreadyVisitedEntities == null) {
- result[i] = load(result[i], false);
- } else {
- result[i] = debugRecursive(result[i], alreadyVisitedEntities, entityCacherDebugResult);
- }
- }
- map.clear();
- for(i = 0; i < originalMapSize; i+=2 ) {
- map.put(
- (T)result[i],
- (T)result[i+1]
- );
- }
- return map;
- }
-
- private <T extends Object> Collection<T> debug(Collection<T> collection, Set<CdmBase> alreadyVisitedEntities, EntityCacherDebugResult entityCacherDebugResult){
- int length = collection.size();
- Object[] result = new Object[length];
- Iterator<T> collectionItr = collection.iterator();
- int count = 0;
- while(collectionItr.hasNext()) {
- Object obj = collectionItr.next();
- if(alreadyVisitedEntities == null) {
- result[count] = load(obj, false);
- } else {
- result[count] = debugRecursive(obj, alreadyVisitedEntities, entityCacherDebugResult);
- }
-
- count++;
- }
-
- collection.clear();
-
- for ( int i = 0; i < length; i++ ) {
- collection.add((T)result[i]);
- }
-
- return collection;
- }
-
- private CdmBase debugRecursive(CdmBase cdmEntity, Set<CdmBase> alreadyVisitedEntities, EntityCacherDebugResult entityCacherDebugResult) {
-
-
-
- // we want to recursive through the cdmEntity (and not the cachedCdmEntity)
- // since there could be new or deleted objects in the cdmEntity sub-graph
-
- // start by getting the fields from the cdm entity
- String className = cdmEntity.getClass().getName();
- CdmModelFieldPropertyFromClass cmgmfc = getFromCdmlibModelCache(className);
- if(cmgmfc != null) {
- alreadyVisitedEntities.add(cdmEntity);
- List<String> fields = cmgmfc.getFields();
- for(String field : fields) {
- // retrieve the actual object corresponding to the field.
- // this object will be either a CdmBase or a Collection / Map
- // with CdmBase as the generic type
-
- CdmBase cdmEntityInSubGraph = getDebugCdmBaseTypeFieldValue(cdmEntity, field, alreadyVisitedEntities, entityCacherDebugResult);
- if(cdmEntityInSubGraph != null) {
- if(!alreadyVisitedEntities.contains(cdmEntityInSubGraph)) {
- logger.info("recursive debugging object of type " + cdmEntityInSubGraph.getClass().getName() + " with id " + cdmEntityInSubGraph.getId());
- debugRecursive(cdmEntityInSubGraph, alreadyVisitedEntities, entityCacherDebugResult);
- } 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 cdmEntity;
- }
-
-
- private CdmBase getDebugCdmBaseTypeFieldValue(CdmBase cdmEntity,
- String fieldName,
- Set<CdmBase> alreadyVisitedEntities,
- EntityCacherDebugResult entityCacherDebugResult) {
-
-
- Class<?> clazz = cdmEntity.getClass();
- try {
- // this call will search in the provided class as well as
- // the super classes until it finds the field
- Field field = ReflectionUtils.findField(clazz, fieldName);
-
- if(field == null) {
- throw new CdmClientCacheException("Field '" + fieldName
- + "' not found when searching in class '" + clazz.getName() + "' and its supercalsses");
- }
- field.setAccessible(true);
- Object o = field.get(cdmEntity);
- if(o != null && o instanceof HibernateProxy) {
- LazyInitializer hli = ((HibernateProxy)o).getHibernateLazyInitializer();
- if(!hli.isUninitialized()) {
- o = hli.getImplementation();
- }
- }
-
- if(o != null && o instanceof PersistentCollection) {
- PersistentCollection pc = ((PersistentCollection)o);
- if(pc.wasInitialized()) {
- o = getObject(pc);
- }
- }
- CdmBase cdmEntityInSubGraph = null;
- if(o != null
- && !ProxyFactory.isProxyClass(o.getClass())
- && !(o instanceof PersistentCollection) ) {
-
- 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;
- for(CdmBase visitedEntity : alreadyVisitedEntities) {
- if(cdmEntityInSubGraph.equals(visitedEntity) && cdmEntityInSubGraph != visitedEntity) {
- //logger.info(" - found duplicate entity at " + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
- CdmEntityInfo cei = entityCacherDebugResult.new CdmEntityInfo(cdmEntityInSubGraph, cdmEntity, field);
- CdmEntityInfo dupCei = entityCacherDebugResult.new CdmEntityInfo(visitedEntity, null, field);
- entityCacherDebugResult.addDuplicateEntity(cei, dupCei);
- }
- }
-
- CdmBase cachedCdmEntityInSubGraph = 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
-
- if(cachedCdmEntityInSubGraph == null) {
- // found a cdm entity which is not in cache - need to record this
- //logger.info(" - found entity not in cache " + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
- CdmEntityInfo cei = entityCacherDebugResult.new CdmEntityInfo(cdmEntityInSubGraph, cdmEntity, field);
- entityCacherDebugResult.addEntityNotInCache(cei);
- }
- } else if(o instanceof Map) {
- debugRecursive((Map)o, alreadyVisitedEntities, entityCacherDebugResult);
- } else if(o instanceof Collection) {
- debugRecursive((Collection)o, alreadyVisitedEntities, entityCacherDebugResult);
- }
- }
- // we return the original cdm entity in the sub graph because we
- // want to continue to recurse on the input cdm entity graph
- // and not the one in the cache
- return cdmEntityInSubGraph;
- } catch (SecurityException e) {
- throw new CdmClientCacheException(e);
- } catch (IllegalArgumentException e) {
- throw new CdmClientCacheException(e);
- } catch (IllegalAccessException e) {
- throw new CdmClientCacheException(e);
- }
- }
-
- public static Object getObject(PersistentCollection pc) {
- if(pc != null) {
- if(pc instanceof PersistentSet) {
- return new HashSet((Set)pc);
- }
- if(pc instanceof PersistentSortedSet) {
- return new TreeSet((Set)pc);
- }
- if(pc instanceof PersistentList) {
- return new ArrayList((List)pc);
- }
- if(pc instanceof PersistentMap || pc instanceof PersistentMultiLanguageText) {
- return new HashMap((Map)pc);
- }
- if(pc instanceof PersistentSortedMap) {
- return new TreeMap((Map)pc);
- }
- throw new CdmRemotingException("Cannot get Collection field for type " + pc.getClass().getName());
- }
- return null;
- }
}
import java.lang.reflect.Field;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import javassist.util.proxy.ProxyFactory;
+
+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;
+
import eu.etaxonomy.cdm.model.common.CdmBase;
/**
*/
public class EntityCacherDebugResult {
- private final Map<CdmEntityInfo, CdmEntityInfo> duplicateCdmEntityMap;
+ private static final Logger logger = Logger.getLogger(EntityCacherDebugResult.class);
+
+ private Map<CdmEntityInfo, CdmEntityInfo> duplicateCdmEntityMap;
- private final List<CdmEntityInfo> notInCacheList;
+ private List<CdmEntityInfo> notInCacheList;
+
+ private CdmTransientEntityCacher cacher;
+
+ private List<CdmEntityInfo> rootElements;
public EntityCacherDebugResult() {
+ }
+
+
+ public <T extends CdmBase> EntityCacherDebugResult(CdmTransientEntityCacher cacher, List<T> rootEntities) {
+ this.cacher = cacher;
+ init();
+ if(rootEntities != null && !rootEntities.isEmpty()) {
+ for(CdmBase rootEntity : rootEntities) {
+ debug(rootEntity, true);
+ print();
+ clear();
+ }
+
+ }
+ }
+
+ private void init() {
duplicateCdmEntityMap = new HashMap<CdmEntityInfo, CdmEntityInfo>();
notInCacheList = new ArrayList<CdmEntityInfo>();
+ rootElements = new ArrayList<CdmEntityInfo>();
+ }
+
+ private void clear() {
+ duplicateCdmEntityMap.clear();
+ notInCacheList.clear();
}
public void addDuplicateEntity(CdmEntityInfo cei, CdmEntityInfo cachedCei) {
notInCacheList.add(cei);
}
- public void print() {
+ public List<CdmEntityInfo> getRootElements() {
+ return rootElements;
+ }
+
+ private void print() {
System.out.println(toString());
}
{
sb.append(System.getProperty("line.separator"));
CdmEntityInfo cei = entry.getKey();
- CdmEntityInfo cachedCei = entry.getValue();
- sb.append(" - entity : " + cei.getCb().getUserFriendlyTypeName() + "/" + cei.getCb().getId() +
+ CdmBase cb = (CdmBase) cei.getObject();
+ CdmBase cbParent = (CdmBase) cei.getParent().getObject();
+
+ CdmEntityInfo dupCei = entry.getValue();
+ CdmBase dupCb = (CdmBase) dupCei.getObject();
+ CdmBase dupCbParent = (CdmBase) dupCei.getParent().getObject();
+
+ sb.append(" - entity : " + cb.getUserFriendlyTypeName() + "/" + cb.getId() +
" as field " + cei.getField().getName() +
- " of entity " + cei.getCbOwner().getUserFriendlyTypeName() + "/" + cei.getCbOwner().getId());
+ " of entity " + cbParent.getUserFriendlyTypeName() + "/" + cbParent.getId());
sb.append(System.getProperty("line.separator"));
- sb.append(" - duplicate entity : " + cachedCei.getCb().getUserFriendlyTypeName() + "/" + cachedCei.getCb().getId() +
- " as field " + cachedCei.getField().getName());
+ sb.append(" - duplicate entity : " + dupCb.getUserFriendlyTypeName() + "/" + dupCb.getId() +
+ " as field " + dupCei.getField().getName() +
+ " of entity " + dupCbParent.getUserFriendlyTypeName() + "/" + dupCbParent.getId());
sb.append(System.getProperty("line.separator"));
sb.append("-----------");
}
sb.append("Not In Cache Entities,");
for(CdmEntityInfo cei : notInCacheList) {
+ CdmBase cb = (CdmBase) cei.getObject();
+ CdmBase cbParent = (CdmBase) cei.getParent().getObject();
+
sb.append(System.getProperty("line.separator"));
- sb.append(" - entity : " + cei.getCb().getUserFriendlyTypeName() + "/" + cei.getCb().getId() +
+
+ sb.append(" - entity : " + cb.getUserFriendlyTypeName() + "/" + cb.getId() +
" as field " + cei.getField().getName() +
- " of entity" + cei.getCbOwner().getUserFriendlyTypeName() + "/" + cei.getCbOwner().getId());
+ " of entity" + cbParent.getUserFriendlyTypeName() + "/" + cbParent.getId());
}
}
}
+ private void debug(CdmBase cdmEntity, boolean recursive) {
+ if(cdmEntity == null) {
+ return;
+ }
+ logger.info("---- starting recursive debug for cdm entity " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId());
+ IdentityHashMap<Object, CdmEntityInfo> alreadyVisitedEntities = new IdentityHashMap<Object, CdmEntityInfo>();
+ CdmEntityInfo cei = new CdmEntityInfo(cdmEntity);
+ debugRecursive(cdmEntity, alreadyVisitedEntities, cei);
+ rootElements.add(cei);
+ alreadyVisitedEntities.clear();
+ logger.info("---- ending recursive debug for cdm entity " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + "\n");
+ }
+
+ private <T extends Object> void debugRecursive(T obj,
+ IdentityHashMap<Object, CdmEntityInfo> alreadyVisitedEntities,
+ CdmEntityInfo cei) {
+ if(obj == null) {
+ return;
+ }
+ if(obj instanceof CdmBase) {
+ debugRecursive((CdmBase)obj, alreadyVisitedEntities, cei);
+ } else if (obj instanceof Map) {
+ debug((Map<T,T>)obj, alreadyVisitedEntities, cei);
+ } else if (obj instanceof Collection) {
+ debug((Collection<T>)obj, alreadyVisitedEntities, cei);
+ }
+
+ logger.info("No caching yet for type " + obj.getClass().getName());
+
+
+ }
+
+ private <T extends Object> void debug(Map<T,T> map,
+ IdentityHashMap<Object, CdmEntityInfo> alreadyVisitedEntities,
+ CdmEntityInfo cei) {
+ if(map == null || map.isEmpty()) {
+ return;
+ }
+
+ int originalMapSize = map.size();
+
+ Iterator<Map.Entry<T,T>> iter = map.entrySet().iterator();
+ int i=0;
+ while ( iter.hasNext() ) {
+ Map.Entry<T,T> e = iter.next();
+ CdmEntityInfo childCei = new CdmEntityInfo(e);
+ cei.addChild(childCei);
+ debugRecursive(e.getKey(), alreadyVisitedEntities, childCei);
+ debugRecursive(e.getValue(), alreadyVisitedEntities, childCei);
+ }
+ }
+
+ private <T extends Object> void debug(Collection<T> collection,
+ IdentityHashMap<Object, CdmEntityInfo> alreadyVisitedEntities,
+ CdmEntityInfo cei) {
+ int length = collection.size();
+ Object[] result = new Object[length];
+ Iterator<T> collectionItr = collection.iterator();
+
+ while(collectionItr.hasNext()) {
+ Object obj = collectionItr.next();
+ CdmEntityInfo childCei = new CdmEntityInfo(obj);
+ cei.addChild(childCei);
+ debugRecursive(obj, alreadyVisitedEntities, childCei);
+
+ }
+
+ }
+
+ private void debugRecursive(CdmBase cdmEntity,
+ IdentityHashMap<Object, CdmEntityInfo> alreadyVisitedEntities,
+ CdmEntityInfo cei) {
+
+ // we want to recursive through the cdmEntity (and not the cachedCdmEntity)
+ // since there could be new or deleted objects in the cdmEntity sub-graph
+
+ // start by getting the fields from the cdm entity
+ String className = cdmEntity.getClass().getName();
+ CdmModelFieldPropertyFromClass cmgmfc = cacher.getFromCdmlibModelCache(className);
+ if(cmgmfc != null) {
+ alreadyVisitedEntities.put(cdmEntity, cei);
+ List<String> fields = cmgmfc.getFields();
+ for(String field : fields) {
+ // retrieve the actual object corresponding to the field.
+ // this object will be either a CdmBase or a Collection / Map
+ // with CdmBase as the generic type
+
+ CdmEntityInfo childCei = getDebugCdmBaseTypeFieldValue(cdmEntity, field, alreadyVisitedEntities, cei);
+ CdmBase cdmEntityInSubGraph = (CdmBase)childCei.getObject();
+ if(cdmEntityInSubGraph != null) {
+ if(!alreadyVisitedEntities.keySet().contains(cdmEntityInSubGraph)) {
+ logger.info("recursive debugging object of type " + cdmEntityInSubGraph.getClass().getName() + " with id " + cdmEntityInSubGraph.getId());
+ debugRecursive(cdmEntityInSubGraph, alreadyVisitedEntities, childCei);
+ } 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" );
+ }
+
+ }
+
+
+ private CdmEntityInfo getDebugCdmBaseTypeFieldValue(CdmBase cdmEntity,
+ String fieldName,
+ IdentityHashMap<Object, CdmEntityInfo> alreadyVisitedEntities,
+ CdmEntityInfo cei) {
+
+ CdmEntityInfo childCei = null;
+ Class<?> clazz = cdmEntity.getClass();
+ try {
+ // this call will search in the provided class as well as
+ // the super classes until it finds the field
+ Field field = ReflectionUtils.findField(clazz, fieldName);
+
+ if(field == null) {
+ throw new CdmClientCacheException("Field '" + fieldName
+ + "' not found when searching in class '" + clazz.getName() + "' and its supercalsses");
+ }
+ field.setAccessible(true);
+ Object o = field.get(cdmEntity);
+ if(o != null) {
+ if(o instanceof HibernateProxy) {
+ LazyInitializer hli = ((HibernateProxy)o).getHibernateLazyInitializer();
+ if(!hli.isUninitialized()) {
+ o = hli.getImplementation();
+ }
+ }
+
+ if(o instanceof PersistentCollection) {
+ PersistentCollection pc = ((PersistentCollection)o);
+ if(pc.wasInitialized()) {
+ o = ProxyUtils.getObject(pc);
+ }
+ }
+ }
+ childCei = new CdmEntityInfo(o);
+ cei.addChild(childCei);
+ childCei.setField(field);
+ CdmBase cdmEntityInSubGraph = null;
+ if(o != null
+ && !ProxyFactory.isProxyClass(o.getClass())
+ && !(o instanceof PersistentCollection) ) {
+
+ 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;
+
+ if(alreadyVisitedEntities.keySet().contains(cdmEntityInSubGraph)) {
+ //logger.info(" - found duplicate entity at " + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
+ CdmEntityInfo dupCei = alreadyVisitedEntities.get(cdmEntityInSubGraph);
+ addDuplicateEntity(childCei, dupCei);
+ }
+
+
+ CdmBase cachedCdmEntityInSubGraph = cacher.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
+ if(cachedCdmEntityInSubGraph == null) {
+ // found a cdm entity which is not in cache - need to record this
+ //logger.info(" - found entity not in cache " + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
+ addEntityNotInCache(childCei);
+ }
+ } else if(o instanceof Map) {
+ debugRecursive((Map)o, alreadyVisitedEntities, childCei);
+ } else if(o instanceof Collection) {
+ debugRecursive((Collection)o, alreadyVisitedEntities, childCei);
+ }
+ }
+ // we return the original cdm entity in the sub graph because we
+ // want to continue to recurse on the input cdm entity graph
+ // and not the one in the cache
+ return childCei;
+ } catch (SecurityException e) {
+ throw new CdmClientCacheException(e);
+ } catch (IllegalArgumentException e) {
+ throw new CdmClientCacheException(e);
+ } catch (IllegalAccessException e) {
+ throw new CdmClientCacheException(e);
+ }
+ }
+
+
+
public class CdmEntityInfo {
- private final CdmBase cb;
- private final CdmBase cbOwner;
- private final Field field;
+ private final Object object;
+ private CdmEntityInfo parent;
+ private List<CdmEntityInfo> children;
+ private Field field;
+ private String label;
- public CdmEntityInfo(CdmBase cb, CdmBase cbOwner, Field field) {
- this.cb = cb;
- this.cbOwner = cbOwner;
- this.field = field;
+ public CdmEntityInfo(Object object) {
+ this.object = object;
+ children = new ArrayList<CdmEntityInfo>();
+ }
+
+ public CdmEntityInfo getParent() {
+ return parent;
+ }
+
+ public void setParent(CdmEntityInfo parent) {
+ this.parent = parent;
+ }
+
+ public List<CdmEntityInfo> getChildren() {
+ return children;
}
- public CdmBase getCb() {
- return cb;
+ public void setChildren(List<CdmEntityInfo> children) {
+ this.children = children;
}
- public CdmBase getCbOwner() {
- return cbOwner;
+ public void addChild(CdmEntityInfo cei) {
+ this.children.add(cei);
+ cei.setParent(this);
}
public Field getField() {
return field;
}
- @Override
- public boolean equals(Object obj) {
- if(obj instanceof CdmEntityInfo & obj == this) {
- return true;
+ public void setField(Field field) {
+ this.field = field;
+ }
+
+
+ public String getLabel() {
+ String label;
+ String fieldName = "";
+ if(field != null) {
+ fieldName = field.getName();
+ }
+ if(object != null) {
+ if(object instanceof HibernateProxy) {
+ LazyInitializer hli = ((HibernateProxy)object).getHibernateLazyInitializer();
+ if(hli.isUninitialized()) {
+ label = "[HibernateProxy] " + fieldName;
+ } else {
+ label = fieldName + "Object is a HibernateProxy, but initialised";
+ }
+ } else if(object instanceof PersistentCollection) {
+ PersistentCollection pc = ((PersistentCollection)object);
+ if(!pc.wasInitialized()) {
+ label = "[PersistentCollection] " + fieldName;
+ } else {
+ label = fieldName + "Object is a PersistentCollection, but initialised";
+ }
+ } else if(object instanceof Collection) {
+ String className = object.getClass().getName();
+ label = "[" + className + "] " + fieldName + String.valueOf(((Collection)object).size());
+ } else if(object instanceof Map) {
+ String className = object.getClass().getName();
+ label = "[" + className + "] " + fieldName + String.valueOf(((Map)object).size());
+ } else {
+ String className = object.getClass().getName();
+ label = "[" + className + "] " + fieldName;
+ }
} else {
- return false;
+ label = "[NULL] " + fieldName;
}
+ return label;
}
- @Override
- public int hashCode() {
- return this.cb.hashCode();
+ public void setLabel(String label) {
+ this.label = label;
}
+
+ public Object getObject() {
+ return object;
+ }
+
+
+
}
}
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 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.remoting.cache;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.hibernate.collection.internal.PersistentList;
+import org.hibernate.collection.internal.PersistentMap;
+import org.hibernate.collection.internal.PersistentSet;
+import org.hibernate.collection.internal.PersistentSortedMap;
+import org.hibernate.collection.internal.PersistentSortedSet;
+import org.hibernate.collection.spi.PersistentCollection;
+
+import eu.etaxonomy.cdm.model.common.PersistentMultiLanguageText;
+import eu.etaxonomy.taxeditor.remoting.CdmRemotingException;
+
+/**
+ * @author cmathew
+ * @date 17 Feb 2015
+ *
+ */
+public class ProxyUtils {
+
+ public static Object getObject(PersistentCollection pc) {
+ if(pc != null) {
+ if(pc instanceof PersistentSet) {
+ return new HashSet((Set)pc);
+ }
+ if(pc instanceof PersistentSortedSet) {
+ return new TreeSet((Set)pc);
+ }
+ if(pc instanceof PersistentList) {
+ return new ArrayList((List)pc);
+ }
+ if(pc instanceof PersistentMap || pc instanceof PersistentMultiLanguageText) {
+ return new HashMap((Map)pc);
+ }
+ if(pc instanceof PersistentSortedMap) {
+ return new TreeMap((Map)pc);
+ }
+ throw new CdmRemotingException("Cannot get Collection field for type " + pc.getClass().getName());
+ }
+ return null;
+ }
+
+}
package eu.etaxonomy.taxeditor.session;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import net.sf.ehcache.statistics.LiveCacheStatistics;
import org.apache.log4j.Logger;
-import org.apache.poi.ss.formula.functions.T;
import eu.etaxonomy.cdm.api.service.IService;
import eu.etaxonomy.cdm.model.common.CdmBase;
private final List<ICdmEntitySessionEnabled> changeObservers;
- private final List<T> rootEntities;
+
public CdmEntitySession(ICdmEntitySessionEnabled sessionOwner, CdmEntitySessionManager cdmEntitySessionManager) {
this.sessionOwner = sessionOwner;
this.cdmTransientEntityCacher = new CdmTransientEntityCacher(sessionOwner, cdmEntitySessionManager);
- this.rootEntities = new ArrayList<T>();
this.cdmEntitySessionManager = cdmEntitySessionManager;
this.changeObservers = new ArrayList<ICdmEntitySessionEnabled>();
cdmEntitySessionManager.addToOwnerSessionMap(sessionOwner, this);
*/
@Override
public <T extends CdmBase> EntityCacherDebugResult debug(T cdmBase) {
- EntityCacherDebugResult entityCacherDebugResult = cdmTransientEntityCacher.debug(cdmBase, true);
- entityCacherDebugResult.print();
+ return debug(Arrays.asList(cdmBase));
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#debug(java.util.List)
+ */
+ @Override
+ public <T extends CdmBase> EntityCacherDebugResult debug(List<T> cdmBases) {
+ EntityCacherDebugResult entityCacherDebugResult =
+ new EntityCacherDebugResult(cdmTransientEntityCacher, cdmBases);
return entityCacherDebugResult;
}
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#debug()
+ */
+ @Override
+ public <T extends CdmBase> EntityCacherDebugResult debug() {
+ return debug(getRootEntities());
+ }
+
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#load(java.util.Collection)
*/
*/
@Override
public void dispose() {
- rootEntities.clear();
+
cdmTransientEntityCacher.dispose();
for(ICdmEntitySessionEnabled observer : changeObservers) {
CdmPostDataChangeObservableListener.getDefault().unregister(observer);
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#getRootEntities()
+ */
+ @Override
+ public <T extends CdmBase> List<T> getRootEntities() {
+ return sessionOwner.getRootEntities();
+ }
+
+
+
public <T extends CdmBase> EntityCacherDebugResult debug(T cdmBase);
+ public <T extends CdmBase> EntityCacherDebugResult debug(List<T> cdmBase);
+
+ public <T extends CdmBase> EntityCacherDebugResult debug();
+
public <T extends CdmBase> Collection<T> load(Collection<T> cdmBaseList);
public void setEntitiesAsLatest();
+ public <T extends CdmBase> List<T> getRootEntities();
+
public void dispose();
public void bind();
package eu.etaxonomy.taxeditor.session;
+import java.util.List;
+
+import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver;
public interface ICdmEntitySessionEnabled extends ICdmPostDataChangeObserver {
public ICdmEntitySession getCdmEntitySession();
+ public <T extends CdmBase> List<T> getRootEntities();
+
}
return false;
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#getRootEntities()
+ */
+ @Override
+ public <T extends CdmBase> List<T> getRootEntities() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#debug(java.util.List)
+ */
+ @Override
+ public <T extends CdmBase> EntityCacherDebugResult debug(List<T> cdmBase) {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#debug()
+ */
+ @Override
+ public <T extends CdmBase> EntityCacherDebugResult debug() {
+
+ return null;
+ }
+
}
*/
package eu.etaxonomy.taxeditor.editor;
-import java.util.List;
-
import eu.etaxonomy.cdm.api.service.IService;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
cdmEntitySession.remoteUpdate(getService(), cdmBase);
}
- public abstract <T extends CdmBase> List<T> getRootEntities();
public abstract <T extends CdmBase> void update();
}
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
public ICdmEntitySession getCdmEntitySession() {
return cdmEntitySession;
}
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
+ */
+ @Override
+ public List<TaxonNode> getRootEntities() {
+ return input.getRootEntities();
+ }
}
*/
package eu.etaxonomy.taxeditor.editor.key.polytomous;
+import java.util.Arrays;
+import java.util.List;
import java.util.UUID;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
public ICdmEntitySession getCdmEntitySession() {
return cdmEntitySession;
}
+
+
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
+ */
+ @Override
+ public List<PolytomousKey> getRootEntities() {
+ return Arrays.asList(key);
+ }
}
return editor.getCdmEntitySession();
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
+ */
+ @Override
+ public <T extends CdmBase> List<T> getRootEntities() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
return null;
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
+ */
+ @Override
+ public <T extends CdmBase> List<T> getRootEntities() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
public ICdmEntitySession getCdmEntitySession() {
return cdmEntitySession;
}
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
+ */
+ @Override
+ public <T extends CdmBase> List<T> getRootEntities() {
+ return null;
+ }
}
package eu.etaxonomy.taxeditor.view;
+import java.util.Arrays;
+import java.util.List;
+
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
return null;
}
+ @Override
+ public List<CdmBase> getRootEntities() {
+ return Arrays.asList((CdmBase)getViewer().getInput());
+ }
+
/** {@inheritDoc} */
@Override
public void update(CdmDataChangeMap changeEvents) {
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 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.view.sessions;
+
+import java.util.List;
+
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.Element;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.wb.swt.SWTResourceManager;
+
+import eu.etaxonomy.taxeditor.remoting.cache.CdmModelFieldPropertyFromClass;
+import eu.etaxonomy.taxeditor.remoting.cache.CdmRemoteCacheManager;
+import eu.etaxonomy.taxeditor.remoting.cache.EntityCacherDebugResult;
+import eu.etaxonomy.taxeditor.remoting.cache.EntityCacherDebugResult.CdmEntityInfo;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author cmathew
+ * @date 17 Feb 2015
+ *
+ */
+public class InspectSessionsDialog extends Dialog {
+
+ protected Object result;
+ protected Shell shlInspectSessions;
+ private Text text;
+ private Label lblDebugInformation;
+
+ private final Cache cdmlibModelCache;
+
+ private final ICdmEntitySession activeSession;
+
+ private TreeViewer treeViewer;
+ /**
+ * Create the dialog.
+ * @param parent
+ * @param style
+ */
+ public InspectSessionsDialog(Shell parent, int style) {
+ super(parent, style);
+ setText("SWT Dialog");
+ cdmlibModelCache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
+ activeSession = CdmStore.getCurrentSessionManager().getActiveSession();
+ }
+
+ /**
+ * Open the dialog.
+ * @return the result
+ */
+ public Object open() {
+ createContents();
+ treeViewer.setContentProvider(new SessionsTreeContentProvider());
+ treeViewer.setLabelProvider(new SessionsTreeLabelProvider());
+ treeViewer.setInput(getRootElements());
+ shlInspectSessions.open();
+ shlInspectSessions.layout();
+ Display display = getParent().getDisplay();
+ while (!shlInspectSessions.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Create contents of the dialog.
+ */
+ private void createContents() {
+ shlInspectSessions = new Shell(getParent(), getStyle());
+ shlInspectSessions.setSize(641, 529);
+ shlInspectSessions.setText("Inspect Sessions");
+ shlInspectSessions.setLayout(new GridLayout(1, false));
+
+ TreeViewer treeViewer = new TreeViewer(shlInspectSessions, SWT.BORDER);
+ Tree tree = treeViewer.getTree();
+ tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+
+ lblDebugInformation = new Label(shlInspectSessions, SWT.NONE);
+ lblDebugInformation.setFont(SWTResourceManager.getFont("Ubuntu", 10, SWT.NORMAL));
+ lblDebugInformation.setText("Debug Information :");
+
+ text = new Text(shlInspectSessions, SWT.BORDER);
+ text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+
+ }
+
+ private CdmEntityInfo[] getRootElements() {
+ EntityCacherDebugResult ecdr = activeSession.debug();
+ return (CdmEntityInfo[]) ecdr.getRootElements().toArray();
+ }
+
+ class SessionsTreeContentProvider implements ITreeContentProvider {
+
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ @Override
+ public void dispose() {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
+ */
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return (CdmEntityInfo[])inputElement;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ List<CdmEntityInfo> children = ((CdmEntityInfo)parentElement).getChildren();
+ return children.toArray();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ @Override
+ public Object getParent(Object element) {
+ CdmEntityInfo cei = (CdmEntityInfo)element;
+ return cei.getParent();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ @Override
+ public boolean hasChildren(Object element) {
+ List<CdmEntityInfo> children = ((CdmEntityInfo)element).getChildren();
+ if(children != null && !children.isEmpty()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public CdmModelFieldPropertyFromClass getFromCdmlibModelCache(String className) {
+ Element e = cdmlibModelCache.get(className);
+ if (e == null) {
+ return null;
+ } else {
+ return (CdmModelFieldPropertyFromClass) e.getObjectValue();
+ }
+ }
+
+ }
+
+ class SessionsTreeLabelProvider extends StyledCellLabelProvider {
+
+ @Override
+ public void update(ViewerCell cell) {
+ CdmEntityInfo cei = (CdmEntityInfo)cell.getElement();
+ StyledString text = new StyledString();
+ if(cei != null) {
+ text.append(cei.getLabel());
+ }
+ cell.setText(text.toString());
+ cell.setStyleRanges(text.getStyleRanges());
+ super.update(cell);
+ }
+ }
+}
+
+
*/
package eu.etaxonomy.cdm.model;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Taxon taxon = CdmBase.deproxy(taxonService.find(taxon1Uuid),Taxon.class);
pkeynode.getChildAt(1).setTaxon(taxon);
- EntityCacherDebugResult debugResult = cacher.debug(pkey, true);
- debugResult.print();
+ EntityCacherDebugResult debugResult = new EntityCacherDebugResult(cacher, Arrays.asList(pkey));
+
polytomousKeyService.merge(pkey);
pkey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);