private final JsonObjectMapper jsonObjectMapper;
private final SessionManager sessionManager;
- private static final String REG_EX_FOR_OPTIONAL_LIST_INDEX = "(\\[@[\\s\\S]+?])?)";
+ private static final String REG_EX_FOR_OPTIONAL_LIST_INDEX = "(\\[@.+?])?)";
private static final String QUERY_ACROSS_ANCHORS = null;
private static final AnchorEntity ALL_ANCHORS = null;
}
}
- @Override
- public void storeDataNode(final String dataspaceName, final String anchorName, final DataNode dataNode) {
- storeDataNodes(dataspaceName, anchorName, Collections.singletonList(dataNode));
- }
-
@Override
public void storeDataNodes(final String dataspaceName, final String anchorName,
final Collection<DataNode> dataNodes) {
private static boolean canUseRegexQuickFind(final FetchDescendantsOption fetchDescendantsOption,
final CpsPathQuery cpsPathQuery) {
return fetchDescendantsOption.equals(FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS)
+ && !cpsPathQuery.hasAncestorAxis()
&& !cpsPathQuery.hasLeafConditions()
- && !cpsPathQuery.hasTextFunctionCondition();
+ && !cpsPathQuery.hasTextFunctionCondition()
+ && !cpsPathQuery.hasContainsFunctionCondition();
}
private List<DataNode> getDataNodesUsingRegexQuickFind(final FetchDescendantsOption fetchDescendantsOption,
final AnchorEntity anchorEntity,
final CpsPathQuery cpsPathQuery) {
- Collection<FragmentEntity> fragmentEntities;
- final String xpathRegex = FragmentQueryBuilder.getXpathSqlRegex(cpsPathQuery, true);
+ final String xpathRegex = FragmentQueryBuilder.getXpathSqlRegexForQuickFindWithDescendants(cpsPathQuery);
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);
- }
+ ? fragmentRepository.quickFindWithDescendantsAcrossAnchors(xpathRegex)
+ : fragmentRepository.quickFindWithDescendants(anchorEntity.getId(), xpathRegex);
+ final Collection<FragmentEntity> fragmentEntities =
+ FragmentEntityArranger.toFragmentEntityTrees(anchorEntity, fragmentExtracts);
return createDataNodesFromFragmentEntities(fetchDescendantsOption, fragmentEntities);
}
final CpsPathQuery cpsPathQuery) {
final Set<String> ancestorXpath = new HashSet<>();
final Pattern pattern =
- Pattern.compile("([\\s\\S]*/" + Pattern.quote(cpsPathQuery.getAncestorSchemaNodeIdentifier())
- + REG_EX_FOR_OPTIONAL_LIST_INDEX + "/[\\s\\S]*");
+ Pattern.compile("(.*/" + Pattern.quote(cpsPathQuery.getAncestorSchemaNodeIdentifier())
+ + REG_EX_FOR_OPTIONAL_LIST_INDEX + "/.*");
for (final FragmentEntity fragmentEntity : fragmentEntities) {
final Matcher matcher = pattern.matcher(fragmentEntity.getXpath());
if (matcher.matches()) {
return new DataNodeBuilder()
.withXpath(fragmentEntity.getXpath())
.withLeaves(leaves)
+ .withDataspace(fragmentEntity.getAnchor().getDataspace().getName())
.withAnchor(fragmentEntity.getAnchor().getName())
.withChildDataNodes(childDataNodes).build();
}
fragmentRepository.save(fragmentEntity);
}
- @Override
- public void updateDataNodeAndDescendants(final String dataspaceName, final String anchorName,
- final DataNode dataNode) {
- final AnchorEntity anchorEntity = getAnchorEntity(dataspaceName, anchorName);
- final FragmentEntity fragmentEntity = getFragmentEntity(anchorEntity, dataNode.getXpath());
- updateFragmentEntityAndDescendantsWithDataNode(fragmentEntity, dataNode);
- try {
- fragmentRepository.save(fragmentEntity);
- } catch (final StaleStateException staleStateException) {
- throw new ConcurrencyException("Concurrent Transactions",
- String.format("dataspace :'%s', Anchor : '%s' and xpath: '%s' is updated by another transaction.",
- dataspaceName, anchorName, dataNode.getXpath()));
- }
- }
-
@Override
public void updateDataNodesAndDescendants(final String dataspaceName, final String anchorName,
final Collection<DataNode> updatedDataNodes) {