aemjcrjcr-sql2

JCR SQL2 compare properties on same node


We have some nodes with incorrect properties where cq:title does not equal cq:summary (we want these to always equal). To find them I type:

SELECT * FROM [nt:base] AS s WHERE s.[cq:title] <> s.[cq:summary]

I get the error:

expected: static operand

I read that we cannot compare properties under the same node. I need a workaround please!


Solution

  • I suggest writing a small servlet that iterates over all pages and does the comparision on JCR property level.

    Using a recursive methode this is rather easy to acomplish, just resolve the root from where you want to check and call the method:

    private void checkChildren(Page parent) {
        Iterator<Page> children = parent.listChildren();
        while (children.hasNext()) {
            Page child = children.next();
            ValueMap props = child.getProperties();
            String title = props.get("jcr:title", String.class);
            String summary = props.get("jcr:summary", String.class);
            if (title != null && summary!=null && !title.equals(summary)) {
                //do something with it
            }
            checkChildren(child);
        }
    }