6.6.10 The Query Object

A new query is created by calling QueryManager.createQuery. The returned Query object has the following methods:

javax.jcr.query.
Query

QueryResult

execute()

Executes this query and returns a QueryResult object.

Throws a RepositoryException if an error occurs.

String

getStatement()

Returns the statement defined for this query.

String

getLanguage()

Returns the language set for this query. This will be one of the strings returned by QueryManager.getSupportedQueryLanguages().

String

getStoredQueryPath()

If this is a Query that has been stored using Query.storeAsNode (regardless of whether it has been saved yet) or retrieved using QueryManager.getQuery, 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 and not yet stored), then this method throws an ItemNotFoundException.

Throws a RepositoryException if another error occurs.

void

storeAsNode(String absPath)

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.

In the context of this method the absPath provided must not have an index on its final element. If it does then a RepositoryException is thrown.

Strictly speaking, the parameter is actually a absolute path to the parent node of the node to be added, appended with the name desired for the new node. It does not specify a position within the child node ordering (if such ordering is supported). If ordering is supported by the node type of the parent node then the new node is appended to the end of the child node list.

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 (by this method), or on save, if the specified path implies intermediary nodes that do not exist. Implementations may differ on when this validation is performed.

A ConstraintViolationException will be thrown either immediately (by this method), or on save, if adding the node would violate a node type or implementation-specific constraint or 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.

A RepositoryException is thrown if another error occurs.

String

XPATH

A string constant representing the XPath query language applied to the document view XML mapping of the workspace.

String

SQL

A string constant representing the SQL query language applied to the database view of the workspace. Support for this language is optional. See 8.5 Searching Repository Content with SQL.