Source:
public ComponentValidationDiagnostic validate(final IBranchPath branchPath, final SnomedConceptIndexEntry component) { final SnomedIndexServerService indexService = getIndexService(); final DocIdCollector collector = DocIdCollector.create(indexService.maxDoc(branchPath)); final SnomedQueryBuilder relationshipTypeQuery = SnomedMappings.newQuery(); for (final String ungroupedRelationshipTypeId : UNGROUPED_RELATIONSHIP_TYPES) { relationshipTypeQuery.relationshipType(ungroupedRelationshipTypeId); } final Query query = SnomedMappings.newQuery() .active() .relationshipSource(component.getId()) .and(relationshipTypeQuery.matchAny()) .matchAll(); indexService.search(branchPath, query, collector); try { final List<ComponentValidationDiagnostic> diagnostics = Lists.newArrayList(); final DocIdsIterator iterator = collector.getDocIDs().iterator(); while (iterator.next()) { final Document doc = indexService.document(branchPath, iterator.getDocID(), SnomedMappings.fieldsToLoad().id().relationshipType().relationshipGroup().build()); final int relationshipGroup = SnomedMappings.relationshipGroup().getValue(doc); if (relationshipGroup != 0) { final String errorMessage = createErrorMessage(doc, component, branchPath); diagnostics.add(new ComponentValidationDiagnosticImpl(component.getId(), errorMessage, ID, SnomedTerminologyComponentConstants.CONCEPT_NUMBER, error())); } } if (diagnostics.isEmpty()) { return createOk(component.getId(), ID, SnomedTerminologyComponentConstants.CONCEPT_NUMBER); } else { return new ComponentValidationDiagnosticImpl(component.getId(), ID, SnomedTerminologyComponentConstants.CONCEPT_NUMBER, diagnostics); } } catch (final IOException e) { throw new IndexException("Error when evaluating validation constraint.", e); } }

Target:
public ComponentValidationDiagnostic validate(final IBranchPath branchPath, final SnomedConceptIndexEntry component) { final SnomedIndexServerService indexService = getIndexService(); List<ComponentValidationDiagnostic> diagnostics = indexService.executeReadTransaction(branchPath, new IndexRead<List<ComponentValidationDiagnostic>>() { @Override public List<ComponentValidationDiagnostic> execute(IndexSearcher index) throws IOException { DocIdCollector collector = DocIdCollector.create(index.getIndexReader().maxDoc()); final SnomedQueryBuilder relationshipTypeQuery = SnomedMappings.newQuery(); for (final String ungroupedRelationshipTypeId : UNGROUPED_RELATIONSHIP_TYPES) { relationshipTypeQuery.relationshipType(ungroupedRelationshipTypeId); } final Query query = SnomedMappings.newQuery() .active() .relationshipSource(component.getId()) .and(relationshipTypeQuery.matchAny()) .matchAll(); index.search(query, collector); List<ComponentValidationDiagnostic> diagnostics = newArrayList(); DocIdsIterator iterator = collector.getDocIDs().iterator(); while (iterator.next()) { Document doc = index.doc(iterator.getDocID(), SnomedMappings.fieldsToLoad().relationshipType().relationshipGroup().build()); final int relationshipGroup = SnomedMappings.relationshipGroup().getValue(doc); if (relationshipGroup != 0) { String relationshipTypeId = String.valueOf(SnomedMappings.relationshipType().getValue(doc)); final String errorMessage = createErrorMessage(relationshipTypeId, component, branchPath); diagnostics.add(new ComponentValidationDiagnosticImpl(component.getId(), errorMessage, ID, SnomedTerminologyComponentConstants.CONCEPT_NUMBER, error())); } } return diagnostics; } }); if (diagnostics.isEmpty()) { return createOk(component.getId(), ID, SnomedTerminologyComponentConstants.CONCEPT_NUMBER); } else { return new ComponentValidationDiagnosticImpl(component.getId(), ID, SnomedTerminologyComponentConstants.CONCEPT_NUMBER, diagnostics); } }