Questions tagged [jcr-sql2]

JCR-SQL2 is a query language defined by the Java Content Repository 2.0 (JSR-283) specification. It is similar to a subset of SQL but also provides JCR-specific elements. JCR-SQL2 is an improvement over JCR-SQL, the original language defined in JCR 1.0 that was far less like SQL.

JCR-SQL2 queries are simple string statements that include common relational operators:

  • The SELECT clause identifies which JCR properties are to be returned in the tabular result set, and may include aliases
  • The FROM clause identifies the JCR node types (conceptually similar to tables or view) or joins that are to be sources of nodes
  • The optional WHERE clause lists any predicates that must be satisfied before nodes can be included in the results
  • The optional ORDER BY clause the specifies how the results are to be ordered

An example JCR-SQL2 query is this query:

SELECT file.*,content.* FROM [nt:file] AS file 
JOIN [nt:resource] AS content ON ISCHILDNODE(content,file) 
WHERE LOCALNAME(file,'*.txt') AND ISDESCENDANTNODE(file,[/a/b/c])

This query finds all nodes of type nt:file with a name that matches the *.txt pattern that exist somewhere under the /a/b/c node, and the nt:file node's child of type nt:resource node. The result set will minimally include a column for each of the properties defined on nt:file (e.g., "jcr:created" and "jcr:createdBy") and nt:resource (e.g., "jcr:mimeType", "jcr:encoding", "jcr:lastModified", "jcr:lastModifiedBy"); implementations are allowed to return additional columns.

Some JCR implementations (such as Jackrabbit) support only the required grammar, while other JCR implementations (such as ModeShape) support an extended grammar with additional functionality.

The JCR-SQL2 language is surprisingly powerful and flexible, and provide an easy way to find repository content independent of where that content exists in the repository's hierarchical structure of nodes.

Links

105 questions
1
vote
2 answers

JCR_SQL2 how to get distinct and aggregeted results

I am trying to write a query in JCR_SQL2 with no luck. I have a table like below : |property |example value| +---------------+-------------+ |user_name |John Smith | |restaurnat_name|McDonalds | |action |like | …
zalis
  • 1,191
  • 1
  • 11
  • 20
1
vote
0 answers

JCR SQL2 like query with escape not working

This query runs fine: SELECT n.* FROM [nt:unstructured] AS n WHERE n.property LIKE 'value' But this query does not: SELECT n.* FROM [nt:unstructured] AS n WHERE n.property LIKE 'value' ESCAPE '#' The error isn't helpful either: …
James Watkins
  • 4,806
  • 5
  • 32
  • 42
1
vote
1 answer

Querying for shared nodes in JCR (ModeShape)

I have a JCR content repository implemented in ModeShape (4.0.0.Final). The structure of the repository is quite simple and looks like this: / (root) Content/ Item 1 Item 2 Item 3 ... Tags/ Foo/ …
Harald K
  • 26,314
  • 7
  • 65
  • 111
1
vote
2 answers

AEM/CQ: UI for one-off JCR-SQL / SQL2 / XPath queries with tabular output?

I am doing a little usage research in our AEM installation. I would like to find all instances of a component and see what value they have for a certain configuration option. So basically, I want to select the title and myOption properties from all…
SleepyMurph
  • 2,079
  • 2
  • 14
  • 9
1
vote
1 answer

Is there a valid JCR sql2 statement for DeleteAll method?

I followed the statement DELETE [address : Address] where Address is one of the entities. Please help in this regard with possible examples on how to implement DeleteAll method.
Suva
  • 55
  • 2
  • 9
1
vote
1 answer

find "frozenNode" by property

We have our custom node type "ns:Document" with property "ns:id". Is it possible to find node (ns:Document) by property (ns:id) when we increase document version and save new document content with new "ns:id"? this xpath: //element(*)[(@ns:id =…
1
vote
1 answer

Need Jackrabbit sql 2 equivalent query for xpath query

I need a jackrabbit sql 2 equivalent query for this xpath query xpath = "/jcr:root//institutes/institute[*]/(@title | @overallScore)" I have this in place for sql2 I can get '/IN/institues/institute' by using ISCHILDNODE() constraint But I want to…
Sumeet
  • 1,683
  • 20
  • 27
1
vote
0 answers

Apply offset and limit to CQ5 jcr query

I am using a simple SQL based jcr query which goes like : select * from jcr:PageContent where cq:tags like '%tag1%' and cq:template like '%tremplate%' This is working fine but now I need to add an offset and limit to implement pagination. I found…
Riju Mahna
  • 6,718
  • 12
  • 52
  • 91
1
vote
0 answers

Why can't I use the JCR Lucene LENGTH function in SQL2 more than once?

I've been trying to run a particular query on my JCR repository (AEM), and for some reason, I'm not able to use the LENGTH function more than once. This means that the following query runs perfectly fine: SELECT * FROM [cq:PageContent] AS page WHERE…
tzrlk
  • 848
  • 1
  • 13
  • 30
1
vote
1 answer

JCR SQL2 query obviously not delivering any results

I'm trying to create a page for CQ based on the jcr API. I'd like to query pages containing a specific string in a property. The query itself (JCR-SQL2) is the following (I tested it on the CQ Web interface and it delivers results): SELECT …
Ahatius
  • 4,777
  • 11
  • 49
  • 79
1
vote
2 answers

JCR-SQL2 Query Wildcard search not working.

I want to run this JCR SQL2 query: SELECT * FROM [nt:base] WHERE path LIKE '/A/B/%' But after running the query I am getting the following Exception: javax.jcr.query.InvalidQueryException: Query: SELECT * FROM [nt:base] WHERE jcr:(*)path LIKE…
Vaibhav Raj
  • 2,214
  • 4
  • 23
  • 39
0
votes
1 answer

How do I do a multi-level properties query in JCR 2.0 SQL2?

I want to do something like this, but in JCR_SQL2 (since XPATH is now deprecated in JCR 2.0). QueryManager queryManager = session.getWorkspace().getQueryManager(); String queryExpression = …
Kevin Wong
  • 14,656
  • 11
  • 42
  • 52
0
votes
0 answers

JCR-SQL2 Select all nodes that have child node with specific property value

I have the following node structure in the JCR /testNode (mgnl:content) |--- child (mgnl:contentNode) |--- property : value How can I select all nodes of type mgnl:content that have property child.property = 'value' using JCR-SQL2? An…
Haris
  • 138
  • 1
  • 11
0
votes
0 answers

How to query for nodes without children nodes with given name in JCR?

I have the following node structure in the JCR: firstNode (namespace:node1) |-- childNode1 (namespace:node2) |-- ... |-- childNode2 (namespace:node2) |-- ... secondNode (namespace:node1) |-- childNode1 (namespace:node2) …
Haris
  • 138
  • 1
  • 11
0
votes
1 answer

Jackrabbit JCR_SQL2: filter on a path of which only part is known

I need to filter out some files that are in some folder that I don't know the full path of in advance, so I can't use ISDESCENDANTNODE. ¿Is there any other way? ¿Why path can't be cast to string so it can be used in a constraint with LIKE? I have…
Rogenry
  • 71
  • 7