Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Now, the updated query does not look for a list data node for a given xpath (representing a list Ex: /bookstore/categories). Instead, it looks for all the fragments in the table which have a similar xpath to that of the list followed by opening square bracket starting with "[" and any attribute identified in the query by special symbol "%"and ending with ] using pattern matching.

To make it work we use a combination of LIKE and NOT LIKE keywords.

For this we make use of the LIKE keyword along with % wildcard to make use of pattern matching.

But the above query would also return fragments for xpaths like /bookstore/categories[@code='1']/books[@name="Hello"]

To avoid this scenario, we make use of NOT LIKE keyword along with the same % wildcard. and hence we have [%[% to exclude multiple opening brackets.

Code Block
titleUpdated Query
"SELECT * FROM fragment WHERE
Code Block
titleUpdated Query
WHERE anchor_id = :anchorId "
+ "     AND (xpath = ANY (:xpaths) OR xpath LIKE ANY (array(SELECT concat(t, '[%') FROM unnest(:xpaths) as t)))

So as seen in the above segment of the query, we have "AND (xpath = ANY (:xpaths) OR xpath LIKE ANY (array(SELECT concat(t, '[%') FROM unnest(:xpaths) as t)))".

Any given xpath for a list (Ex: /bookstore/categories) would become like so:

Code Block
(xpath = '/bookstore/categories' OR xpath LIKE '/bookstore/categories[%') + "AND xpath LIKE :escapedXpath||'[%]' ESCAPE '\\' "
            + "AND xpath NOT LIKE :escapedXpath||'[%[%' ESCAPE '\\'"

And this would return 2 fragments as follows.

...