if(_handler.batchSizeForRelationship(ec, relationship) > 0 && !relationship.isToMany()) {
markStart("ToOne.Calculation", source, key);
long timestamp = source.batchFaultingTimeStamp();
boolean fromThreadStorage = false;
NSMutableArray<EOEnterpriseObject> eos = new NSMutableArray<EOEnterpriseObject>();
NSMutableSet faults = new NSMutableSet();
NSArray<EOEnterpriseObject> candidates = null;
NSArray currentObjects = (NSArray) ERXThreadStorage.valueForKey(THREAD_KEY);
if (currentObjects != null) {
NSMutableArray<EOEnterpriseObject> tmpList = new NSMutableArray<EOEnterpriseObject>();
for (Object tmpItem : currentObjects) {
if (tmpItem instanceof AutoBatchFaultingEnterpriseObject) {
tmpList.add((EOEnterpriseObject) tmpItem);
}
}
if (tmpList.count() > 0) {
candidates = tmpList;
fromThreadStorage = true;
}
}
if (candidates == null) {
candidates = ec.registeredObjects();
}
for (EOEnterpriseObject current : candidates) {
if (current instanceof AutoBatchFaultingEnterpriseObject) {
AutoBatchFaultingEnterpriseObject currentEO = (AutoBatchFaultingEnterpriseObject) current;
if(currentEO.batchFaultingTimeStamp() == timestamp || fromThreadStorage) {
if(source.classDescription() == currentEO.classDescription()) {
if(!EOFaultHandler.isFault(currentEO)) {
Object fault = currentEO.storedValueForKey(key);
if(EOFaultHandler.isFault(fault)) {
faults.addObject(fault);
eos.addObject(currentEO);
if(eos.count() == autoBatchFetchSize()) {
break;
}
}
}
}
}
}
}
markEnd("ToOne.Calculation", source, key);
if(eos.count() > 1) {
markStart("ToOne.Fetching", source, key);
doFetch(dbc, ec, relationship, eos);
freshenFetchTimestamps(faults.allObjects(), timestamp);
markEnd("ToOne.Fetching", source, key);
if(batchLog.isDebugEnabled()) {
batchLog.debug("Fetched " + faults.count() + " to-one " + relationship.destinationEntity().name() + " from " + eos.count() + " " + source.entityName() + " for " + key);
}
return EOFaultHandler.isFault(eo);
}
}
}