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 net.sf.ehcache.Cache;
import net.sf.ehcache.Element;
sb.append(System.getProperty("line.separator"));
- sb.append(" - " + cei.getField().getName() + ":" + cb.getUserFriendlyTypeName() + "/" + cb.getId());
+ String fieldName = "";
+ if(cei.getField() != null) {
+ fieldName = cei.getField().getName();
+ }
+ sb.append(" - " + fieldName + ":" + cb.getUserFriendlyTypeName() + "/" + cb.getId());
if(cbParent instanceof CdmBase) {
sb.append(" of entity " + ((CdmBase)cbParent).getUserFriendlyTypeName());
return;
}
logger.info("---- starting recursive debug for cdm entity " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId());
- Set<CdmEntityInfo> alreadyVisitedEntities = new HashSet<CdmEntityInfo>();
+ List<CdmEntityInfo> alreadyVisitedEntities = new ArrayList<CdmEntityInfo>();
CdmEntityInfo cei = new CdmEntityInfo(cdmEntity);
debugRecursive(cdmEntity, alreadyVisitedEntities, cei);
rootElements.add(cei);
}
private <T extends Object> void debugRecursive(T obj,
- Set<CdmEntityInfo> alreadyVisitedEntities,
+ List<CdmEntityInfo> alreadyVisitedEntities,
CdmEntityInfo cei) {
if(obj == null) {
return;
}
private <T extends Object> void debug(Map<T,T> map,
- Set<CdmEntityInfo> alreadyVisitedEntities,
+ List<CdmEntityInfo> alreadyVisitedEntities,
CdmEntityInfo cei) {
if(map == null || map.isEmpty()) {
return;
}
private <T extends Object> void debug(Collection<T> collection,
- Set<CdmEntityInfo> alreadyVisitedEntities,
+ List<CdmEntityInfo> alreadyVisitedEntities,
CdmEntityInfo cei) {
int length = collection.size();
Object[] result = new Object[length];
}
private void debugRecursive(CdmBase cdmEntity,
- Set<CdmEntityInfo> alreadyVisitedEntities,
+ List<CdmEntityInfo> alreadyVisitedEntities,
CdmEntityInfo cei) {
+ CdmBase cachedCdmEntityInSubGraph = null;
+
+ if(cei.getObject() instanceof CdmBase) {
+ CdmBase cb = (CdmBase)cei.getObject();
+ cachedCdmEntityInSubGraph = cacher.getFromCache(cb);
+ if(cachedCdmEntityInSubGraph != cb) {
+ // 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(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
// 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
-
+ String f = field;
CdmEntityInfo childCei = getDebugCdmBaseTypeFieldValue(cdmEntity, field, alreadyVisitedEntities, cei);
if(!childCei.isProxy()) {
Object object = childCei.getObject();
private CdmEntityInfo getDebugCdmBaseTypeFieldValue(CdmBase cdmEntity,
String fieldName,
- Set<CdmEntityInfo> alreadyVisitedEntities,
+ List<CdmEntityInfo> alreadyVisitedEntities,
CdmEntityInfo cei) {
CdmEntityInfo childCei = null;
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) {
}
- private CdmEntityInfo getDuplicate(Set<CdmEntityInfo> alreadyVisitedEntities, Object objectToCompare) {
+ private CdmEntityInfo getDuplicate(List<CdmEntityInfo> alreadyVisitedEntities, Object objectToCompare) {
if(objectToCompare != null ) {
for(CdmEntityInfo cei: alreadyVisitedEntities) {
if(objectToCompare.equals(cei.getObject()) && objectToCompare != cei.getObject()) {
return null;
}
- private boolean containsIdenticalCdmEntity(Set<CdmEntityInfo> ceiSet, Object objectToCompare) {
+ private boolean containsIdenticalCdmEntity(List<CdmEntityInfo> ceiSet, Object objectToCompare) {
+ boolean foundIdentical = false;
if(objectToCompare != null) {
for(CdmEntityInfo cei : ceiSet) {
if(cei.getObject() == objectToCompare) {
- return true;
+ foundIdentical = true;
+ } else if(objectToCompare.equals(cei.getObject())) {
+ return false;
}
}
}
- return false;
+ return foundIdentical;
}
public class CdmEntityInfo {