'How can i add an expression to jcr sql2 query?

I have query

SELECT * 
FROM [cq:ReplicationStatus] AS node 
WHERE (ISDESCENDANTNODE(node,'/home/users/we-retail') 
  AND node.[rep:authorizableId] = ${userId}) 

and I have a function

public HashMap<String, Object> getInformation(Integer userId) throws IOException, RepositoryException 
{
     ... 
}

where I execute my query. But it does not work, because ${userId} is a string not an expression. I also tried

SELECT * 
FROM [cq:ReplicationStatus] AS node 
WHERE (ISDESCENDANTNODE(node,'/home/users/A') 
  AND node.[rep:authorizableId] = '\"+userId+\"')"

Where is my mistake?



Solution 1:[1]

I'm not sure if I understand you right:

public HashMap<String, Object> getInformation(Integer userId) throws 
       IOException, RepositoryException 
{
     String sqlQueryStr = "SELECT * FROM [cq:ReplicationStatus] AS node
     WHERE (ISDESCENDANTNODE(node,'/home/users/A') AND 
     node.[rep:authorizableId] = '"+userId+"')";
     ... 
}

should work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Reporter