3

I have some records stored as Nodes in JCR and the name of the node is the primary key. eg 1,2,3. But the problem starts here,

the records are as follows 1,2,6,53,54

Where the numbers above are nodes under EMP unstructured node. If I do

int count=empNode.getNodeIterator().getSize() I will get 5 As there are 5 nodes

So I do count++ which gives me 6 but 6 already exists, so I can't create a node with name 6 under EMP[nt:unstructred], thats why I want to apply MAX(nodeNames) something in the query. What should I do ?

Update :: I use CQ5.5. EMP is an unstructered node under content like /content/EMP. Under this(EMP) I have unstructered nodes that hold my data. And these node have names as 1,2, etc

Oliver
  • 6,152
  • 2
  • 42
  • 75

2 Answers2

4

I tried with my CQ5.4 instance to find a soloution. Unfortunatly my tries were not successful. When I used the keywords 'sql2 count' with Google, I found this page. There was asked the same question and the answer was

There is no count(*) or group by selector in JCR SQL 1, XPath [2] or JCR-SQL2/AQM [3].

To implement such a tag cloud, you can run one query that fetches all your content containing the relevant "tag" property:

//element(*, my:Article)[@tag]

and then iterate over the result and count your tags on the application side by looking at the tag property values and using some hashmap (tagid -> count).

http://www.day.com/specs/jcr/1.0/ (section 8.5)

http://www.day.com/specs/jcr/1.0/ (section 6.6)

http://www.day.com/specs/jcr/2.0/6_Query.html

I think you can connect this answer to MAX() and MIN().

Community
  • 1
  • 1
Reporter
  • 3,897
  • 5
  • 33
  • 47
  • :: does that mean that. We fetch all the records we want and then re iterate over it in JCR_SQL2? Or do I have to really do that manually in Java? Or are you talking about writing a procedure in CQ5? The last question is bizzare but just curious! – Oliver Oct 16 '14 at 15:33
  • Yes, you have to it manually. Fortunatly the `java.util.List` contains the method `size()`. – Reporter Oct 16 '14 at 15:39
  • :: I understand. but if you see my question properly you'll understand that `list.size()` doesn't help me. I however managed to solve it by maintaining a CounterTable (node) that keeps a track of the latest used integer instead of doing list.size() +1 to get the latest int and use it as primary key. – Oliver Oct 17 '14 at 04:30
0

I implemented a simple Apache Sling servlet to implement the count(*) function. More information here: https://github.com/artika4biz/sling-utils. Official documentation can be found here: https://jackrabbit.apache.org/oak/docs/query/query-engine.html

artika4biz
  • 21
  • 4