- private static boolean canUseRegexQuickFind(final FetchDescendantsOption fetchDescendantsOption,
- final CpsPathQuery cpsPathQuery) {
- return fetchDescendantsOption.equals(FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS)
- && !cpsPathQuery.hasLeafConditions()
- && !cpsPathQuery.hasTextFunctionCondition();
- }
-
- private List<DataNode> getDataNodesUsingRegexQuickFind(final FetchDescendantsOption fetchDescendantsOption,
- final AnchorEntity anchorEntity,
- final CpsPathQuery cpsPathQuery) {
- Collection<FragmentEntity> fragmentEntities;
- final String xpathRegex = FragmentQueryBuilder.getXpathSqlRegex(cpsPathQuery, true);
- final List<FragmentExtract> fragmentExtracts = (anchorEntity == ALL_ANCHORS)
- ? fragmentRepository.quickFindWithDescendantsAcrossAnchor(xpathRegex) :
- fragmentRepository.quickFindWithDescendants(anchorEntity.getId(), xpathRegex);
- fragmentEntities = FragmentEntityArranger.toFragmentEntityTrees(anchorEntity, fragmentExtracts);
- if (cpsPathQuery.hasAncestorAxis()) {
- final Collection<String> ancestorXpaths = processAncestorXpath(fragmentEntities, cpsPathQuery);
- fragmentEntities = (anchorEntity == ALL_ANCHORS) ? getAncestorFragmentEntitiesAcrossAnchors(cpsPathQuery,
- fragmentEntities) : getFragmentEntities(anchorEntity, ancestorXpaths, fetchDescendantsOption);
- }
- return createDataNodesFromFragmentEntities(fetchDescendantsOption, fragmentEntities);
- }
-
- private Collection<FragmentEntity> getAncestorFragmentEntitiesAcrossAnchors(final CpsPathQuery cpsPathQuery,
- final Collection<FragmentEntity> fragmentEntities) {
- final Collection<String> ancestorXpaths = processAncestorXpath(fragmentEntities, cpsPathQuery);
- return ancestorXpaths.isEmpty() ? Collections.emptyList() : fragmentRepository.findAllByXpathIn(ancestorXpaths);
- }
-
- private List<DataNode> createDataNodesFromProxiedFragmentEntities(
- final FetchDescendantsOption fetchDescendantsOption,
- final AnchorEntity anchorEntity,
- final Collection<FragmentEntity> proxiedFragmentEntities) {
- final List<DataNode> dataNodes = new ArrayList<>(proxiedFragmentEntities.size());
- for (final FragmentEntity proxiedFragmentEntity : proxiedFragmentEntities) {
- if (FetchDescendantsOption.OMIT_DESCENDANTS.equals(fetchDescendantsOption)) {
- dataNodes.add(toDataNode(proxiedFragmentEntity, fetchDescendantsOption));
- } else {
- final String normalizedXpath = getNormalizedXpath(proxiedFragmentEntity.getXpath());
- final AnchorEntity anchorEntityForFragmentExtract = (anchorEntity == ALL_ANCHORS)
- ? proxiedFragmentEntity.getAnchor() : anchorEntity;
- final Collection<FragmentEntity> unproxiedFragmentEntities =
- buildFragmentEntitiesFromFragmentExtracts(anchorEntityForFragmentExtract, normalizedXpath);
- for (final FragmentEntity unproxiedFragmentEntity : unproxiedFragmentEntities) {
- dataNodes.add(toDataNode(unproxiedFragmentEntity, fetchDescendantsOption));
- }
- }
- }
- return Collections.unmodifiableList(dataNodes);
- }
-