protected boolean pojoGraphMultipleReferenced(Object obj, Map undoMap) throws CacheException {
// store object in cache
if (obj instanceof Advised) {
CachedType type = cache_.getCachedType(obj.getClass());
// add interceptor
InstanceAdvisor advisor = ((Advised) obj)._getInstanceAdvisor();
if(advisor == null)
throw new RuntimeException("pojoGraphMultipleReferenced(): InstanceAdvisor is null for: " +obj);
BaseInterceptor interceptor = (BaseInterceptor)AopUtil.findCacheInterceptor(advisor);
// just in case
if(interceptor == null)
{
return false;
}
AOPInstance aopInstance = interceptor.getAopInstance();
// Check if there is cross referenced.
if(aopInstance.getRefCount() != 0) return true; // I have been referenced
if(aopInstance.getRefFqn() != null) return true; // I am referencing others
boolean hasFieldAnnotation = hasAnnotation(obj.getClass(), ((Advised)obj)._getAdvisor(), type);
// Check the fields
for (Iterator i = type.getFieldsIterator(); i.hasNext();) {
Field field = (Field) i.next();
Object value = null;
try {
value=field.get(obj);
}
catch(IllegalAccessException e) {
throw new CacheException("field access failed", e);
}
CachedType fieldType = cache_.getCachedType(field.getType());
// we simply treat field that has @Serializable as a primitive type.
if (fieldType.isImmediate() ||
(hasFieldAnnotation &&
CachedType.hasSerializableAnnotation(field, ((Advised)obj)._getAdvisor())))
{
continue;
}
// check for non-replicatable types
if(CachedType.isNonReplicatable(field, ((Advised)obj)._getAdvisor()))
{
continue;
}
if(!hasFieldAnnotation)
{
if(CachedType.hasTransientAnnotation(field, ((Advised)obj)._getAdvisor()))
{
continue;
}
}
// Need to do a getObject just in case this is a failover removeObject.
if(value == null)
value = _getObject(new Fqn(interceptor.getFqn(), field.getName()));
if(value == null) continue; // this is no brainer.
if(pojoGraphMultipleReferenced(value, undoMap)) return true;
}
boolean detachOnly = false;
detachInterceptor(advisor, interceptor, detachOnly, undoMap);
} else if (obj instanceof Map || obj instanceof List || obj instanceof Set)
{
// TODO Is this really necessary?
if(!(obj instanceof ClassProxy)) return false;
InstanceAdvisor advisor = ((ClassProxy)obj)._getInstanceAdvisor();
BaseInterceptor interceptor = (BaseInterceptor)AopUtil.findCollectionInterceptor(advisor);
AOPInstance aopInstance = interceptor.getAopInstance();
if(aopInstance == null) return false; // safeguard
// Check if there is cross referenced.
if(aopInstance.getRefCount() != 0) return true; // I have been referenced