| com.uwyn.rife.cmf.dam.ContentQueryManager
ContentQueryManager | public class ContentQueryManager extends GenericQueryManagerDelegate implements Cloneable(Code) | | The ContentQueryManager simplifies working with content a lot.
It extends
com.uwyn.rife.database.querymanagers.generic.GenericQueryManagerGenericQueryManager 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
com.uwyn.rife.site.Validation Validation and
com.uwyn.rife.site.ConstrainedProperty 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 '
com.uwyn.rife.site.ConstrainedProperty.mimeType(com.uwyn.rife.cmf.MimeType) 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:
Datasource ds = Datasources.getRepInstance().getDatasource("datasource");
DatabaseContentFactory.getInstance(ds).install();
new ContentQueryManager(ds, NewsItem.class).install();
Apart from the handling of content, this query manager also integrates
the functionalities of the
OrdinalManager class.
The new '
com.uwyn.rife.site.ConstrainedProperty.ordinal(boolean) ordinal '
constraint indicates which bean property will be used to order that table
rows. When saving and deleting beans, the ordinal values will be
automatically updated in the entire table. The
ContentQueryManager also provides the
ContentQueryManager.move(Constrained,String,OrdinalManager.Direction) move ,
ContentQueryManager.up(Constrained,String) up and
ContentQueryManager.down(Constrained,String) down methods to easily manipulate the order of existing rows.
author: Geert Bevin (gbevin[remove] at uwyn dot com)i version: $Revision: 3848 $ since: 1.0 |
Method Summary | |
public String | buildCmfPath(T bean, String propertyName) Builds the path that is used by the ContentQueryManager
for a certain bean and property. | public String | buildCmfPath(int objectId, String propertyName) Builds the path that is used by the ContentQueryManager
for a certain bean ID and property. | public String | buildServeContentPath(T bean, String propertyName) Builds the path that is used by the ServeContent element
for a certain bean and property. | public String | buildServeContentPath(int objectId, String propertyName) Builds the path that is used by the ServeContent element
for a certain bean ID and property. | public Object | clone() Simply clones the instance with the default clone method. | public GenericQueryManager<OtherBeanType> | createNewManager(Class<OtherBeanType> type) | public boolean | delete(int objectId) Deletes a bean according to its ID. | public 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. | public String | getContentForHtml(T bean, String propertyName, Element element, String serveContentExitName) Retrieves a content data representation for use in html.
This is mainly used to integrate content data inside a html
document. | public String | getContentForHtml(int objectId, String propertyName, Element element, String serveContentExitName) Retrieves a content data representation for use in html.
This is mainly used to integrate content data inside a html
document. | public ContentManager | getContentManager() Returns the ContentManager that is used to store and
retrieve the content. | public String | getRepository() Retrieves the default repository that is used by this ContentQueryManager . | public boolean | hasContent(T bean, String propertyName) Checks if there's content available for a certain property of a bean. | public boolean | hasContent(int objectId, String propertyName) Checks if there's content available for a certain property of a bean. | public 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. | public ContentQueryManager<T> | repository(String repository) Sets the default repository that will be used by this ContentQueryManager . | public T | restore(int objectId) Restores a bean according to its ID. | public List<T> | restore() Restores all beans. | public List<T> | restore(RestoreQuery query) Restores all beans from a RestoreQuery . | public T | restoreFirst(RestoreQuery query) Restores the first bean from a RestoreQuery . | public int | save(T bean) Saves a bean.
This augments the regular GenericQueryManager 's
save 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 an autoRetrieved
constraint. | public boolean | storeEmptyContent(T bean, String propertyName) 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 an autoRetrieved
constraint. | public 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. |
ContentQueryManager | public ContentQueryManager(Datasource datasource, Class<T> klass, Class backendClass)(Code) | | Creates a new ContentQueryManager instance for a specific
class.
All content will be stored in a
com.uwyn.rife.cmf.dam.contentmanagers.DatabaseContent .
Parameters: datasource - the datasource that indicates where the data will bestored Parameters: klass - the class of the bean that will be handled by thisContentQueryManager Parameters: backendClass - the class the will be used by thisContentQueryManager to reference data in the backend since: 1.0 |
ContentQueryManager | public ContentQueryManager(Datasource datasource, Class<T> klass, String table)(Code) | | Creates a new ContentQueryManager instance for a specific
class, but with a different table name for the database storage.
All content will be stored in a
com.uwyn.rife.cmf.dam.contentmanagers.DatabaseContent .
Parameters: datasource - the datasource that indicates where the data will bestored Parameters: klass - the class of the bean that will be handled by thisContentQueryManager Parameters: table - the name of the database table in which the non CMF data willbe stored since: 1.6 |
ContentQueryManager | public ContentQueryManager(Datasource datasource, Class<T> klass)(Code) | | Creates a new ContentQueryManager instance for a specific
class.
All content will be stored in a
com.uwyn.rife.cmf.dam.contentmanagers.DatabaseContent .
Parameters: datasource - the datasource that indicates where the data will bestored Parameters: klass - the class of the bean that will be handled by thisContentQueryManager since: 1.0 |
ContentQueryManager | public ContentQueryManager(Datasource datasource, Class<T> klass, ContentManager contentManager)(Code) | | Creates a new ContentQueryManager 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 bestored Parameters: klass - the class of the bean that will be handled by thisContentQueryManager Parameters: contentManager - a ContentManager instance since: 1.0 |
buildCmfPath | public String buildCmfPath(T bean, String propertyName)(Code) | | Builds the path that is used by the ContentQueryManager
for a certain bean and property.
Parameters: bean - the bean instance that will be used to construct the path Parameters: propertyName - the name of the property that will be used toconstruct the path the requested path since: 1.0 |
buildCmfPath | public String buildCmfPath(int objectId, String propertyName)(Code) | | Builds the path that is used by the ContentQueryManager
for a certain bean ID and property.
Parameters: objectId - the bean ID that will be used to construct the path Parameters: propertyName - the name of the property that will be used toconstruct the path the requested path since: 1.0 |
buildServeContentPath | public String buildServeContentPath(T bean, String propertyName)(Code) | | Builds the path that is used by the ServeContent element
for a certain bean and property.
Any declaration of the repository name will be ignore, 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 path Parameters: propertyName - the name of the property that will be used toconstruct the path the requested path since: 1.4 |
buildServeContentPath | public String buildServeContentPath(int objectId, String propertyName)(Code) | | Builds the path that is used by the ServeContent element
for a certain bean ID and property.
Any declaration of the repository name will be ignore, 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 path Parameters: propertyName - the name of the property that will be used toconstruct the path the requested path since: 1.4 |
clone | public Object clone()(Code) | | 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.
since: 1.0 |
delete | public boolean delete(int objectId) throws DatabaseException(Code) | | Deletes a bean according to its ID.
This augments the regular GenericQueryManager 's
restore method with behaviour that correctly handles
content and ordinal properties.
Parameters: objectId - the ID of the bean that has to be restored true if the bean was deleted successfully; or false if it couldn't be found since: 1.0
|
down | public boolean down(Constrained bean, String propertyName)(Code) | | 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 tobe moved Parameters: propertyName - the name of the property with an ordinal constraint true if the row was moved successfully; orfalse otherwise since: 1.0
|
getContentForHtml | public String getContentForHtml(T bean, String propertyName, Element element, String serveContentExitName) throws ContentManagerException(Code) | | 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 data Parameters: propertyName - the name of the property whose html representationwill be provided Parameters: element - an active element instance Parameters: serveContentExitName - the exit name that leads to a com.uwyn.rife.cmf.elements.ServeContent ServeContent element. This willbe used to generate URLs for content that can't be directly displayedin-line. the html content representation exception: ContentManagerException - if an unexpected error occurred since: 1.0 |
getContentForHtml | public String getContentForHtml(int objectId, String propertyName, Element element, String serveContentExitName) throws ContentManagerException(Code) | | 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 data Parameters: propertyName - the name of the property whose html representationwill be provided Parameters: element - an active element instance Parameters: serveContentExitName - the exit name that leads to a com.uwyn.rife.cmf.elements.ServeContent ServeContent element. This willbe used to generate URLs for content that can't be directly displayedin-line. the html content representation exception: ContentManagerException - if an unexpected error occurred since: 1.0 |
getContentManager | public ContentManager getContentManager()(Code) | | Returns the ContentManager that is used to store and
retrieve the content.
the ContentManager since: 1.0 |
getRepository | public String getRepository()(Code) | | Retrieves the default repository that is used by this ContentQueryManager .
this ContentQueryManager 's repository See Also: ContentQueryManager.repository since: 1.4 |
hasContent | public boolean hasContent(T bean, String propertyName) throws DatabaseException(Code) | | Checks if there's content available for a certain property of a bean.
Parameters: bean - the bean instance that will be checked Parameters: propertyName - the name of the property whose content availabilitywill be checked true if content is available; orfalse otherwise since: 1.0
|
hasContent | public boolean hasContent(int objectId, String propertyName) throws DatabaseException(Code) | | Checks if there's content available for a certain property of a bean.
Parameters: objectId - the ID of the bean instance that will be checked Parameters: propertyName - the name of the property whose content availabilitywill be checked true if content is available; orfalse otherwise since: 1.0
|
move | public boolean move(Constrained bean, String propertyName, OrdinalManager.Direction direction)(Code) | | 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 tobe moved Parameters: propertyName - the name of the property with an ordinal constraint Parameters: direction - OrdinalManager.UP or OrdinalManager.DOWN true if the row was moved successfully; orfalse otherwise since: 1.0
|
restore | public T restore(int objectId) throws DatabaseException(Code) | | Restores a bean according to its ID.
This augments the regular GenericQueryManager 's
restore method with behaviour that correctly handles
content properties.
Parameters: objectId - the ID of the bean that has to be restored the bean instance if it was restored successfully; or null if it couldn't be found since: 1.0
|
restore | public List<T> restore() throws DatabaseException(Code) | | Restores all beans.
This augments the regular GenericQueryManager 's
restore method with behaviour that correctly handles
content properties.
the list of beans; or null if no beans could be found since: 1.0
|
restore | public List<T> restore(RestoreQuery query) throws DatabaseException(Code) | | Restores all beans from a RestoreQuery .
This augments the regular GenericQueryManager 's
restore method with behaviour that correctly handles
content properties.
Parameters: query - the query that will be used to restore the beans the list of beans; or null if no beans could be found since: 1.0
|
restoreFirst | public T restoreFirst(RestoreQuery query) throws DatabaseException(Code) | | Restores the first bean from a RestoreQuery .
This augments the regular GenericQueryManager 's
restore method with behaviour that correctly handles
content properties.
Parameters: query - the query that will be used to restore the beans the first bean instance that was found; or null if no beans could be found since: 1.0
|
save | public int save(T bean) throws DatabaseException(Code) | | Saves a bean.
This augments the regular GenericQueryManager 's
save 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 an autoRetrieved
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.
Parameters: bean - the bean instance that has to be saved true if the bean was stored successfully; or false otherwise since: 1.0
|
storeEmptyContent | public boolean storeEmptyContent(T bean, String propertyName)(Code) | | 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 an autoRetrieved
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 on null to
indicate empty content. This method has thus been added explicitly for
this purpose.
Parameters: bean - the bean instance that contains the property Parameters: propertyName - the name of the property whose content has to beemptied in the database true if the empty content was stored successfully;or false otherwise since: 1.0
|
up | public boolean up(Constrained bean, String propertyName)(Code) | | 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 tobe moved Parameters: propertyName - the name of the property with an ordinal constraint true if the row was moved successfully; orfalse otherwise since: 1.0
|
|
|