|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object info.magnolia.module.rssaggregator.util.MagnoliaTemplate
public class MagnoliaTemplate
Convenience class to simplify use of Magnolia queries and the mapping of their results to types.
Note that all queries performed by this class are logged at DEBUG level for convenient debugging when necessary.
ContentMapper
Field Summary | |
---|---|
protected org.slf4j.Logger |
logger
Logger for this instance. |
Constructor Summary | |
---|---|
MagnoliaTemplate()
|
Method Summary | ||
---|---|---|
protected
|
doExceptionThrowingQuery(String repository,
String query,
String language,
String type)
|
|
protected
|
query(String repository,
String query,
String language,
String type,
ContentMapper<T> mapper)
|
|
|
queryForList(String repository,
String query,
String language,
String type,
ContentMapper<T> mapper)
Execute a query for a result list of type T, for the given query. |
|
|
queryForObject(String repository,
String query,
String language,
String type,
ContentMapper<T> mapper)
Execute a query for a single or null result object, for the given query. |
|
protected
|
queryInternal(String repository,
String query,
String language,
String type)
Performs the actual query execution. |
|
protected static
|
singleResult(Collection<T> results)
Return a single result object from the given collection or null if the collection is empty or null. |
|
javax.jcr.Node |
xpathQueryForContent(String repository,
String query,
String type)
Execute an XPath query for a Content node. |
|
|
xpathQueryForList(String repository,
String query,
String type,
ContentMapper<T> mapper)
Execute an XPath query for a result list of type T, for the given query. |
|
|
xpathQueryForObject(String repository,
String query,
String type,
ContentMapper<T> mapper)
Execute an XPath query for a single or null result object, for the given query. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected org.slf4j.Logger logger
Constructor Detail |
---|
public MagnoliaTemplate()
Method Detail |
---|
public <T> List<T> queryForList(String repository, String query, String language, String type, ContentMapper<T> mapper)
queryForList
in interface MagnoliaQueryOperations
repository
- the repository to execute query againstquery
- query to executelanguage
- query language (either XPATH
or SQL
).type
- the type of the item to query formapper
- the mapper used
null
in case of a null
querypublic <T> T queryForObject(String repository, String query, String language, String type, ContentMapper<T> mapper)
null
result object, for the given query. This method is useful for
running queries with a known outcome. The query is expected to be a single result query; the returned result will
be directly mapped to the corresponding object type.
queryForObject
in interface MagnoliaQueryOperations
repository
- the repository to execute query againstquery
- query to executelanguage
- query language (either XPATH
or SQL
).type
- the type of the item to query formapper
- the mapper used
null
in case of a null
querypublic <T> List<T> xpathQueryForList(String repository, String query, String type, ContentMapper<T> mapper) throws DataAccessException
xpathQueryForList
in interface MagnoliaQueryOperations
repository
- the repository to execute query againstquery
- query to executetype
- the type of the item to query formapper
- the mapper used
null
in case of a null
Xpath query
DataAccessException
- if there is any problem executing the querypublic <T> T xpathQueryForObject(String repository, String query, String type, ContentMapper<T> mapper) throws DataAccessException
null
result object, for the given query. This method is
useful for running queries with a known outcome. The query is expected to be a single result query; the returned
result will be directly mapped to the corresponding object type.
xpathQueryForObject
in interface MagnoliaQueryOperations
repository
- the repository to execute query againstquery
- query to executetype
- the type of the item to query formapper
- the mapper used
null
in case of a null
query
IncorrectResultSizeDataAccessException
- if the query returns more than one results
DataAccessException
- if there is any problem executing the querypublic javax.jcr.Node xpathQueryForContent(String repository, String query, String type) throws DataAccessException
xpathQueryForContent
in interface MagnoliaQueryOperations
repository
- the repository to execute query againstquery
- query to executetype
- the type of the item to query for
null
if no such node exists
DataAccessException
- if there is any problem executing the queryprotected <T> List<T> query(String repository, String query, String language, String type, ContentMapper<T> mapper) throws DataAccessException
DataAccessException
protected <T> Collection<T> queryInternal(String repository, String query, String language, String type)
QueryUtil.exceptionThrowingQuery(..)
in order to provide flexibility with regards to
error handling, by translating any RepositoryException
into an unchecked DataAccessException
.
This allows for optional exception handling and logging, making it a better alternative then using QueryUtil.query(..)
direcltly, which logs the error and then directly swallows
the exception
. Execute a query for a result list of type T, for the given query.
repository
- the repository to execute query againstquery
- query to executelanguage
- query language (either or ).type
- the type of the item to query for
null
in case of a null
query
DataAccessException
- if there is any problem executing the queryprotected <T> Collection<T> doExceptionThrowingQuery(String repository, String query, String language, String type) throws javax.jcr.RepositoryException
javax.jcr.RepositoryException
protected static <T> T singleResult(Collection<T> results) throws IncorrectResultSizeDataAccessException
null
if the collection is empty or null.
results
- the result collection (may be null
)
null
when no result
IncorrectResultSizeDataAccessException
- if collection contains more than one element
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |