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
0 answers

SQL2 query to search current path(defined in pathfield or RTE) in path

How to perform the following using sql2 query: Requirement: path: /content/consumer go one node level, for example : /content/consumer/en-us search for String authored in a pathfield like "/content/consumer/en-us" if (current Node != Pathfield)…
Ajay
  • 421
  • 3
  • 17
1
vote
2 answers

Node Identifier of copied node in Jackrabbit not found while deleting

I copied a node in Jackrabbit using session.getWorkspace().copy(sourceNode.getPath(), destinationNode.getPath()) This operation changes are persisted instantly as far as I know. But when I tried to get the copied node for deleting it using…
Gandhi
  • 11,875
  • 4
  • 39
  • 63
1
vote
0 answers

AEM 6.2 JCR query on node property instead of JCR creation/modifiy/publish date?

I am trying to write a query where I can get content from a location in AEM dated from today's day back 24 months, but the date is not based on the publish/modify/creation date. They are asking for the dates to be based on the content called the…
1
vote
1 answer

Jackrabbit Oak Indexing

I'm executing this JCR SQL2 query: SELECT * FROM [my:type] AS n WHERE NAME(n) LIKE 'node_name_prefix.%' AND n.deleted = CAST('false' AS BOOLEAN) AND CONTAINS(n.user, '1f12f97d-6516-48b9-ae75-47d17ef6877f') AND CONTAINS(n.state, 'executing') OR…
funfried
  • 605
  • 3
  • 14
1
vote
1 answer

How to Query Jackrabbit for same name siblings

Is it possible to find the same-name siblings (SNS) using JCR-SQL2, JCR-SQL or QueryBuilder in Adobe CQ5/Adobe Experience Manager. I'm trying to match those nodes with a query having the following criteria without having to traverse the whole…
d33t
  • 1,143
  • 6
  • 15
1
vote
3 answers

Recursive search in JCR repo via java

I know how to search for something in the JCR via JCR SQL2 queries. However, I would like to use Java in certain cases, using the JCR API: javax.jcr.Node, javax.jcr.NodeIterator and the like. I'm afraid I will simply reinvent the wheel by coding my…
Adriano
  • 19,463
  • 19
  • 103
  • 140
1
vote
0 answers

How to get parent "node" based on property or name of a descendant node using XPath or SQL@ query?

I am writing a standalone program to get all the page nodes which have a certain descendant node. Ex - if structure is like this - - parent - jcr:content -node1 -node2 -node3 -node4 I want the parent node based on…
Agrawal.P
  • 11
  • 4
1
vote
1 answer

Querybuilder search for only single tag

I am using Querybuilder to search for pages that are tagged with specific tags. The issue is Querybuilder is creating an xpath query that searches for all child tags of the tag along-with the main tag. I want it to search for only the parent tag and…
cqsapientuser
  • 65
  • 3
  • 12
1
vote
0 answers

SQL2 query with equality using a backslash

Issue I have an oak property index on the property somePath When I execute SQL2 queries on this property, like below, I get results: select * from [dam:Asset] as d where d.[jcr:content/metadata/somePath] = 'ABC' However, when I put values with a…
NielsInc
  • 426
  • 7
  • 23
1
vote
3 answers

Magnolia JCR-SQL2 order by Date

In the JCR, I've noticed that dates are stored in the format Feb 19, 2015 12:00:00 AM. This means that when you try and order a query by a date, it doesn't seem to work: SELECT * FROM [mgnl:pages] ORDER BY articlePublishedDate Will return: Apr 1,…
bashaus
  • 1,614
  • 1
  • 17
  • 33
1
vote
1 answer

JCR-SQL2 InvalidQueryException using UNION - expected:

I am trying to use UNION to collect all the unique identifiers(jcr:uuid) of multiple node types and getting an InvalidQueryException, while the actual SELECT statements by themselves are successful. jackrabbit version: 2.12.1 SELECT [jcr:uuid] FROM…
1
vote
1 answer

Using the IN clause with Java's JCR-SQL2

I am trying to use an 'IN' clause with Magnolia with JCR-SQL2: SELECT * FROM [mgnl:page] WHERE [mgnl:template] IN ( "context:pages/template-type-1", "context:pages/template-type-2" ) However I'm receiving this error: SELECT * FROM…
bashaus
  • 1,614
  • 1
  • 17
  • 33
1
vote
2 answers

How to find by a relative path in jcrQuery (Sql2)

I´m trying to find a node by a relative path: I need to search a node which terminates in : 3265 I´m using queries like that: SELECT * from [mgnl:news] AS t WHERE ISSAMENODE([/%/3265]) I need to know how to find a node by a relative path, thanks
Miguel Carrasco
  • 171
  • 1
  • 2
  • 16
1
vote
1 answer

how to find size of a jcr node including its childnodes?

I am using Jackrabbit 2.8.0 and JCR 2.0, I am developing a project for a organization so that it's users can store their documents and directories in digital format using their user account. I want to give size quota limit to all users. For keeping…
Rohit Tiwari
  • 58
  • 1
  • 10
1
vote
1 answer

AEM Find Assets Referenced By Image Components

I'm trying to find pages in AEM 6.1 that reference images from the DAM that are wider than 1280px. I'm really struggling to figure out if this is possible via a single JCR_SQL2 query or not. I've tried many things that have not worked (get…
David Hosier
  • 243
  • 3
  • 12