There are three well-known approaches to querying object databases:
RQL (Root Query Language) language is a QBL language, similar to SQL.
SQL Query: A SQL command is used to search all records from the Users table where the organization name starts with the letter 'A':
SELECT * FROM Users
WHERE OrganizationID IN
(SELECT ID FROM Organizations WHERE Name Like 'A%')
Programming with SQL is entirely based on a database schema, making it unintuitive to write and read, even for professional programmers.
RQL Query 1: The equivalent query in RQL:
RootStore r1 = rdb.getRootStore("fi.rootrql.users.User"); RootStore r2 = rdb.getRootStore("fi.rootrql.users.Organization"); Query query = Query.createQuery() .addQ1Query(r1, "(organization IN (Q2))") .addQ2Query(r2, "(name MATCH 'A%')"); List<User> list = query.queryQ1Objects();
RQL Query 2: The equivalent query using OOP conventions in RQL:
RootStore r1 = rdb.getRootStore("fi.rootrql.users.User"); Query query = Query.createQuery() .addQ1Query(r1, "(organization.name MATCH 'A%')"); List<User> list = query.queryQ1Objects();
RQL Query 3: Resolving the User objects can also be delegated to RootDB. In this case, the search condition is applied directly to the Organization class, rather than through the Person class, as in the OOP example above. The resolveObjectModel attribute is set to true, instructing RootDB to resolve all root objects whose data structures contain the matching organization objects. The query is defined for the Organization class (r2 refers to the Organization class), and retrieving the Person objects requires calling the transferObjectList method to extract them from the result set.
RootStore r2 = rdb.getRootStore("fi.rootrql.users.Organization"); Query query = Query.createQuery() .addQ1Query(r2, "(name MATCH 'A%')") .setResolveObjectModel(true); query.queryQ1Objects(); List<User> list = r2.transferObjectList("fi.rootrql.users.User");
See the more detailed example at Performance Benchmarking on Queries of a New Category with Variations in Indexing and Object Database Sizes Performance Comparison with Multiple Query Conditions in an Object Hierarchy.
Note that RootDB database queries return complete objects, unlike relational databases, which return only table records.
Programming with RQL is based on Object Oriented Programming (OOP) principles, entirely decoupled from the database schema, making it intuitive to write and read, even for non-experts.
Links to other pages on this site.
Page content © 2024
Contact us: