1 /** 2 * This file Copyright (c) 2003-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.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 * Equivalent to {@link javax.jcr.query.Query} but working with {@link Content} objects. 49 * Date: Apr 4, 2005 Time: 11:02:35 AM 50 * @author Sameer Charles 51 */ 52 53 public interface Query { 54 55 String XPATH = "xpath"; //$NON-NLS-1$ 56 57 String SQL = "sql"; //$NON-NLS-1$ 58 59 /** 60 * <i>Description inherited from javax.jcr.query.Query#execute()</i><br> 61 * Executes this query and returns a <code>{@link QueryResult}</code>. 62 * @return a <code>QueryResult</code> 63 * @throws RepositoryException if an error occurs 64 */ 65 QueryResult execute() throws RepositoryException; 66 67 /** 68 * Restrict the result size of subsequent {@link #execute()} invocations to the given 69 * number of objects.<p> 70 * Use this method if the query result can be large, but you are interested 71 * only in the first few objects. This will avoid the rest of the result objects 72 * to be instantiated, resulting in a huge performance gain for large 73 * results and small limit numbers.<p> 74 * The performance gain may be defeated if your query returns a lot of nodes 75 * of the "wrong" nodetype, resulting in {@link QueryResult#getContent(String)} to 76 * iterate often before the limit is reached. So make sure your query yields only nodes with the 77 * required nodetype. 78 * @param limit the maximum result size, initial value is {@link Long#MAX_VALUE} 79 */ 80 void setLimit(long limit); 81 82 /** 83 * <i>Description inherited from javax.jcr.query.Query#getStatement()</i><br> 84 * Returns the statement set for this query. 85 * @return the query statement. 86 */ 87 String getStatement(); 88 89 /** 90 * <i>Description inherited from javax.jcr.query.Query#getLanguage()</i><br> 91 * Returns the language set for this query. This will be one of the query language constants returned by 92 * {@link QueryManager#getSupportedQueryLanguages}. 93 * @return the query language. 94 */ 95 String getLanguage(); 96 97 /** 98 * <i>Description inherited from javax.jcr.query.Query#getStoredQueryPath()</i><br> 99 * If this is a <code>Query</code> object that has been stored using {@link Query#storeAsNode} (regardless of 100 * whether it has been <code>save</code>d yet) or retrieved using {@link QueryManager#getQuery}), then this 101 * method returns the path of the <code>nt:query</code> node that stores the query. If this is a transient query 102 * (that is, a <code>Query</code> object created with {@link QueryManager#createQuery} but not yet stored) then 103 * this method throws an <code>ItemNotFoundException</code>. 104 * @return path of the node representing this query. 105 * @throws ItemNotFoundException if this query is not a stored query. 106 * @throws RepositoryException if another error occurs. 107 */ 108 String getStoredQueryPath() throws ItemNotFoundException, RepositoryException; 109 110 /** 111 * <i>Description inherited from javax.jcr.query.Query#storeAsNode()</i><br> 112 * Creates a node representing this <code>Query</code> in content. <p/> In a level 1 repository this method throws 113 * an <code>UnsupportedRepositoryOperationException</code>. <p/> In a level 2 repository it creates a node of 114 * type <code>nt:query</code> at <code>absPath</code> and returns that node. <p/> In order to persist the newly 115 * created node, a <code>save</code> must be performed that includes <i>the parent</i> of this new node within 116 * its scope. In other words, either a <code>Session.save</code> or an <code>Item.save</code> on the parent or 117 * higher-degree ancestor of <code>absPath</code> must be performed. <p/> An <code>ItemExistsException</code> 118 * will be thrown either immediately (by this method), or on <code>save</code>, if an item at the specified path 119 * already exists and same-name siblings are not allowed. Implementations may differ on when this validation is 120 * performed. <p/> A <code>PathNotFoundException</code> will be thrown either immediately , or on 121 * <code>save</code>, if the specified path implies intermediary nodes that do not exist. Implementations may 122 * differ on when this validation is performed. <p/> A <code>ConstraintViolationException</code>will be thrown 123 * either immediately or on <code>save</code>, if adding the node would violate a node type or 124 * implementation-specific constraintor if an attempt is made to add a node as the child of a property. 125 * Implementations may differ on when this validation is performed. <p/> A <code>VersionException</code> will be 126 * thrown either immediately (by this method), or on <code>save</code>, if the node to which the new child is 127 * being added is versionable and checked-in or is non-versionable but its nearest versionable ancestor is 128 * checked-in. Implementations may differ on when this validation is performed. <p/> A <code>LockException</code> 129 * will be thrown either immediately (by this method), or on <code>save</code>, if a lock prevents the addition 130 * of the node. Implementations may differ on when this validation is performed. 131 * @return the newly created node. 132 * @throws ItemExistsException if an item at the specified path already exists, same-name siblings are not allowed 133 * and this implementation performs this validation immediately instead of waiting until <code>save</code>. 134 * @throws PathNotFoundException if the specified path implies intermediary <code>Node</code>s that do not exist 135 * or the last element of <code>relPath</code> has an index, and this implementation performs this validation 136 * immediately instead of waiting until <code>save</code>. 137 * @throws ConstraintViolationException if a node type or implementation-specific constraint is violated or if an 138 * attempt is made to add a node as the child of a property and this implementation performs this validation 139 * immediately instead of waiting until <code>save</code>. 140 * @throws VersionException if the node to which the new child is being added is versionable and checked-in or is 141 * non-versionable but its nearest versionable ancestor is checked-in and this implementation performs this 142 * validation immediately instead of waiting until <code>save</code>. 143 * @throws LockException if a lock prevents the addition of the node and this implementation performs this 144 * validation immediately instead of waiting until <code>save</code>. 145 * @throws UnsupportedRepositoryOperationException in a level 1 implementation. 146 * @throws RepositoryException if another error occurs or if the <code>relPath</code> provided has an index on its 147 * final element. 148 */ 149 Node storeAsNode(String s) throws ItemExistsException, PathNotFoundException, VersionException, 150 ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException; 151 152 }