Help with JCR-SQL2 query involving ISCHILDNODE and multiple conjunctions
brmeyer Mar 4, 2015 3:11 PMBackground: [ARTIF-656] Cannot query with 2 relationship predicates - JBoss Issue Tracker
Artificer includes an artifact -> relationship -> target node structure. Relevant bits from the CND:
[sramp:target] - sramp:type (string) - sramp:targetArtifact (weakreference) < 'sramp:baseArtifactType' ... [sramp:relationship] - sramp:relationshipType (string) + * (sramp:target) ... [sramp:baseArtifactType] > mix:created, mix:lastModified, mix:referenceable abstract mixin + * (sramp:relationship) ...
The specific Artificer query looks something like:
/s-ramp/wsdl/Part[relatedDocument[@uuid = '%1$s'] and element]
Ie, find me all "Part" artifacts that have 1.) a relationship of type "relatedDocument" that targets the given UUID and 2.) a relationship of type "element"
So, we need to somehow query for sramp:baseArtifactType nodes that have sramp:relationship children. Those children must include a node with relationshipType "relatedDocument" and another node with "element". Those could be the same sramp:relationship nodes, as well as different ones.
If ModeShape allowed selectors to be transitive, we might be able to do something with "ISCHILDNODE" and the conditions in subselects. But, since it doesn't, our parser uses INNER JOINs. Each time a relationship predicate is hit in an Artificer query, the parser assumes it needs to add a join and conditions. With a conjunction, this fails and results in something like:
SELECT artifact1.* FROM [sramp:baseArtifactType] AS artifact1 INNER JOIN [sramp:relationship] AS relationship2 ON ISCHILDNODE(relationship2,artifact1) INNER JOIN [sramp:target] AS target3 ON ISCHILDNODE(target3,relationship2) INNER JOIN [sramp:baseArtifactType] AS artifact4 ON target3.[sramp:targetArtifact] = artifact4.[jcr:uuid] INNER JOIN [sramp:relationship] AS relationship5 ON ISCHILDNODE(relationship5,artifact1) WHERE artifact1.[sramp:artifactType] = 'Part' AND relationship2.[sramp:relationshipType] = 'relatedDocument' AND artifact4.[sramp:uuid] = 'cea13510-e7a6-4195-a18e-c091eb5a939e' AND relationship5.[sramp:relationshipType] = 'element' AND ISDESCENDANTNODE([sramp:baseArtifactType],'/s-ramp'
The multiple sramp:relationship inner joins are obviously problematic and ModeShape ends up with an assertion failure.
So, if anyone has any ideas about what a JCR-SQL2 query would look like, I'd sincerely appreciate it! In a nutshell, how do you select A, given that it must have children B, where each B selection potentially has its own conditional?