com.ibm.workplace.wcm.api.query
Interface Query


public interface Query

An interface defining a query for QueryService.

Here is an example of how to query the first content directly under the SiteArea parentSiteArea that has an element called "myElement":

  Content contentWithMyElement;
  QueryService queryService = workspace.getQueryService();
  Query query = queryService.createQuery(Content.class);
  query.addParentId(parentSiteArea.getId(), QueryDepth.CHILDREN);
  try
  {
     ResultIterator resultIterator = queryService.execute(query);
     if (resultIterator.hasNext())
     {
        Content childContent = (Content) resultIterator.next();
        if (childContent.hasComponent("myElement"))
        {
           contentWithMyElement = childContent;
        }
     }
  }
  catch (QueryServiceException e)
  {
     // Handle exception
  } 
 

Since:
7.0
See Also:
QueryService

Method Summary
 void addParentId(Identity parentId, QueryDepth depth)
          Instructs this query to find children of the parent document.
 void addSelector(Selector selector)
          Adds a Selector to this Query.
 void addSelectors(Selector... selectors)
          Adds multiple Selector to this Query.
 void addSort(Sort sort)
          Adds a Sort to this Query.
 void clearSorts()
          Clean the sort setting for this query.
 QueryDepth getDepth()
          Returns whether this query will find descendant children of the parents or not.
 java.util.Set<Identity> getParentIds()
          Return a Set of parent Identity.
 Query getParentQuery()
          Returns the parent query.
 java.util.List<Selector> getSelectors()
          Returns a List that contains all the Selector in this Query.
 java.util.List<Sort> getSorts()
          Returns a List of the Sort in this query.
 boolean hasParents()
          Returns true if this query has a parent Query.
 boolean isIdQuery()
          Indicates whether this is query for DocumentId or not.
 boolean isObjectQuery()
          Indicates whether this is query for Document or not.
 void returnIds()
          Instructs the QueryService to return DocumentId instead of Document.
 void returnObjects()
          Instructs the QueryService to return Document instead of DocumentId.
 void setAccessFilter(AccessFilter filter)
          Set the access filter for this query.
 void setDepth(QueryDepth depth)
          If a Query is scoped to parents, the QueryDepth tells the Query to return all descendants or children of the parent(s).
 void setParentIds(java.util.Collection<Identity> parentIds, QueryDepth depth)
          Instructs this query to find children of the parent documents.
 void setParentQuery(Query parentQuery, QueryDepth depth)
          Instructs this query to find children of the parent documents.
 void setSorts(Sort... sorts)
          Set all of the sorts, overriding any previous sorts added.
 

Method Detail

addSelector

void addSelector(Selector selector)
Adds a Selector to this Query.

Parameters:
selector - selector to be added

addSelectors

void addSelectors(Selector... selectors)
Adds multiple Selector to this Query.

Parameters:
selectors - selectors to be added
Since:
8.0

getSelectors

java.util.List<Selector> getSelectors()
Returns a List that contains all the Selector in this Query.

Returns:
a list of Selector

returnIds

void returnIds()
Instructs the QueryService to return DocumentId instead of Document. By default, the QueryService will return Documents.


returnObjects

void returnObjects()
Instructs the QueryService to return Document instead of DocumentId. By default, the QueryService will return Documents.


isObjectQuery

boolean isObjectQuery()
Indicates whether this is query for Document or not.

Returns:
true if the query result will return Document

isIdQuery

boolean isIdQuery()
Indicates whether this is query for DocumentId or not.

Returns:
true if the query result will return DocumentId

addSort

void addSort(Sort sort)
Adds a Sort to this Query. It is possible to add multiple Sort in one Query, the result will be sorted by adding order.

Parameters:
sort - Sort to be added

getSorts

java.util.List<Sort> getSorts()
Returns a List of the Sort in this query.

Returns:
a List of Sort

setSorts

void setSorts(Sort... sorts)
Set all of the sorts, overriding any previous sorts added.

Parameters:
sorts - the sorts to set

clearSorts

void clearSorts()
Clean the sort setting for this query.


addParentId

void addParentId(Identity parentId,
                 QueryDepth depth)
Instructs this query to find children of the parent document.

Note 1: If a parent query is also defined (via the setParentQuery method), then this query will process the children of the specified parents who also satisfy the parent query.

Note 2: Will only return children from DRAFT parents when the query is executed under a Project QueryScope

Note 3: The value of depth is global to the query and the value passed will override any previous value

Parameters:
parentId - the id of the parent document
depth - find all descendant children

setParentIds

void setParentIds(java.util.Collection<Identity> parentIds,
                  QueryDepth depth)
Instructs this query to find children of the parent documents.

Note 1: If a parent query is also defined (via the setParentQuery method), then this query will process the children of the specified parents who also satisfy the parent query.

Note 2: Will only return children from DRAFT parents when the query is executed under a Project QueryScope

Note 3: The value of depth is global to the query and the value passed will override any previous value

Note 4: If the collection contains duplicates these will be dropped

Parameters:
parentIds - collection of parent ids
depth - find all descendant children

getParentIds

java.util.Set<Identity> getParentIds()
Return a Set of parent Identity.

Returns:
A set of parent identities, null if there is no parent.

setParentQuery

void setParentQuery(Query parentQuery,
                    QueryDepth depth)
Instructs this query to find children of the parent documents.

Note 1: If parent IDs are also defined (via the addParentId / setParentIds methods), then this query will process the children of the defined parents who satisfy the parent query.

Note 2: Children will only be returned from PUBLISHED parents. If your parentQuery needs to be Project-Aware, then first execute it under a Project QueryScope then set the returned Parent IDs on the Query via the Query.setParentIds / Query.addParentId methods

Note 3: The value of depth is global to the query and the value passed will override any previous value

Parameters:
parentQuery - query to locate parent documents
depth - find all descendant children

getParentQuery

Query getParentQuery()
Returns the parent query.

Returns:
the parent query or null if no parent query is set.

setDepth

void setDepth(QueryDepth depth)
If a Query is scoped to parents, the QueryDepth tells the Query to return all descendants or children of the parent(s).

This has no effect if the query is not scoped to parents

Parameters:
depth -

setAccessFilter

void setAccessFilter(AccessFilter filter)
Set the access filter for this query. An AccessFiler allows the results of a query to be filtered based on the access rights of specific users.

Parameters:
filter -

getDepth

QueryDepth getDepth()
Returns whether this query will find descendant children of the parents or not.

Returns:
whether this query will find descendant children of the parents

hasParents

boolean hasParents()
Returns true if this query has a parent Query. i.e. if this query is scoped by parents

Returns:
true if the query has parents; false otherwise