Class QueryBuilder<C,F>
- java.lang.Object
-
- org.forgerock.openam.sm.datalayer.api.query.QueryBuilder<C,F>
-
- Type Parameters:
C- The type of connection that will be used.F- The type of filter (if any) that will be supported.
- Direct Known Subclasses:
LdapQueryBuilder,QueryBuilder
public abstract class QueryBuilder<C,F> extends Object
Fluent class responsible for constructing queries for the data store. This class will handle the details around preparing a query and executing the query, including processing the return results. Uses Token as its main means of expressing the data returned from the data store and so is intended for use with the Core Token Service.
-
-
Constructor Summary
Constructors Constructor Description QueryBuilder(Debug debug)Default constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Iterator<Collection<Token>>execute(C connection)Perform the query and return the results as processed Token instances.Iterator<Collection<PartialToken>>executeAttributeQuery(C connection)Perform an Attribute based query against the persistent store.abstract ContinuousQueryexecuteContinuousQuery(ContinuousQueryListener listener)Attaches a listener to a connection which will continually return its results.abstract <T> Iterator<Collection<T>>executeRawResults(C connection, Class<T> returnType)Creates an iterator that contains pages of results (if paging not requested, one page is returned).booleanisPagingResults()Indicates that the QueryBuilder is paging the search results, and subsequent calls are required to collect the rest of the results.QueryBuilder<C,F>limitResultsTo(int maxSize)Limit the number of results returned from this query to the given amount.QueryBuilder<C,F>pageResultsBy(int pageSize)The search results can be paged, in which case successive calls to the iterator's next method will return each page.QueryBuilder<C,F>returnTheseAttributes(Collection<CoreTokenField> returnFields)Limit the search to return only the named attributes.QueryBuilder<C,F>returnTheseAttributes(CoreTokenField... returnFields)Limit the search to return only the named attributes.QueryBuilder<C,F>withFilter(F filter)Assign a filter to the query.QueryBuilder<C,F>within(org.forgerock.util.time.Duration timeLimit)Limit the amount of time within this query should finish.
-
-
-
Constructor Detail
-
QueryBuilder
public QueryBuilder(Debug debug)
Default constructor.
-
-
Method Detail
-
limitResultsTo
public QueryBuilder<C,F> limitResultsTo(int maxSize)
Limit the number of results returned from this query to the given amount.- Parameters:
maxSize- Positive number, zero indicates no limit.- Returns:
- The QueryBuilder instance.
-
within
public QueryBuilder<C,F> within(org.forgerock.util.time.Duration timeLimit)
Limit the amount of time within this query should finish. The default behavior is to have no time limit associated with the query.- Parameters:
timeLimit- The time limit associated with this query.- Returns:
- The QueryBuilder instance.
-
pageResultsBy
public QueryBuilder<C,F> pageResultsBy(int pageSize)
The search results can be paged, in which case successive calls to the iterator's next method will return each page.- Parameters:
pageSize- The size of each page of results.- Returns:
- The QueryBuilder instance.
-
isPagingResults
public boolean isPagingResults()
Indicates that the QueryBuilder is paging the search results, and subsequent calls are required to collect the rest of the results.- Returns:
- True if paging has been initialised, false if not.
-
returnTheseAttributes
public QueryBuilder<C,F> returnTheseAttributes(CoreTokenField... returnFields)
Limit the search to return only the named attributes.- Parameters:
returnFields- Array of CoreTokenField which are required in the results.- Returns:
- The QueryBuilder instance.
- Throws:
IllegalArgumentException- If array was null or empty.
-
returnTheseAttributes
public QueryBuilder<C,F> returnTheseAttributes(Collection<CoreTokenField> returnFields)
Limit the search to return only the named attributes.- Parameters:
returnFields- Collection of CoreTokenField that are required in the search results.- Returns:
- The QueryBuilder instance.
- Throws:
IllegalArgumentException- If the requested fields were null or empty.
-
withFilter
public QueryBuilder<C,F> withFilter(F filter)
Assign a filter to the query. This can be a complex filter and is handled by the QueryFilter class.- Parameters:
filter- An OpenDJ SDK Filter to assign to the query.- Returns:
- The QueryBuilder instance.
-
executeAttributeQuery
public Iterator<Collection<PartialToken>> executeAttributeQuery(C connection)
Perform an Attribute based query against the persistent store. An attribute query is one where we are interested in specific attributes from the Tokens rather than all attributes assigned to the matched Tokens. This can be more performant than requesting back all attributes of a Token first.- Parameters:
connection- The connection used to perform the request.- Returns:
- An iterator of non null but possibly empty collections. If paging is not requested, the iterator will have one entry in it. Note that the next method may throw a DataLayerRuntimeException in the event of a failure.
-
executeRawResults
public abstract <T> Iterator<Collection<T>> executeRawResults(C connection, Class<T> returnType)
Creates an iterator that contains pages of results (if paging not requested, one page is returned). It is recommended that the query itself is performed in the iterator rather than in the implementation of this method.- Type Parameters:
T- The type being returned.- Parameters:
connection- The connection to query.returnType- The type of object wanted.- Returns:
- An iterator of collections of objects.
-
execute
public Iterator<Collection<Token>> execute(C connection)
Perform the query and return the results as processed Token instances.- Parameters:
connection- The connection used to perform the request.- Returns:
- An iterator of non null but possibly empty collections. If paging is not requested, the iterator will have one entry in it. Note that the next method may throw a DataLayerRuntimeException in the event of a failure.
-
executeContinuousQuery
public abstract ContinuousQuery executeContinuousQuery(ContinuousQueryListener listener) throws DataLayerException
Attaches a listener to a connection which will continually return its results. The listener will perform appropriate actions in response to the data returned from the connection.- Parameters:
listener- The listening class used to process the returned data.- Throws:
DataLayerException- An error forming the continuous query connection.
-
-