JSR query in Extension

Hello All,

Is there a way to execute a JSR query from an extensioin? Here is my scenario. when ever a particular content item (A) is created, I need to create a different content item (B) in a specific folder. If B is already created, then I just need to skip the creation. for this scenario, I am trying to see if I can pass a JSR query to extension to check if Content Item B has already been created or not?

Ravi

You can use IPSContentMgr in conjunction with javax.jcr.query Query, QueryResult, RowIterator, and Row.

For example :


IPSContentMgr mgr = PSContentMgrLocator.getContentMgr();
String qry = "select rx:sys_contentid, rx:sys_folderid, jcr:path from nt:base where rx:sys_contentid = '123'";
try{
  Query query = mgr.createQuery(qry.toString(), Query.SQL);
  QueryResult qresults = mgr.executeQuery(query, -1, null);
  RowIterator rows = qresults.getRows();
  while (rows.hasNext())
  {
    Row nrow = rows.nextRow();
    log.debug(nrow.getValue("jcr:path").getString());
  }
}catch(Exception e){
  log.warn("Error: " + e);
}

Thanks Jitendra,

I will try this solution.

Ravi