RQL supports a very flexible syntax for writing query expressions.
Query Example 1: The query variable Q2 is used twice, and grouping with parentheses is demonstrated in the code extract below.
RootStore r1 = rdb.getRootStore("fi.rootrql.example1.Person"); Query query = Query.createQuery() .addQ1Query(r1, "(((Q2 AND Q3) OR (Q4 AND Q5)) MERGE" + "(Q6 OR (Q2 AND (friends.hobby IN ('slalom','rally')))))") .addQ2Query(r1, " ... query expression Q2 ...") .addQ3Query(r1, " ... query expression Q3 ...") .addQ4Query(r1, " ... query expression Q4 ...") .addQ5Query(r1, " ... query expression Q5 ...") .addQ6Query(r1, " ... query expression Q6 ..."); List<Person> list = query.queryQ1Objects();
In a recursive data structure, the same field name can be repeated multiple times within a query expression.
Query Example 2: The field name friends is repeated three times in the query condition.
RootStore r1 = rdb.getRootStore("fi.rootrql.users.Person");
Query query = Query.createQuery()
.setParts(true)
.addQ1Query(r1, "(friends.friends.friends.hobby = 'golf')");
List<Person> list = query.queryQ1Objects();
Query Example 3: The dot notation of OOP can be used just as in object-oriented programming to define the location of the search condition within the data structure.
RootStore r1 = rdb.getRootStore("fi.rootrql.users.Person");
Query query = Query.createQuery()
.setParts(true)
.addQ1Query(r1, "(" +
"friends.organization.friends.friends.hobby = 'golf')");
List<Person> list = query.queryQ1Objects();
However, a more general and better option is to use the setResolveRoots attribute with the value set to true.
RQL Query 3: Calling the method setQ1ResolveRoots(true) specifies that all root objects are automatically resolved for the query result objects within the recursive data structure of the Person class. The attribute setQ1ResolveCycles is also set, although the default value is already true.
RootStore r1 = rdb.getRootStore("fi.rootrql.users.Person"); Query query = Query.createQuery() .setParts(true) .addQ1Query(r1, "(friends.hobby = 'golf')") .setQ1ResolveRoots(true) .setQ1ResolveCycles(true) //true is also default value List<Person> list = query.queryQ1Objects();
The automatic resolution of recursive data structures in database searches offers significant advantages.
Links to other pages on this site.
Page content © 2024
Contact us: