I have the following Marklogic query that, when run in the query console, allows me to retrieve my system user's who have admin privileges:
xquery version "1.0-ml";
import schema namespace bfa="http://bitfood.org/auth" at "schema/auth/bitfood-auth.xsd";
cts:search(/bfa:AppUser[bfa:appAccess/@appRole = "ROLE_SYS_ADMIN"], cts:and-query(()))
Pardon my ignorance, but is it possible to implement this query using the Java client API only?
I know I could use the raw query via XCC but I'm trying to avoid that as much as possible.
I've been digging through the Java client API's documentation which, unfortunately, deals briefly with other search methods and have found nothing hinting that this is possible.
UPDATE 1: Guys, I think I've hit a showstopper here.
According to this question, the Query Options building facilities of the Java client API are marked as deprecated.
@ehennum suggests an alternative which uses either XML or JSON query options. However, such query option specifications are still essentially defined as raw Strings in the code:
String xmlOptions =
"<search:options "+
"xmlns:search='http://marklogic.com/appservices/search'>"+
"<search:constraint name='industry'>"+
"<search:value>"+
"<search:element name='industry' ns=''/>"+
"</search:value>"+
"</search:constraint>"+
"</search:options>";
Granted, I could use JAXB, JDOM, files or some other tool to create the XML, but my personal opinion is that we are still resorting to storing queries in resource files in the code, which is not a bad thing in itself, but without careful consideration could lead to code maintenance nightmares.
Furthermore, the fact that these options need to be persisted via REST at the server introduces one more layer of potential problems in case this is mandatory since the options might need to be synchronized with every database instance that is meant to work with a code base.
So, if the Marklogic devs are listening, I think the Java client API isn't as mature or documented as I expected it to be.
I have two options so far:
1) I could hardcode my XCC queries in String files and try to use parameter placeholders to insert the data that I need and retrieve via an XCC session. Or.
2) See if there are any XSD files for the http://marklogic.com/appservices/search
namespace and create static JAXB objects from them in order to build some sort of "criteria" classes a la Hibernate or QueryDSL which, sadly I must say, already supports some level of MongoDB querying.
Guys, really, bring some sort of fluent querying facilities like QueryDSL to Marklogic and get rid of this Rube Goldberg querying machine.
Update 2: Seems as if this might be addressed in ML7. Looking forward to it.
Thanks!