cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco, CMIS and Prepared statement

nagatoo
Champ in-the-making
Champ in-the-making

Hi guys, my question is: how, using only an CMIS interface, execute prepared statement query?

My code: 

String query = "SELECT org.cmis:objectId FROM supd:orgStructure "
      + "as org WHERE org.cmis:name like ? AND org.supd:orgStructureKind = ?";

   QueryStatement qs = session.createQueryStatement(query);

   qs.setProperty(1, "%"+name+"%");

   qs.setProperty(2, indexkind);



String statement = qs.toQuerySring();
ItemIterable<QueryResult> results = qs.query(false);

Object session include connection settings (serverDB url, etc...). How get this object, using only CMIS?

1 ACCEPTED ANSWER

andy1
Star Collaborator
Star Collaborator

Hi

You do not need to worry about prepared statements.

You are expressing your query in a language that does not support that feature. Underneath the covers your SQL gets parsed and executed against either SOLR or the database. The database execution engine generates SQL which will use prepared statements.

We do have support for parametrised queries in AFTS - but not for the CMIS QL. They do not get used much. They did not make it to the public API for this reason (IIRC).

Andy

View answer in original post

4 REPLIES 4

afaust
Legendary Innovator
Legendary Innovator

I don't understand the question. You are already using CMIS - so what are you asking for when you say "how to get this object using only CMIS"? Do you mean by manually crafting / sending the CMIS HTTP requests, without the OpenCMIS library?

nagatoo
Champ in-the-making
Champ in-the-making

Sorry for incorrect question,

Usually, I work with base through searchService: 

   String query = "SELECT org.cmis:objectId FROM supd:orgStructure "
      + "as org WHERE org.cmis:name like" + name + " AND org.supd:orgStructureKind = "

       + indexKind;    

   SearchParameters sp = new SearchParameters();


   sp.addStore(store);
   sp.setLanguage(language);
   sp.setQuery(query);

    ResultSet rs = searchService.query(sp);

   result = rs.getNodeRefs();

    if (rs != null) {
      rs.close();
   }

 

Now i wanna execute prepared statement query, but i dont know how to do this. After googling i search solution described above (in the first post). In solution appears session object:

   QueryStatement qs = session.createQueryStatement(query);

 Make session object == make new connection (if i understand right, and if its true, this solution is not for me).

 Maybe there is an opportunity execute this query in searchService?

afaust
Legendary Innovator
Legendary Innovator

Within the Repository-tier Java API there is no support for using prepared statements to execute an Alfresco query.

andy1
Star Collaborator
Star Collaborator

Hi

You do not need to worry about prepared statements.

You are expressing your query in a language that does not support that feature. Underneath the covers your SQL gets parsed and executed against either SOLR or the database. The database execution engine generates SQL which will use prepared statements.

We do have support for parametrised queries in AFTS - but not for the CMIS QL. They do not get used much. They did not make it to the public API for this reason (IIRC).

Andy