View Javadoc

1   /**
2    * This file Copyright (c) 2003-2010 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.cms.core.search;
35  
36  import javax.jcr.ItemExistsException;
37  import javax.jcr.ItemNotFoundException;
38  import javax.jcr.Node;
39  import javax.jcr.PathNotFoundException;
40  import javax.jcr.RepositoryException;
41  import javax.jcr.UnsupportedRepositoryOperationException;
42  import javax.jcr.lock.LockException;
43  import javax.jcr.nodetype.ConstraintViolationException;
44  import javax.jcr.version.VersionException;
45  
46  
47  /**
48   * Date: Apr 4, 2005 Time: 11:02:35 AM
49   * @author Sameer Charles
50   */
51  
52  public interface Query {
53  
54      String XPATH = "xpath"; //$NON-NLS-1$
55  
56      String SQL = "sql"; //$NON-NLS-1$
57  
58      /**
59       * <i>Description inherited from javax.jcr.query.Query#execute()</i><br>
60       * Executes this query and returns a <code>{@link QueryResult}</code>.
61       * @return a <code>QueryResult</code>
62       * @throws RepositoryException if an error occurs
63       */
64      QueryResult execute() throws RepositoryException;
65  
66      /**
67       * <i>Description inherited from javax.jcr.query.Query#getStatement()</i><br>
68       * Returns the statement set for this query.
69       * @return the query statement.
70       */
71      String getStatement();
72  
73      /**
74       * <i>Description inherited from javax.jcr.query.Query#getLanguage()</i><br>
75       * Returns the language set for this query. This will be one of the query language constants returned by
76       * {@link QueryManager#getSupportedQueryLanguages}.
77       * @return the query language.
78       */
79      String getLanguage();
80  
81      /**
82       * <i>Description inherited from javax.jcr.query.Query#getStoredQueryPath()</i><br>
83       * If this is a <code>Query</code> object that has been stored using {@link Query#storeAsNode} (regardless of
84       * whether it has been <code>save</code>d yet) or retrieved using {@link QueryManager#getQuery}), then this
85       * method returns the path of the <code>nt:query</code> node that stores the query. If this is a transient query
86       * (that is, a <code>Query</code> object created with {@link QueryManager#createQuery} but not yet stored) then
87       * this method throws an <code>ItemNotFoundException</code>.
88       * @return path of the node representing this query.
89       * @throws ItemNotFoundException if this query is not a stored query.
90       * @throws RepositoryException if another error occurs.
91       */
92      String getStoredQueryPath() throws ItemNotFoundException, RepositoryException;
93  
94      /**
95       * <i>Description inherited from javax.jcr.query.Query#storeAsNode()</i><br>
96       * Creates a node representing this <code>Query</code> in content. <p/> In a level 1 repository this method throws
97       * an <code>UnsupportedRepositoryOperationException</code>. <p/> In a level 2 repository it creates a node of
98       * type <code>nt:query</code> at <code>absPath</code> and returns that node. <p/> In order to persist the newly
99       * created node, a <code>save</code> must be performed that includes <i>the parent</i> of this new node within
100      * its scope. In other words, either a <code>Session.save</code> or an <code>Item.save</code> on the parent or
101      * higher-degree ancestor of <code>absPath</code> must be performed. <p/> An <code>ItemExistsException</code>
102      * will be thrown either immediately (by this method), or on <code>save</code>, if an item at the specified path
103      * already exists and same-name siblings are not allowed. Implementations may differ on when this validation is
104      * performed. <p/> A <code>PathNotFoundException</code> will be thrown either immediately , or on
105      * <code>save</code>, if the specified path implies intermediary nodes that do not exist. Implementations may
106      * differ on when this validation is performed. <p/> A <code>ConstraintViolationException</code>will be thrown
107      * either immediately or on <code>save</code>, if adding the node would violate a node type or
108      * implementation-specific constraintor if an attempt is made to add a node as the child of a property.
109      * Implementations may differ on when this validation is performed. <p/> A <code>VersionException</code> will be
110      * thrown either immediately (by this method), or on <code>save</code>, if the node to which the new child is
111      * being added is versionable and checked-in or is non-versionable but its nearest versionable ancestor is
112      * checked-in. Implementations may differ on when this validation is performed. <p/> A <code>LockException</code>
113      * will be thrown either immediately (by this method), or on <code>save</code>, if a lock prevents the addition
114      * of the node. Implementations may differ on when this validation is performed.
115      * @return the newly created node.
116      * @throws ItemExistsException if an item at the specified path already exists, same-name siblings are not allowed
117      * and this implementation performs this validation immediately instead of waiting until <code>save</code>.
118      * @throws PathNotFoundException if the specified path implies intermediary <code>Node</code>s that do not exist
119      * or the last element of <code>relPath</code> has an index, and this implementation performs this validation
120      * immediately instead of waiting until <code>save</code>.
121      * @throws ConstraintViolationException if a node type or implementation-specific constraint is violated or if an
122      * attempt is made to add a node as the child of a property and this implementation performs this validation
123      * immediately instead of waiting until <code>save</code>.
124      * @throws VersionException if the node to which the new child is being added is versionable and checked-in or is
125      * non-versionable but its nearest versionable ancestor is checked-in and this implementation performs this
126      * validation immediately instead of waiting until <code>save</code>.
127      * @throws LockException if a lock prevents the addition of the node and this implementation performs this
128      * validation immediately instead of waiting until <code>save</code>.
129      * @throws UnsupportedRepositoryOperationException in a level 1 implementation.
130      * @throws RepositoryException if another error occurs or if the <code>relPath</code> provided has an index on its
131      * final element.
132      */
133     Node storeAsNode(String s) throws ItemExistsException, PathNotFoundException, VersionException,
134         ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException;
135 
136 }