info.magnolia.cms.core.search
Class QueryImpl

java.lang.Object
  extended by info.magnolia.cms.core.search.QueryImpl
All Implemented Interfaces:
Query

public class QueryImpl
extends Object
implements Query

Wrapping a JCR Query. Date: Mar 29, 2005 Time: 2:57:55 PM

Author:
Sameer Charles

Field Summary
protected  HierarchyManager hm
           
protected  long limit
           
protected  javax.jcr.query.Query query
           
 
Fields inherited from interface info.magnolia.cms.core.search.Query
SQL, XPATH
 
Constructor Summary
protected QueryImpl(javax.jcr.query.Query query, HierarchyManager hm)
           
 
Method Summary
 QueryResult execute()
          Description inherited from javax.jcr.query.Query#execute()
Executes this query and returns a QueryResult.
 String getLanguage()
          Description inherited from javax.jcr.query.Query#getLanguage()
Returns the language set for this query.
 String getStatement()
          Description inherited from javax.jcr.query.Query#getStatement()
Returns the statement set for this query.
 String getStoredQueryPath()
          Description inherited from javax.jcr.query.Query#getStoredQueryPath()
If this is a Query object that has been stored using Query.storeAsNode(java.lang.String) (regardless of whether it has been saved yet) or retrieved using QueryManager.getQuery(javax.jcr.Node)), then this method returns the path of the nt:query node that stores the query.
 void setLimit(long limit)
          Restrict the result size of subsequent Query.execute() invocations to the given number of objects.
 javax.jcr.Node storeAsNode(String s)
          Description inherited from javax.jcr.query.Query#storeAsNode()
Creates a node representing this Query in content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

query

protected javax.jcr.query.Query query

hm

protected HierarchyManager hm

limit

protected long limit
Constructor Detail

QueryImpl

protected QueryImpl(javax.jcr.query.Query query,
                    HierarchyManager hm)
Method Detail

setLimit

public void setLimit(long limit)
Description copied from interface: Query
Restrict the result size of subsequent Query.execute() invocations to the given number of objects.

Use this method if the query result can be large, but you are interested only in the first few objects. This will avoid the rest of the result objects to be instantiated, resulting in a huge performance gain for large results and small limit numbers.

The performance gain may be defeated if your query returns a lot of nodes of the "wrong" nodetype, resulting in QueryResult.getContent(String) to iterate often before the limit is reached. So make sure your query yields only nodes with the required nodetype.

Specified by:
setLimit in interface Query
Parameters:
limit - the maximum result size, initial value is Long.MAX_VALUE

execute

public QueryResult execute()
                    throws javax.jcr.RepositoryException
Description copied from interface: Query
Description inherited from javax.jcr.query.Query#execute()
Executes this query and returns a QueryResult.

Specified by:
execute in interface Query
Returns:
a QueryResult
Throws:
javax.jcr.RepositoryException - if an error occurs

getStatement

public String getStatement()
Description copied from interface: Query
Description inherited from javax.jcr.query.Query#getStatement()
Returns the statement set for this query.

Specified by:
getStatement in interface Query
Returns:
the query statement.

getLanguage

public String getLanguage()
Description copied from interface: Query
Description inherited from javax.jcr.query.Query#getLanguage()
Returns the language set for this query. This will be one of the query language constants returned by QueryManager.getSupportedQueryLanguages().

Specified by:
getLanguage in interface Query
Returns:
the query language.

getStoredQueryPath

public String getStoredQueryPath()
                          throws javax.jcr.ItemNotFoundException,
                                 javax.jcr.RepositoryException
Description copied from interface: Query
Description inherited from javax.jcr.query.Query#getStoredQueryPath()
If this is a Query object that has been stored using Query.storeAsNode(java.lang.String) (regardless of whether it has been saved yet) or retrieved using QueryManager.getQuery(javax.jcr.Node)), then this method returns the path of the nt:query node that stores the query. If this is a transient query (that is, a Query object created with QueryManager.createQuery(java.lang.String, java.lang.String) but not yet stored) then this method throws an ItemNotFoundException.

Specified by:
getStoredQueryPath in interface Query
Returns:
path of the node representing this query.
Throws:
javax.jcr.ItemNotFoundException - if this query is not a stored query.
javax.jcr.RepositoryException - if another error occurs.

storeAsNode

public javax.jcr.Node storeAsNode(String s)
                           throws javax.jcr.ItemExistsException,
                                  javax.jcr.PathNotFoundException,
                                  javax.jcr.version.VersionException,
                                  javax.jcr.nodetype.ConstraintViolationException,
                                  javax.jcr.lock.LockException,
                                  javax.jcr.UnsupportedRepositoryOperationException,
                                  javax.jcr.RepositoryException
Description copied from interface: Query
Description inherited from javax.jcr.query.Query#storeAsNode()
Creates a node representing this Query in content.

In a level 1 repository this method throws an UnsupportedRepositoryOperationException.

In a level 2 repository it creates a node of type nt:query at absPath and returns that node.

In order to persist the newly created node, a save must be performed that includes the parent of this new node within its scope. In other words, either a Session.save or an Item.save on the parent or higher-degree ancestor of absPath must be performed.

An ItemExistsException will be thrown either immediately (by this method), or on save, if an item at the specified path already exists and same-name siblings are not allowed. Implementations may differ on when this validation is performed.

A PathNotFoundException will be thrown either immediately , or on save, if the specified path implies intermediary nodes that do not exist. Implementations may differ on when this validation is performed.

A ConstraintViolationExceptionwill be thrown either immediately or on save, if adding the node would violate a node type or implementation-specific constraintor if an attempt is made to add a node as the child of a property. Implementations may differ on when this validation is performed.

A VersionException will be thrown either immediately (by this method), or on save, if the node to which the new child is being added is versionable and checked-in or is non-versionable but its nearest versionable ancestor is checked-in. Implementations may differ on when this validation is performed.

A LockException will be thrown either immediately (by this method), or on save, if a lock prevents the addition of the node. Implementations may differ on when this validation is performed.

Specified by:
storeAsNode in interface Query
Returns:
the newly created node.
Throws:
javax.jcr.ItemExistsException - if an item at the specified path already exists, same-name siblings are not allowed and this implementation performs this validation immediately instead of waiting until save.
javax.jcr.PathNotFoundException - if the specified path implies intermediary Nodes that do not exist or the last element of relPath has an index, and this implementation performs this validation immediately instead of waiting until save.
javax.jcr.version.VersionException - if the node to which the new child is being added is versionable and checked-in or is non-versionable but its nearest versionable ancestor is checked-in and this implementation performs this validation immediately instead of waiting until save.
javax.jcr.nodetype.ConstraintViolationException - if a node type or implementation-specific constraint is violated or if an attempt is made to add a node as the child of a property and this implementation performs this validation immediately instead of waiting until save.
javax.jcr.lock.LockException - if a lock prevents the addition of the node and this implementation performs this validation immediately instead of waiting until save.
javax.jcr.UnsupportedRepositoryOperationException - in a level 1 implementation.
javax.jcr.RepositoryException - if another error occurs or if the relPath provided has an index on its final element.


Copyright © 2003-2012 Magnolia International Ltd.. All Rights Reserved.