View Javadoc

1   /**
2    * This file Copyright (c) 2008-2011 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.module.rssaggregator.util;
35  
36  import info.magnolia.cms.core.Content;
37  import info.magnolia.cms.core.ItemType;
38  
39  import java.util.List;
40  
41  /**
42   * Specifies a basic set of Magnolia query operations. Implemented by {@link MagnoliaTemplate}. Not often used directly,
43   * but a useful option to enhance testability, as it can easily be mocked or stubbed.
44   *
45   * @author Rob van der Linden Vooren
46   * @see MagnoliaTemplate
47   */
48  public interface MagnoliaQueryOperations {
49  
50      /**
51       * Execute a query for a single or {@code null} result object, for the given query. <p/> This method is useful for
52       * running queries with a known outcome. The query is expected to be a single result query; the returned result will
53       * be directly mapped to the corresponding object type.
54       *
55       * @param repository the repository to execute query against
56       * @param query      query to execute
57       * @param language   query language (either {@link info.magnolia.cms.core.search.Query#XPATH XPATH} or {@link info.magnolia.cms.core.search.Query#SQL SQL}).
58       * @param type       the type of the item to query for
59       * @param mapper     the mapper used
60       * @return the result object of the required type, or {@code null} in case of a {@code null} query
61       * @throws IncorrectResultSizeDataAccessException
62       *                             if the query returns more than one results
63       * @throws DataAccessException if there is any problem executing the query
64       */
65      <T> T queryForObject(String repository, String query, String language, ItemType type, ContentMapper<T> mapper) throws DataAccessException;
66  
67      /**
68       * Execute a query for a result list of type T, for the given query. <p/>
69       *
70       * @param repository the repository to execute query against
71       * @param query      query to execute
72       * @param language   query language (either {@link info.magnolia.cms.core.search.Query#XPATH XPATH} or {@link info.magnolia.cms.core.search.Query#SQL SQL}).
73       * @param type       the type of the item to query for
74       * @param mapper     the mapper used
75       * @return the result object of the required type, or {@code null} in case of a {@code null} query
76       * @throws DataAccessException if there is any problem executing the query
77       */
78      <T> List<T> queryForList(String repository, String query, String language, ItemType type, ContentMapper<T> mapper) throws DataAccessException;
79  
80      /**
81       * Execute an XPath query for a single or {@code null} result object, for the given query. <p/> This method is
82       * useful for running queries with a known outcome. The query is expected to be a single result query; the returned
83       * result will be directly mapped to the corresponding object type.
84       *
85       * @param repository the repository to execute query against
86       * @param query      query to execute
87       * @param type       the type of the item to query for
88       * @param mapper     the mapper used
89       * @return the result object of the required type, or {@code null} in case of a {@code null} query
90       * @throws IncorrectResultSizeDataAccessException
91       *                             if the query returns more than one results
92       * @throws DataAccessException if there is any problem executing the query
93       */
94      <T> T xpathQueryForObject(String repository, String query, ItemType type, ContentMapper<T> mapper) throws DataAccessException;
95  
96      /**
97       * Execute an XPath query for a result list of type T, for the given query.
98       *
99       * @param repository the repository to execute query against
100      * @param query      query to execute
101      * @param type       the type of the item to query for
102      * @param mapper     the mapper used
103      * @return the result object of the required type, or {@code null} in case of a {@code null} Xpath query
104      * @throws DataAccessException if there is any problem executing the query
105      */
106     <T> List<T> xpathQueryForList(String repository, String query, ItemType type, ContentMapper<T> mapper) throws DataAccessException;
107 
108     /**
109      * Execute an XPath query for a Content node.
110      *
111      * @param repository the repository to execute query against
112      * @param query      query to execute
113      * @param type       the type of the item to query for
114      * @return the result Content node, or {@code null} if no such node exists
115      * @throws DataAccessException if there is any problem executing the query
116      */
117     Content xpathQueryForContent(String repository, String query, ItemType type) throws DataAccessException;
118 
119 }