public interface Query<S extends Storable>
Storable
objects.
Queries are immutable representations of an action – they do not
contain any Storable instances. The apparent mutators (with, et al) do not
actually modify the Query. Instead, they return another Query instance which
has the requested modification. To obtain an initial Query instance, call
one of the Storage
query methods.
Query objects are usually compiled and cached, and the same instance can be re-used for future queries. This is possible because queries are immutable and naturally thread-safe.
Modifier and Type | Interface and Description |
---|---|
static interface |
Query.Controller
Controller instance can be used to abort query operations.
|
static class |
Query.Timeout
Timeout controller, for aborting long running queries.
|
Modifier and Type | Method and Description |
---|---|
<T extends S> |
after(T start)
Returns a query which fetches results for this query after a given
starting point, which is useful for re-opening a cursor.
|
Query<S> |
and(Filter<S> filter)
Returns a new query which has another
filter logically "and"ed to this, potentially reducing the amount of
results. |
Query<S> |
and(java.lang.String filter)
Returns a new query which has another
filter logically "and"ed to this, potentially reducing the amount of
results. |
long |
count()
Returns a count of all results matched by this query.
|
long |
count(Query.Controller controller)
Returns a count of all results matched by this query.
|
void |
deleteAll()
Deletes zero or more matching objects.
|
void |
deleteAll(Query.Controller controller)
Deletes zero or more matching objects.
|
void |
deleteOne()
Deletes one matching object.
|
void |
deleteOne(Query.Controller controller)
Deletes one matching object.
|
boolean |
equals(java.lang.Object obj) |
boolean |
exists()
Returns true if any results are matched by this query.
|
boolean |
exists(Query.Controller controller)
Returns true if any results are matched by this query.
|
Cursor<S> |
fetch()
Fetches results for this query.
|
Cursor<S> |
fetch(Query.Controller controller)
Fetches results for this query.
|
<T extends S> |
fetchAfter(T start)
Fetches results for this query after a given starting point, which is
useful for re-opening a cursor.
|
<T extends S> |
fetchAfter(T start,
Query.Controller controller)
Fetches results for this query after a given starting point, which is
useful for re-opening a cursor.
|
Cursor<S> |
fetchSlice(long from,
java.lang.Long to)
Fetches a slice of results for this query, as defined by a numerical
range.
|
Cursor<S> |
fetchSlice(long from,
java.lang.Long to,
Query.Controller controller)
Fetches a slice of results for this query, as defined by a numerical
range.
|
int |
getBlankParameterCount()
Returns the amount of blank parameters that need to be filled in.
|
Filter<S> |
getFilter()
Returns the query's filter.
|
FilterValues<S> |
getFilterValues()
Returns the query's filter values, which is null if filter has no
parameters.
|
java.lang.Class<S> |
getStorableType()
Returns the specific type of Storable managed by this object.
|
int |
hashCode() |
S |
loadOne()
Attempts to load exactly one matching object.
|
S |
loadOne(Query.Controller controller)
Attempts to load exactly one matching object.
|
Query<S> |
not()
Returns a new query which produces all the results not supplied in this
query.
|
Query<S> |
or(Filter<S> filter)
Returns a new query which has another
filter logically "or"ed to this, potentially increasing the amount of
results. |
Query<S> |
or(java.lang.String filter)
Returns a new query which has another
filter logically "or"ed to this, potentially increasing the amount of
results. |
Query<S> |
orderBy(java.lang.String... properties)
Returns a copy of this query ordered by specific property values.
|
Query<S> |
orderBy(java.lang.String property)
Returns a copy of this query ordered by a specific property value.
|
boolean |
printNative()
Print the native query to standard out, which is useful for performance
analysis.
|
boolean |
printNative(java.lang.Appendable app)
Prints the native query to any appendable, which is useful for
performance analysis.
|
boolean |
printNative(java.lang.Appendable app,
int indentLevel)
Prints the native query to any appendable, which is useful for
performance analysis.
|
boolean |
printPlan()
Prints the query excecution plan to standard out, which is useful for
performance analysis.
|
boolean |
printPlan(java.lang.Appendable app)
Prints the query excecution plan to any appendable, which is useful for
performance analysis.
|
boolean |
printPlan(java.lang.Appendable app,
int indentLevel)
Prints the query excecution plan to any appendable, which is useful for
performance analysis.
|
java.lang.String |
toString()
Returns a description of the query filter and any other arguments.
|
boolean |
tryDeleteOne()
Deletes zero or one matching objects.
|
boolean |
tryDeleteOne(Query.Controller controller)
Deletes zero or one matching objects.
|
S |
tryLoadOne()
Tries to load one record, but returns null if nothing was found.
|
S |
tryLoadOne(Query.Controller controller)
Tries to load one record, but returns null if nothing was found.
|
Query<S> |
with(boolean value)
Returns a copy of this Query with the next blank parameter filled in.
|
Query<S> |
with(byte value)
Returns a copy of this Query with the next blank parameter filled in.
|
Query<S> |
with(char value)
Returns a copy of this Query with the next blank parameter filled in.
|
Query<S> |
with(double value)
Returns a copy of this Query with the next blank parameter filled in.
|
Query<S> |
with(float value)
Returns a copy of this Query with the next blank parameter filled in.
|
Query<S> |
with(int value)
Returns a copy of this Query with the next blank parameter filled in.
|
Query<S> |
with(long value)
Returns a copy of this Query with the next blank parameter filled in.
|
Query<S> |
with(java.lang.Object value)
Returns a copy of this Query with the next blank parameter filled in.
|
Query<S> |
with(short value)
Returns a copy of this Query with the next blank parameter filled in.
|
Query<S> |
withValues(java.lang.Object... values)
Returns a copy of this Query with the next blank parameters filled in.
|
java.lang.Class<S> getStorableType()
FilterValues<S> getFilterValues()
int getBlankParameterCount()
Query<S> with(int value)
value
- parameter value to fill injava.lang.IllegalStateException
- if no blank parametersjava.lang.IllegalArgumentException
- if type doesn't matchQuery<S> with(long value)
value
- parameter value to fill injava.lang.IllegalStateException
- if no blank parametersjava.lang.IllegalArgumentException
- if type doesn't matchQuery<S> with(float value)
value
- parameter value to fill injava.lang.IllegalStateException
- if no blank parametersjava.lang.IllegalArgumentException
- if type doesn't matchQuery<S> with(double value)
value
- parameter value to fill injava.lang.IllegalStateException
- if no blank parametersjava.lang.IllegalArgumentException
- if type doesn't matchQuery<S> with(boolean value)
value
- parameter value to fill injava.lang.IllegalStateException
- if no blank parametersjava.lang.IllegalArgumentException
- if type doesn't matchQuery<S> with(char value)
value
- parameter value to fill injava.lang.IllegalStateException
- if no blank parametersjava.lang.IllegalArgumentException
- if type doesn't matchQuery<S> with(byte value)
value
- parameter value to fill injava.lang.IllegalStateException
- if no blank parametersjava.lang.IllegalArgumentException
- if type doesn't matchQuery<S> with(short value)
value
- parameter value to fill injava.lang.IllegalStateException
- if no blank parametersjava.lang.IllegalArgumentException
- if type doesn't matchQuery<S> with(java.lang.Object value)
value
- parameter value to fill injava.lang.IllegalStateException
- if no blank parametersjava.lang.IllegalArgumentException
- if type doesn't matchQuery<S> withValues(java.lang.Object... values)
values
- parameter values to fill in; if null or empty, this
Query instance is returnedjava.lang.IllegalStateException
- if no blank parameters or if too many
parameter values suppliedjava.lang.IllegalArgumentException
- if any type doesn't matchQuery<S> and(java.lang.String filter) throws FetchException
filter
logically "and"ed to this, potentially reducing the amount of
results.filter
- query filter expressionFetchException
- if storage layer throws an exceptionjava.lang.IllegalStateException
- if any blank parameters in this query, or
if this query is already guaranteed to fetch nothingjava.lang.IllegalArgumentException
- if filter is nullMalformedFilterException
- if expression is malformedjava.lang.UnsupportedOperationException
- if given filter is unsupported by repositoryQuery<S> and(Filter<S> filter) throws FetchException
filter
logically "and"ed to this, potentially reducing the amount of
results.filter
- query filterFetchException
- if storage layer throws an exceptionjava.lang.IllegalStateException
- if any blank parameters in this query, or
if this query is already guaranteed to fetch nothingjava.lang.IllegalArgumentException
- if filter is nulljava.lang.UnsupportedOperationException
- if given filter is unsupported by repositoryQuery<S> or(java.lang.String filter) throws FetchException
filter
logically "or"ed to this, potentially increasing the amount of
results.filter
- query filter expressionFetchException
- if storage layer throws an exceptionjava.lang.IllegalStateException
- if any blank parameters in this query, or
if this query is already guaranteed to fetch everythingjava.lang.IllegalArgumentException
- if filter is nullMalformedFilterException
- if expression is malformedjava.lang.UnsupportedOperationException
- if given filter is unsupported by repositoryQuery<S> or(Filter<S> filter) throws FetchException
filter
logically "or"ed to this, potentially increasing the amount of
results.filter
- query filterFetchException
- if storage layer throws an exceptionjava.lang.IllegalStateException
- if any blank parameters in this query, or
if this query is already guaranteed to fetch everythingjava.lang.IllegalArgumentException
- if filter is nulljava.lang.UnsupportedOperationException
- if given filter is unsupported by repositoryQuery<S> not() throws FetchException
FetchException
- if storage layer throws an exceptionjava.lang.UnsupportedOperationException
- if new query is unsupported by repositoryQuery<S> orderBy(java.lang.String property) throws FetchException
Note: Specification of ordering properties is not cumulative. Calling this method will first remove any previous ordering properties.
property
- name of property to order byFetchException
- if storage layer throws an exceptionjava.lang.IllegalArgumentException
- if property is null or is not a member
of type Sjava.lang.UnsupportedOperationException
- if given ordering, combined with
query filter, is unsupported by repositoryQuery<S> orderBy(java.lang.String... properties) throws FetchException
Note: Specification of ordering properties is not cumulative. Calling this method will first remove any previous ordering properties.
properties
- names of properties to order byFetchException
- if storage layer throws an exceptionjava.lang.IllegalArgumentException
- if any property is null or is not a
member of type Sjava.lang.UnsupportedOperationException
- if given ordering, combined with
query filter, is unsupported by repository<T extends S> Query<S> after(T start) throws FetchException
ordering
. If not a total ordering, then query may start at an earlier
position.
Note: The returned query can be very expensive to fetch from repeatedly, if the query needs to perform a sort operation. Ideally, the query ordering should match the natural ordering of an index or key.
start
- storable to attempt to start after; if null, this query is
returnedjava.lang.IllegalStateException
- if any blank parameters in this queryFetchException
- if storage layer throws an exceptionCursor<S> fetch() throws FetchException
java.lang.IllegalStateException
- if any blank parameters in this queryFetchException
- if storage layer throws an exceptionRepository.enterTransaction(IsolationLevel)
Cursor<S> fetch(Query.Controller controller) throws FetchException
controller
- optional controller which can abort query operationjava.lang.IllegalStateException
- if any blank parameters in this queryFetchException
- if storage layer throws an exceptionRepository.enterTransaction(IsolationLevel)
Cursor<S> fetchSlice(long from, java.lang.Long to) throws FetchException
ordering
in order for the slice results to be deterministic.from
- zero-based from
record number, inclusiveto
- optional zero-based to
record number, exclusivejava.lang.IllegalStateException
- if any blank parameters in this queryjava.lang.IllegalArgumentException
- if from
is negative or if
from
is more than to
FetchException
- if storage layer throws an exceptionCursor<S> fetchSlice(long from, java.lang.Long to, Query.Controller controller) throws FetchException
ordering
in order for the slice results to be deterministic.from
- zero-based from
record number, inclusiveto
- optional zero-based to
record number, exclusivecontroller
- optional controller which can abort query operationjava.lang.IllegalStateException
- if any blank parameters in this queryjava.lang.IllegalArgumentException
- if from
is negative or if
from
is more than to
FetchException
- if storage layer throws an exception<T extends S> Cursor<S> fetchAfter(T start) throws FetchException
ordering
. If not a total
ordering, then cursor may start at an earlier position.
Note: This method can be very expensive to call repeatedly, if the query needs to perform a sort operation. Ideally, the query ordering should match the natural ordering of an index or key.
Calling fetchAfter(s)
is equivalent to calling after(s).fetch()
.
start
- storable to attempt to start after; if null, fetch all resultsjava.lang.IllegalStateException
- if any blank parameters in this queryFetchException
- if storage layer throws an exceptionRepository.enterTransaction(IsolationLevel)
,
after(T)
<T extends S> Cursor<S> fetchAfter(T start, Query.Controller controller) throws FetchException
ordering
. If not a total
ordering, then cursor may start at an earlier position.
Note: This method can be very expensive to call repeatedly, if the query needs to perform a sort operation. Ideally, the query ordering should match the natural ordering of an index or key.
Calling fetchAfter(s)
is equivalent to calling after(s).fetch()
.
start
- storable to attempt to start after; if null, fetch all resultscontroller
- optional controller which can abort query operationjava.lang.IllegalStateException
- if any blank parameters in this queryFetchException
- if storage layer throws an exceptionRepository.enterTransaction(IsolationLevel)
,
after(T)
S loadOne() throws FetchException
java.lang.IllegalStateException
- if any blank parameters in this queryFetchNoneException
- if no matching record foundFetchMultipleException
- if more than one matching record foundFetchException
- if storage layer throws an exceptionS loadOne(Query.Controller controller) throws FetchException
controller
- optional controller which can abort query operationjava.lang.IllegalStateException
- if any blank parameters in this queryFetchNoneException
- if no matching record foundFetchMultipleException
- if more than one matching record foundFetchException
- if storage layer throws an exceptionS tryLoadOne() throws FetchException
java.lang.IllegalStateException
- if any blank parameters in this queryFetchMultipleException
- if more than one matching record foundFetchException
- if storage layer throws an exceptionS tryLoadOne(Query.Controller controller) throws FetchException
controller
- optional controller which can abort query operationjava.lang.IllegalStateException
- if any blank parameters in this queryFetchMultipleException
- if more than one matching record foundFetchException
- if storage layer throws an exceptionvoid deleteOne() throws PersistException
java.lang.IllegalStateException
- if any blank parameters in this queryPersistNoneException
- if no matching record foundPersistMultipleException
- if more than one record matchesPersistException
- if storage layer throws an exceptionvoid deleteOne(Query.Controller controller) throws PersistException
controller
- optional controller which can abort query operationjava.lang.IllegalStateException
- if any blank parameters in this queryPersistNoneException
- if no matching record foundPersistMultipleException
- if more than one record matchesPersistException
- if storage layer throws an exceptionboolean tryDeleteOne() throws PersistException
java.lang.IllegalStateException
- if any blank parameters in this queryPersistMultipleException
- if more than one record matchesPersistException
- if storage layer throws an exceptionboolean tryDeleteOne(Query.Controller controller) throws PersistException
controller
- optional controller which can abort query operationjava.lang.IllegalStateException
- if any blank parameters in this queryPersistMultipleException
- if more than one record matchesPersistException
- if storage layer throws an exceptionvoid deleteAll() throws PersistException
java.lang.IllegalStateException
- if any blank parameters in this queryPersistException
- if storage layer throws an exceptionvoid deleteAll(Query.Controller controller) throws PersistException
controller
- optional controller which can abort query operationjava.lang.IllegalStateException
- if any blank parameters in this queryPersistException
- if storage layer throws an exceptionlong count() throws FetchException
java.lang.IllegalStateException
- if any blank parameters in this queryFetchException
- if storage layer throws an exceptionlong count(Query.Controller controller) throws FetchException
controller
- optional controller which can abort query operationjava.lang.IllegalStateException
- if any blank parameters in this queryFetchException
- if storage layer throws an exceptionboolean exists() throws FetchException
java.lang.IllegalStateException
- if any blank parameters in this queryFetchException
- if storage layer throws an exceptionboolean exists(Query.Controller controller) throws FetchException
controller
- optional controller which can abort query operationjava.lang.IllegalStateException
- if any blank parameters in this queryFetchException
- if storage layer throws an exceptionboolean printNative()
boolean printNative(java.lang.Appendable app) throws java.io.IOException
app
- append results herejava.io.IOException
boolean printNative(java.lang.Appendable app, int indentLevel) throws java.io.IOException
app
- append results hereindentLevel
- amount to indent text, zero for nonejava.io.IOException
boolean printPlan()
boolean printPlan(java.lang.Appendable app) throws java.io.IOException
app
- append results herejava.io.IOException
boolean printPlan(java.lang.Appendable app, int indentLevel) throws java.io.IOException
app
- append results hereindentLevel
- amount to indent text, zero for nonejava.io.IOException
int hashCode()
hashCode
in class java.lang.Object
boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2006-2013 Amazon Technologies, Inc.. All Rights Reserved.