public class MagnoliaTemplate extends Object implements MagnoliaQueryOperations
ContentMapper
Modifier and Type | Field and Description |
---|---|
protected org.slf4j.Logger |
logger
Logger for this instance.
|
Constructor and Description |
---|
MagnoliaTemplate() |
Modifier and Type | Method and Description |
---|---|
protected <T> Collection<T> |
doExceptionThrowingQuery(String repository,
String query,
String language,
String type) |
protected <T> List<T> |
query(String repository,
String query,
String language,
String type,
ContentMapper<T> mapper) |
<T> List<T> |
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.
|
<T> T |
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 <T> Collection<T> |
queryInternal(String repository,
String query,
String language,
String type)
Performs the actual query execution.
|
protected static <T> T |
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.
|
<T> List<T> |
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.
|
<T> T |
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. |
public <T> List<T> queryForList(String repository, String query, String language, String type, ContentMapper<T> mapper)
MagnoliaQueryOperations
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 usednull
in case of a null
querypublic <T> T queryForObject(String repository, String query, String language, String type, ContentMapper<T> mapper)
MagnoliaQueryOperations
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 usednull
in case of a null
querypublic <T> List<T> xpathQueryForList(String repository, String query, String type, ContentMapper<T> mapper) throws DataAccessException
MagnoliaQueryOperations
xpathQueryForList
in interface MagnoliaQueryOperations
repository
- the repository to execute query againstquery
- query to executetype
- the type of the item to query formapper
- the mapper usednull
in case of a null
Xpath queryDataAccessException
- if there is any problem executing the querypublic <T> T xpathQueryForObject(String repository, String query, String type, ContentMapper<T> mapper) throws DataAccessException
MagnoliaQueryOperations
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 usednull
in case of a null
queryIncorrectResultSizeDataAccessException
- if the query returns more than one resultsDataAccessException
- if there is any problem executing the querypublic javax.jcr.Node xpathQueryForContent(String repository, String query, String type) throws DataAccessException
MagnoliaQueryOperations
xpathQueryForContent
in interface MagnoliaQueryOperations
repository
- the repository to execute query againstquery
- query to executetype
- the type of the item to query fornull
if no such node existsDataAccessException
- 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(..)
directly, 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 fornull
in case of a null
queryDataAccessException
- 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 resultIncorrectResultSizeDataAccessException
- if collection contains more than one elementCopyright © 2016 Magnolia International Ltd.. All rights reserved.