T
- Entity class for which results are returned.public class Query<T>
extends java.lang.Object
implements java.io.Closeable
Use find()
or related methods to fetch the latest results from the BoxStore.
Use property(Property)
to only return values or an aggregate of a single Property.
See the Queries documentation for details.
Modifier and Type | Method and Description |
---|---|
void |
close()
If possible, try to close the query once you are done with it to reclaim resources immediately.
|
long |
count()
Returns the count of Objects matching the query.
|
java.lang.String |
describe()
For logging and testing, returns a string describing this query
like "Query for entity Example with 4 conditions with properties prop1, prop2".
|
java.lang.String |
describeParameters()
For logging and testing, returns a string describing the conditions of this query
like "(prop1 == A AND prop2 is null)".
|
protected void |
finalize()
Explicitly call
close() instead to avoid expensive finalization. |
java.util.List<T> |
find()
Find all Objects matching the query.
|
java.util.List<T> |
find(long offset,
long limit)
Find all Objects matching the query, skipping the first offset results and returning at most limit results.
|
T |
findFirst()
Find the first Object matching the query.
|
long[] |
findIds()
Very efficient way to get just the IDs without creating any objects.
|
long[] |
findIds(long offset,
long limit)
Like
findIds() but with a offset/limit param, e.g. |
LazyList<T> |
findLazy()
|
LazyList<T> |
findLazyCached()
|
T |
findUnique()
Find the unique Object matching the query.
|
void |
forEach(QueryConsumer<T> consumer)
Emits query results one by one to the given consumer (synchronously).
|
PropertyQuery |
property(Property<T> property)
Creates a
PropertyQuery for the given property. |
void |
publish()
Publishes the current data to all subscribed @
DataObserver s. |
long |
remove()
Removes (deletes) all Objects matching the query
|
Query<T> |
setParameter(Property<?> property,
boolean value)
Sets a parameter previously given to the
QueryBuilder to a new value. |
Query<T> |
setParameter(Property<?> property,
byte[] value)
Sets a parameter previously given to the
QueryBuilder to new values. |
Query<T> |
setParameter(Property<?> property,
java.util.Date value)
Sets a parameter previously given to the
QueryBuilder to a new value. |
Query<T> |
setParameter(Property<?> property,
double value)
Sets a parameter previously given to the
QueryBuilder to a new value. |
Query<T> |
setParameter(Property<?> property,
long value)
Sets a parameter previously given to the
QueryBuilder to a new value. |
Query<T> |
setParameter(Property<?> property,
java.lang.String value)
Sets a parameter previously given to the
QueryBuilder to a new value. |
Query<T> |
setParameter(java.lang.String alias,
boolean value)
Sets a parameter previously given to the
QueryBuilder to a new value. |
Query<T> |
setParameter(java.lang.String alias,
byte[] value)
Sets a parameter previously given to the
QueryBuilder to new values. |
Query<T> |
setParameter(java.lang.String alias,
java.util.Date value)
Sets a parameter previously given to the
QueryBuilder to a new value. |
Query<T> |
setParameter(java.lang.String alias,
double value)
Sets a parameter previously given to the
QueryBuilder to a new value. |
Query<T> |
setParameter(java.lang.String alias,
long value)
Sets a parameter previously given to the
QueryBuilder to a new value. |
Query<T> |
setParameter(java.lang.String alias,
java.lang.String value)
Sets a parameter previously given to the
QueryBuilder to a new value. |
Query<T> |
setParameters(Property<?> property,
double value1,
double value2)
Sets a parameter previously given to the
QueryBuilder to new values. |
Query<T> |
setParameters(Property<?> property,
int[] values)
Sets a parameter previously given to the
QueryBuilder to new values. |
Query<T> |
setParameters(Property<?> property,
long[] values)
Sets a parameter previously given to the
QueryBuilder to new values. |
Query<T> |
setParameters(Property<?> property,
long value1,
long value2)
Sets a parameter previously given to the
QueryBuilder to new values. |
Query<T> |
setParameters(Property<?> property,
java.lang.String[] values)
Sets a parameter previously given to the
QueryBuilder to new values. |
Query<T> |
setParameters(java.lang.String alias,
double value1,
double value2)
Sets a parameter previously given to the
QueryBuilder to new values. |
Query<T> |
setParameters(java.lang.String alias,
int[] values)
Sets a parameter previously given to the
QueryBuilder to new values. |
Query<T> |
setParameters(java.lang.String alias,
long[] values)
Sets a parameter previously given to the
QueryBuilder to new values. |
Query<T> |
setParameters(java.lang.String alias,
long value1,
long value2)
Sets a parameter previously given to the
QueryBuilder to new values. |
Query<T> |
setParameters(java.lang.String alias,
java.lang.String[] values)
Sets a parameter previously given to the
QueryBuilder to new values. |
SubscriptionBuilder<java.util.List<T>> |
subscribe()
A
DataObserver can be subscribed to data changes using the returned builder. |
SubscriptionBuilder<java.util.List<T>> |
subscribe(DataSubscriptionList dataSubscriptionList)
Convenience for
subscribe() with a subsequent call to
SubscriptionBuilder.dataSubscriptionList(DataSubscriptionList) . |
protected void finalize() throws java.lang.Throwable
close()
instead to avoid expensive finalization.finalize
in class java.lang.Object
java.lang.Throwable
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
@Nullable public T findFirst()
@Nullable public T findUnique()
NonUniqueResultException
- if result was not unique@Nonnull public java.util.List<T> find()
@Nonnull public java.util.List<T> find(long offset, long limit)
@Nonnull public long[] findIds()
Note: a filter set with QueryBuilder.filter(QueryFilter)
will be silently ignored!
@Nonnull public long[] findIds(long offset, long limit)
findIds()
but with a offset/limit param, e.g. for pagination.
Note: a filter set with QueryBuilder.filter(QueryFilter)
will be silently ignored!
public PropertyQuery property(Property<T> property)
PropertyQuery
for the given property.
A PropertyQuery
uses the same conditions as this Query object,
but returns only the value(s) of a single property (not an entity objects).
property
- the property for which to return valuespublic void forEach(QueryConsumer<T> consumer)
findLazy()
, this method can be used for a high amount of data.
Note: because the consumer is called within a read transaction it may not write to the database.
public long count()
public Query<T> setParameter(Property<?> property, java.lang.String value)
QueryBuilder
to a new value.public Query<T> setParameter(java.lang.String alias, java.lang.String value)
QueryBuilder
to a new value.alias
- as defined using QueryBuilder.parameterAlias(String)
.public Query<T> setParameter(Property<?> property, long value)
QueryBuilder
to a new value.public Query<T> setParameter(java.lang.String alias, long value)
QueryBuilder
to a new value.alias
- as defined using QueryBuilder.parameterAlias(String)
.public Query<T> setParameter(Property<?> property, double value)
QueryBuilder
to a new value.public Query<T> setParameter(java.lang.String alias, double value)
QueryBuilder
to a new value.alias
- as defined using QueryBuilder.parameterAlias(String)
.public Query<T> setParameter(Property<?> property, java.util.Date value)
QueryBuilder
to a new value.java.lang.NullPointerException
- if given date is nullpublic Query<T> setParameter(java.lang.String alias, java.util.Date value)
QueryBuilder
to a new value.alias
- as defined using QueryBuilder.parameterAlias(String)
.java.lang.NullPointerException
- if given date is nullpublic Query<T> setParameter(Property<?> property, boolean value)
QueryBuilder
to a new value.public Query<T> setParameter(java.lang.String alias, boolean value)
QueryBuilder
to a new value.alias
- as defined using QueryBuilder.parameterAlias(String)
.public Query<T> setParameters(Property<?> property, long value1, long value2)
QueryBuilder
to new values.public Query<T> setParameters(java.lang.String alias, long value1, long value2)
QueryBuilder
to new values.alias
- as defined using QueryBuilder.parameterAlias(String)
.public Query<T> setParameters(Property<?> property, int[] values)
QueryBuilder
to new values.public Query<T> setParameters(java.lang.String alias, int[] values)
QueryBuilder
to new values.alias
- as defined using QueryBuilder.parameterAlias(String)
.public Query<T> setParameters(Property<?> property, long[] values)
QueryBuilder
to new values.public Query<T> setParameters(java.lang.String alias, long[] values)
QueryBuilder
to new values.alias
- as defined using QueryBuilder.parameterAlias(String)
.public Query<T> setParameters(Property<?> property, double value1, double value2)
QueryBuilder
to new values.public Query<T> setParameters(java.lang.String alias, double value1, double value2)
QueryBuilder
to new values.alias
- as defined using QueryBuilder.parameterAlias(String)
.public Query<T> setParameters(Property<?> property, java.lang.String[] values)
QueryBuilder
to new values.public Query<T> setParameters(java.lang.String alias, java.lang.String[] values)
QueryBuilder
to new values.alias
- as defined using QueryBuilder.parameterAlias(String)
.public Query<T> setParameter(Property<?> property, byte[] value)
QueryBuilder
to new values.public Query<T> setParameter(java.lang.String alias, byte[] value)
QueryBuilder
to new values.alias
- as defined using QueryBuilder.parameterAlias(String)
.public long remove()
public SubscriptionBuilder<java.util.List<T>> subscribe()
DataObserver
can be subscribed to data changes using the returned builder.
The observer is supplied via SubscriptionBuilder.observer(DataObserver)
and will be notified once
the query results have (potentially) changed.
With subscribing, the observer will immediately get current query results. The query is run for the subscribing observer.
Threading notes: Query observers are notified from a thread pooled. Observers may be notified in parallel. The notification order is the same as the subscription order, although this may not always be guaranteed in the future.
Stale observers: you must hold on to the Query or DataSubscription
objects to keep
your DataObserver
s active. If this Query is not referenced anymore
(along with its DataSubscription
s, which hold a reference to the Query internally),
it may be GCed and observers may become stale (won't receive anymore data).
public SubscriptionBuilder<java.util.List<T>> subscribe(DataSubscriptionList dataSubscriptionList)
subscribe()
with a subsequent call to
SubscriptionBuilder.dataSubscriptionList(DataSubscriptionList)
.dataSubscriptionList
- the resulting DataSubscription
will be added to itpublic void publish()
DataObserver
s.
This is useful triggering observers when new parameters have been set.
Note, that setParameter methods will NOT be propagated to observers.public java.lang.String describe()
Note: the format of the returned string may change without notice.
public java.lang.String describeParameters()
Note: the format of the returned string may change without notice.