Class ContentQueryManager<T>
- All Implemented Interfaces:
Cloneable
,GenericQueryManager<T>
,ValidationContext
ContentQueryManager
simplifies working with content a lot.
It extends GenericQueryManager
and is a drop-in replacement that can be used instead.
The ContentQueryManager
class works hand-in-hand with
CMF-related constraints that are provided via the classes Validation
and ConstrainedProperty
. The additional constraints
allow you to provide CMF-related metadata for bean properties while still
having access to all regular constraints.
The most important additional constraint is 'mimeType
'. Setting this
constraint directs RIFE 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 content store.
Before being able to use the CMF and a ContentQueryManager
,
you must install both of them, as in this example:
DatabaseContentFactory.instance(datasource).install(); new ContentQueryManager(datasource, NewsItem.class).install();
Apart from the handling of content, this query manager also integrates
the functionalities of the OrdinalManager
class.
The new '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 the move
, up
and down
methods to easily manipulate the order of existing rows.
- Since:
- 1.0
-
Constructor Summary
ConstructorDescriptionContentQueryManager
(Datasource datasource, Class<T> klass) Creates a newContentQueryManager
instance for a specific class.ContentQueryManager
(Datasource datasource, Class<T> klass, Class backendClass) Creates a newContentQueryManager
instance for a specific class.ContentQueryManager
(Datasource datasource, Class<T> klass, String table) Creates a newContentQueryManager
instance for a specific class, but with a different table name for the database storage.ContentQueryManager
(Datasource datasource, Class<T> klass, ContentManager contentManager) Creates a newContentQueryManager
instance for a specific class. -
Method Summary
Modifier and TypeMethodDescriptionbuildCmfPath
(int objectId, String propertyName) Builds the path that is used by theContentQueryManager
for a certain bean ID and property.buildCmfPath
(T bean, String propertyName) Builds the path that is used by theContentQueryManager
for a certain bean and property.buildServeContentPath
(int objectId, String propertyName) Builds the path that is used by theServeContent
element for a certain bean ID and property.buildServeContentPath
(T bean, String propertyName) Builds the path that is used by theServeContent
element for a certain bean and property.clone()
Simply clones the instance with the default clone method.<OtherBeanType>
GenericQueryManager<OtherBeanType>createNewManager
(Class<OtherBeanType> type) Create a new generic query manager of the same kind but for another bean class.boolean
delete
(int objectId) Deletes a bean according to its ID.boolean
down
(Constrained bean, String propertyName) Moves the row that corresponds to the provided bean instance downwards according to a property with an ordinal constraint.getContentForHtml
(int objectId, String propertyName, Context context, Route route) Retrieves a content data representation for use in html.getContentForHtml
(T bean, String propertyName, Context context, Route route) Retrieves a content data representation for use in html.Returns theContentManager
that is used to store and retrieve the content.Retrieves the default repository that is used by thisContentQueryManager
.boolean
hasContent
(int objectId, String propertyName) Checks if there's content available for a certain property of a bean.boolean
hasContent
(T bean, String propertyName) Checks if there's content available for a certain property of a bean.boolean
move
(Constrained bean, String propertyName, OrdinalManager.Direction direction) Moves the row that corresponds to the provided bean instance according to a property with an ordinal constraint.repository
(String repository) Sets the default repository that will be used by thisContentQueryManager
.restore()
Restores all beans.restore
(int objectId) Restores a bean according to its ID.restore
(RestoreQuery query) Restores all beans from aRestoreQuery
.restoreFirst
(RestoreQuery query) Restores the first bean from aRestoreQuery
.int
Saves a bean.boolean
storeEmptyContent
(T bean, String propertyName) Empties the content of a certain bean property.boolean
up
(Constrained bean, String propertyName) Moves the row that corresponds to the provided bean instance upwards according to a property with an ordinal constraint.Methods inherited from class rife.database.querymanagers.generic.GenericQueryManagerDelegate
addListener, count, count, delete, getBaseClass, getCountQuery, getDatasource, getDelegate, getDeleteQuery, getDeleteQuery, getIdentifierName, getIdentifierValue, getInstallTableQuery, getRestoreQuery, getRestoreQuery, getTable, insert, install, install, remove, removeListeners, restore, restore, restore, restore, update, validate
-
Constructor Details
-
ContentQueryManager
Creates a newContentQueryManager
instance for a specific class.All content will be stored in a
DatabaseContent
.- Parameters:
datasource
- the datasource that indicates where the data will be storedklass
- the class of the bean that will be handled by thisContentQueryManager
backendClass
- the class will be used by thisContentQueryManager
to reference data in the backend- Since:
- 1.0
-
ContentQueryManager
Creates a newContentQueryManager
instance for a specific class, but with a different table name for the database storage.All content will be stored in a
DatabaseContent
.- Parameters:
datasource
- the datasource that indicates where the data will be storedklass
- the class of the bean that will be handled by thisContentQueryManager
table
- the name of the database table in which the non CMF data will be stored- Since:
- 1.6
-
ContentQueryManager
Creates a newContentQueryManager
instance for a specific class.All content will be stored in a
DatabaseContent
.- Parameters:
datasource
- the datasource that indicates where the data will be storedklass
- the class of the bean that will be handled by thisContentQueryManager
- Since:
- 1.0
-
ContentQueryManager
Creates a newContentQueryManager
instance for a specific class.All content will be stored in the provided
ContentManager
instance. This constructor is handy if you want to integrate a custom content manager implementation.- Parameters:
datasource
- the datasource that indicates where the data will be storedklass
- the class of the bean that will be handled by thisContentQueryManager
contentManager
- aContentManager
instance- Since:
- 1.0
-
-
Method Details
-
repository
Sets the default repository that will be used by thisContentQueryManager
.- Returns:
- this
ContentQueryManager
- Since:
- 1.4
- See Also:
-
getRepository
Retrieves the default repository that is used by thisContentQueryManager
.- Returns:
- this
ContentQueryManager
's repository - Since:
- 1.4
- See Also:
-
getContentManager
Returns theContentManager
that is used to store and retrieve the content.- Returns:
- the
ContentManager
- Since:
- 1.0
-
move
Moves the row that corresponds to the provided bean instance according to a property with an ordinal constraint.- Parameters:
bean
- the bean instance that corresponds to the row that has to be movedpropertyName
- the name of the property with an ordinal constraintdirection
-OrdinalManager.UP
orOrdinalManager.DOWN
- Returns:
true
if the row was moved successfully; orfalse
otherwise- Since:
- 1.0
-
up
Moves the row that corresponds to the provided bean instance upwards according to a property with an ordinal constraint.- Parameters:
bean
- the bean instance that corresponds to the row that has to be movedpropertyName
- the name of the property with an ordinal constraint- Returns:
true
if the row was moved successfully; orfalse
otherwise- Since:
- 1.0
-
down
Moves the row that corresponds to the provided bean instance downwards according to a property with an ordinal constraint.- Parameters:
bean
- the bean instance that corresponds to the row that has to be movedpropertyName
- the name of the property with an ordinal constraint- Returns:
true
if the row was moved successfully; orfalse
otherwise- Since:
- 1.0
-
storeEmptyContent
Empties the content of a certain bean property.When a bean is saved,
null
content properties are simply ignored when the property hasn't got anautoRetrieved
constraint. This is needed to make it possible to only update a bean's data without having to fetch the content from the back-end and store it together with the other data just to make a simple update. However, this makes it impossible to rely onnull
to indicate empty content. This method has thus been added explicitly for this purpose.- Parameters:
bean
- the bean instance that contains the propertypropertyName
- the name of the property whose content has to be emptied in the database- Returns:
true
if the empty content was stored successfully; orfalse
otherwise- Since:
- 1.0
-
save
Saves a bean.This augments the regular
GenericQueryManager
'ssave
method with behaviour that correctly handles content or ordinal properties. When a bean is saved,null
content properties are simply ignored when the property hasn't got anautoRetrieved
constraint. This is needed to make it possible to only update a bean's data without having to fetch the content from the back-end and store it together with the other data just to make a simple update.- Specified by:
save
in interfaceGenericQueryManager<T>
- Overrides:
save
in classGenericQueryManagerDelegate<T>
- Parameters:
bean
- the bean instance that has to be saved- Returns:
true
if the bean was stored successfully; orfalse
otherwise- Throws:
DatabaseException
- Since:
- 1.0
-
restore
Restores a bean according to its ID.This augments the regular
GenericQueryManager
'srestore
method with behaviour that correctly handles content properties.- Specified by:
restore
in interfaceGenericQueryManager<T>
- Overrides:
restore
in classGenericQueryManagerDelegate<T>
- Parameters:
objectId
- the ID of the bean that has to be restored- Returns:
- the bean instance if it was restored successfully; or
null
if it couldn't be found - Throws:
DatabaseException
- Since:
- 1.0
-
restoreFirst
Restores the first bean from aRestoreQuery
.This augments the regular
GenericQueryManager
'srestore
method with behaviour that correctly handles content properties.- Specified by:
restoreFirst
in interfaceGenericQueryManager<T>
- Overrides:
restoreFirst
in classGenericQueryManagerDelegate<T>
- Parameters:
query
- the query that will be used to restore the beans- Returns:
- the first bean instance that was found; or
null
if no beans could be found - Throws:
DatabaseException
- Since:
- 1.0
- See Also:
-
restore
Restores all beans.This augments the regular
GenericQueryManager
'srestore
method with behaviour that correctly handles content properties.- Specified by:
restore
in interfaceGenericQueryManager<T>
- Overrides:
restore
in classGenericQueryManagerDelegate<T>
- Returns:
- the list of beans; or
null
if no beans could be found - Throws:
DatabaseException
- Since:
- 1.0
-
restore
Restores all beans from aRestoreQuery
.This augments the regular
GenericQueryManager
'srestore
method with behaviour that correctly handles content properties.- Specified by:
restore
in interfaceGenericQueryManager<T>
- Overrides:
restore
in classGenericQueryManagerDelegate<T>
- Parameters:
query
- the query that will be used to restore the beans- Returns:
- the list of beans; or
null
if no beans could be found - Throws:
DatabaseException
- Since:
- 1.0
- See Also:
-
delete
Deletes a bean according to its ID.This augments the regular
GenericQueryManager
'srestore
method with behaviour that correctly handles content and ordinal properties.- Specified by:
delete
in interfaceGenericQueryManager<T>
- Overrides:
delete
in classGenericQueryManagerDelegate<T>
- Parameters:
objectId
- the ID of the bean that has to be restored- Returns:
true
if the bean was deleted successfully; orfalse
if it couldn't be found- Throws:
DatabaseException
- Since:
- 1.0
-
hasContent
Checks if there's content available for a certain property of a bean.- Parameters:
bean
- the bean instance that will be checkedpropertyName
- the name of the property whose content availability will be checked- Returns:
true
if content is available; orfalse
otherwise- Throws:
DatabaseException
- Since:
- 1.0
-
hasContent
Checks if there's content available for a certain property of a bean.- Parameters:
objectId
- the ID of the bean instance that will be checkedpropertyName
- the name of the property whose content availability will be checked- Returns:
true
if content is available; orfalse
otherwise- Throws:
DatabaseException
- Since:
- 1.0
-
buildCmfPath
Builds the path that is used by theContentQueryManager
for a certain bean and property.- Parameters:
bean
- the bean instance that will be used to construct the pathpropertyName
- the name of the property that will be used to construct the path- Returns:
- the requested path
- Since:
- 1.0
-
buildCmfPath
Builds the path that is used by theContentQueryManager
for a certain bean ID and property.- Parameters:
objectId
- the bean ID that will be used to construct the pathpropertyName
- the name of the property that will be used to construct the path- Returns:
- the requested path
- Since:
- 1.0
-
buildServeContentPath
Builds the path that is used by theServeContent
element for a certain bean and property.Any declaration of the repository name will be ignored, since the
ServeContent
element doesn't allow you to provide this through the URL for safety reasons.- Parameters:
bean
- the bean instance that will be used to construct the pathpropertyName
- the name of the property that will be used to construct the path- Returns:
- the requested path
- Since:
- 1.4
-
buildServeContentPath
Builds the path that is used by theServeContent
element for a certain bean ID and property.Any declaration of the repository name will be ignored, since the
ServeContent
element doesn't allow you to provide this through the URL for safety reasons.- Parameters:
objectId
- the bean ID that will be used to construct the pathpropertyName
- the name of the property that will be used to construct the path- Returns:
- the requested path
- Since:
- 1.4
-
getContentForHtml
public String getContentForHtml(T bean, String propertyName, Context context, Route route) throws ContentManagerException Retrieves a content data representation for use in html.This is mainly used to integrate content data inside a html document. For instance, html content will be displayed as-is, while image content will cause an image tag to be generated with the correct source URL to serve the image.
- Parameters:
bean
- the bean instance that contains the datapropertyName
- the name of the property whose html representation will be providedcontext
- an active web engine contextroute
- a route that leads to arife.cmf.elements.ServeContent
element- Returns:
- the html content representation
- Throws:
ContentManagerException
- if an unexpected error occurred- Since:
- 1.0
-
getContentForHtml
public String getContentForHtml(int objectId, String propertyName, Context context, Route route) throws ContentManagerException Retrieves a content data representation for use in html.This is mainly used to integrate content data inside a html document. For instance, html content will be displayed as-is, while image content will cause an image tag to be generated with the correct source URL to serve the image.
- Parameters:
objectId
- the ID of the bean that contains the datapropertyName
- the name of the property whose html representation will be providedcontext
- an active web engine contextroute
- a route that leads to arife.cmf.elements.ServeContent
element- Returns:
- the html content representation
- Throws:
ContentManagerException
- if an unexpected error occurred- Since:
- 1.0
-
clone
Simply clones the instance with the default clone method. This creates a shallow copy of all fields and the clone will in fact just be another reference to the same underlying data. The independence of each cloned instance is consciously not respected since they rely on resources that can't be cloned. -
createNewManager
public <OtherBeanType> GenericQueryManager<OtherBeanType> createNewManager(Class<OtherBeanType> type) Description copied from interface:GenericQueryManager
Create a new generic query manager of the same kind but for another bean class.- Specified by:
createNewManager
in interfaceGenericQueryManager<T>
- Overrides:
createNewManager
in classGenericQueryManagerDelegate<T>
- Parameters:
type
- the class of the bean for which the new generic query manager has to be created- Returns:
- a new generic query manager instance
-