private final NSMutableSet<String> _warned = new NSMutableSet();
protected NSArray indexableObjectsForObject(String type, EOEnterpriseObject object) {
ERXGenericRecord eo = (ERXGenericRecord) object;
EOEditingContext ec = eo.editingContext();
NSMutableSet<EOEnterpriseObject> result = new NSMutableSet();
String entityName = eo.entityName();
ConfigurationEntry config = _configuration.entryForKey(entityName);
if (config != null) {
if (!config.active) {
for (Enumeration e1 = config.notificationKeys.objectEnumerator(); e1.hasMoreElements();) {
String key = (String) e1.nextElement();
Object value = null;
if (type.equals(EOEditingContext.DeletedKey)) {
value = ec.committedSnapshotForObject(eo);
}
EOEntity source = ERXEOAccessUtilities.entityForEo(eo);
if (source.classPropertyNames().containsObject(key)) {
value = eo.valueForKey(key);
} else {
if (eo.isNewObject()) {
if (!_warned.containsObject(entityName)) {
log.error("We currently don't support unsaved related objects for this entity: " + entityName);
_warned.addObject(entityName);
}
} else {
EORelationship rel = source.anyRelationshipNamed(key);
EOKeyGlobalID sourceGlobalID = (EOKeyGlobalID) ec.globalIDForObject(eo);
// AK: I wish I could, but when a relationship
// is
// not a class prop, there's nothing we can do.
// value =
// ec.arrayFaultWithSourceGlobalID(sourceGlobalID,
// rel.name(), ec);
EOFetchSpecification fs = new EOFetchSpecification(rel.destinationEntity().name(), null, null);
NSMutableArray<EOQualifier> qualifiers = new NSMutableArray(rel.joins().count());
NSDictionary pk = source.primaryKeyForGlobalID(sourceGlobalID);
for (Iterator iterator = rel.joins().iterator(); iterator.hasNext();) {
EOJoin join = (EOJoin) iterator.next();
Object pkValue = pk.objectForKey(join.sourceAttribute().name());
EOKeyValueQualifier qualifier = new EOKeyValueQualifier(join.destinationAttribute().name(), EOQualifier.QualifierOperatorEqual, pkValue);
qualifiers.addObject(qualifier);
}
fs.setQualifier(qualifiers.count() == 1 ? qualifiers.lastObject() : new EOAndQualifier(qualifiers));
value = ec.objectsWithFetchSpecification(fs);
}
}
if (value != null) {
NSArray<EOEnterpriseObject> eos = (value instanceof EOEnterpriseObject ? new NSArray(value) : (NSArray) value);
for (EOEnterpriseObject target : eos) {
NSArray targetObjects = indexableObjectsForObject(EOEditingContext.UpdatedKey, target);
result.addObjectsFromArray(targetObjects);
}
}
if (!result.isEmpty() && log.isDebugEnabled()) {
log.debug("re-index: " + eo + "->" + result);
}
}
} else {
result.addObject(eo);
}
}
return result.allObjects();
}