Skip to content

Content Query Manager

Geert Bevin edited this page Oct 26, 2023 · 2 revisions

To simplify working with content, RIFE2 provides a dedicated query manager, called ContentQueryManager, which extends GenericQueryManager and is a drop-in replacement. This query manager class works hand-in-hand with CMF-specific constraints. These additional constraints allow you to provide CMF-related metadata for bean properties while still having access to all regular constraints.

CMF Constraints

The most important CMF constraint is mimeType. Setting this constraint directs RIFE2 to delegate the handling of that property's data to the CMF instead of storing it as a regular column in a database table. The property content location (i.e. its full path) is generated automatically based on the bean class name, the instance's identifier value (i.e. the primary key used by GenericQueryManager), and the property name.

So for example, if you have an instance of the NewsItem class whose identifier is 23, then the full path that is generated for a property named text is /newsitem/23/text.
Note that this always specifies the most recent version of the property, but that older versions are also available from the ContentStore.

TIP : You can find a content query manager example in the RIFE2 GitHub repository. This is the source code of the associated bean.

Ordinal management

Apart from the handling of content, the ContentQueryManager also integrates the functionalities of the CMF OrdinalManager class.

The ordinal constraint indicates which bean property will be used to order that table's rows. When saving and deleting beans, the ordinal values will be automatically updated in the entire table. The ContentQueryManager also provides move(), up() and down() methods to easily manipulate the order of existing rows.

Installation

Before being able to use the CMF and a ContentQueryManager, you must install both of them, as in this example:

DatabaseContentFactory.getInstance(datasource).install();
new ContentQueryManager(datasource, NewsItem.class).install();
new ContentQueryManager(datasource, NewsComment.class).install();
new ContentQueryManager(datasource, NewsAuthor.class).install();

NOTE: You might have many different ContentQueryManager instances, one for each bean class that you're storing, all these will usually however share the same ContentStore. This is why the ContentQueryManager doesn't automatically install the ContentStore, but why it's a separate installation call is needed.


Next learn more about Serving Content