Class RealmQuery
On this page
- io.realm
- Method Summary
- Inherited Methods
- Method Detail
- alwaysFalse
- alwaysTrue
- and
- average
- averageDecimal128
- averageRealmAny
- beginGroup
- beginsWith
- between
- contains
- containsEntry
- containsKey
- containsValue
- count
- distinct
- endGroup
- endsWith
- equalTo
- findAll
- findAllAsync
- findFirst
- findFirstAsync
- getDescription
- getQueryPointer
- getRealm
- getTypeQueried
- greaterThan
- greaterThanOrEqualTo
- in
- isEmpty
- isNotEmpty
- isNotNull
- isNull
- isValid
- lessThan
- lessThanOrEqualTo
- like
- limit
- max
- maxRealmAny
- maximumDate
- min
- minRealmAny
- minimumDate
- not
- notEqualTo
- or
- rawPredicate
- sort
- sum
io.realm
A RealmQuery encapsulates a query on a io.realm.Realm or a io.realm.RealmResults using the Builder pattern. The query is executed using either findAll() or findFirst() .
The input to many of the query functions take a field name as String. Note that this is not type safe. If a RealmObject class is refactored care has to be taken to not break any queries.
A io.realm.Realm is unordered, which means that there is no guarantee that querying a Realm will return the objects in the order they where inserted. Use sort(String) (String)} and similar methods if a specific order is required.
A RealmQuery cannot be passed between different threads.
Results are obtained quickly most of the times. However, launching heavy queries from the UI thread may result in a drop of frames or even ANRs. If you want to prevent these behaviors, you can instantiate a Realm using a RealmConfiguration that explicitly sets RealmConfiguration.Builder.allowQueriesOnUiThread(boolean) to false
. This way queries will be forced to be launched from a non-UI thread. Alternatively, you can also use findAllAsync() or findFirstAsync() .
Method Summary
Modifier and Type | Method and Description |
---|---|
public RealmQuery | alwaysFalse () This predicate will never match, resulting in the query always returning 0 results. |
public RealmQuery | alwaysTrue () This predicate will always match. |
public RealmQuery | and () Logical-and two conditions Realm automatically applies logical-and between all query statements, so this is intended only as a mean to increase readability. |
public double | |
public Decimal128 | Returns the average of a given field. |
public Decimal128 | Returns the average of a given field. |
public RealmQuery | beginGroup () Begin grouping of conditions ("left parenthesis"). |
public RealmQuery | Condition that the value of field begins with the specified substring. |
public RealmQuery | Condition that the value of field begins with the specified substring. |
public RealmQuery | Condition that the value of field begins with the specified string. |
public RealmQuery | Condition that the value of field begins with the specified string. |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | Condition that value, if a dictionary field, contains the specified entry. |
public RealmQuery | Condition that value, if a dictionary field, contains the specified key. |
public RealmQuery | Condition that value, if a dictionary field, contains the specified value. |
public RealmQuery | Condition that value, if a dictionary field, contains the specified value. |
public RealmQuery | Condition that value, if a dictionary field, contains the specified value. |
public RealmQuery | Condition that value, if a dictionary field, contains the specified value. |
public RealmQuery | Condition that value, if a dictionary field, contains the specified value. |
public RealmQuery | Condition that value, if a dictionary field, contains the specified value. |
public RealmQuery | Condition that value, if a dictionary field, contains the specified value. |
public RealmQuery | Condition that value, if a dictionary field, contains the specified value. |
public RealmQuery | Condition that value, if a dictionary field, contains the specified value. |
public RealmQuery | Condition that value, if a dictionary field, contains the specified value. |
public RealmQuery | Condition that value, if a dictionary field, contains the specified value. |
public RealmQuery | Condition that value, if a dictionary field, contains the specified value. |
public long | count () Counts the number of objects that fulfill the query conditions. |
public RealmQuery | Selects a distinct set of objects of a specific class. |
public RealmQuery | endGroup () End grouping of conditions ("right parenthesis") which was opened by a call to |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmResults | findAll () Finds all objects that fulfill the query conditions. |
public RealmResults | findAllAsync () Finds all objects that fulfill the query conditions. |
public E | findFirst () Finds the first object that fulfills the query conditions. |
public E | Similar to findFirst() but runs asynchronously on a worker thread. |
public String | Returns a textual description of this query. |
public long | Returns the pointer to the underlying C++ query. |
public Realm | |
public String | Returns the internal Realm name of the type being queried. |
public RealmQuery | Greater-than comparison. |
public RealmQuery | Greater-than comparison. |
public RealmQuery | Greater-than comparison. |
public RealmQuery | Greater-than comparison. |
public RealmQuery | Greater-than comparison. |
public RealmQuery | Greater-than comparison. |
public RealmQuery | Greater-than comparison. |
public RealmQuery | Greater-than comparison. |
public RealmQuery | Greater-than-or-equal-to comparison. |
public RealmQuery | Greater-than-or-equal-to comparison. |
public RealmQuery | Greater-than-or-equal-to comparison. |
public RealmQuery | Greater-than-or-equal-to comparison. |
public RealmQuery | Greater-than-or-equal-to comparison. |
public RealmQuery | Greater-than-or-equal-to comparison. |
public RealmQuery | Greater-than-or-equal-to comparison. |
public RealmQuery | In comparison. |
public RealmQuery | In comparison. |
public RealmQuery | In comparison. |
public RealmQuery | In comparison. |
public RealmQuery | In comparison. |
public RealmQuery | In comparison. |
public RealmQuery | In comparison. |
public RealmQuery | In comparison. |
public RealmQuery | In comparison. |
public RealmQuery | In comparison. |
public RealmQuery | In comparison. |
public RealmQuery | |
public RealmQuery | Condition that finds values that are considered "Not-empty" i.e., a list, a string or a byte array with not-empty values. |
public RealmQuery | |
public RealmQuery | |
public boolean | isValid () Checks if io.realm.RealmQuery is still valid to use i.e., the io.realm.Realm instance hasn't been closed and any parent io.realm.RealmResults is still valid. |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | Less-than-or-equal-to comparison. |
public RealmQuery | Less-than-or-equal-to comparison. |
public RealmQuery | Less-than-or-equal-to comparison. |
public RealmQuery | Less-than-or-equal-to comparison. |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | Limits the number of objects returned in case the query matched more objects. |
public Number | |
public RealmAny | Finds the maximum value of a RealmAny field. |
public Date | Finds the maximum value of a field. |
public Number | |
public RealmAny | Finds the minimum value of a RealmAny field. |
public Date | Finds the minimum value of a field. |
public RealmQuery | not () Negate condition. |
public RealmQuery | Not-equal-to comparison. |
public RealmQuery | Not-equal-to comparison. |
public RealmQuery | Not-equal-to comparison. |
public RealmQuery | Not-equal-to comparison. |
public RealmQuery | Not-equal-to comparison. |
public RealmQuery | or () Logical-or two conditions. |
public RealmQuery | Create a text-based predicate using the Realm Query Language. |
public RealmQuery | Sorts the query result by the specific field names in the provided orders. |
public RealmQuery | |
public RealmQuery | |
public RealmQuery | |
public Number |
Inherited Methods
Methods inherited from class java.lang.Object :
getClass
,hashCode
,equals
,clone
,toString
,notify
,notifyAll
,wait
,wait
,wait
,finalize
Method Detail
alwaysFalse
public RealmQuery alwaysFalse () |
---|
This predicate will never match, resulting in the query always returning 0 results. |
alwaysTrue
public RealmQuery alwaysTrue () |
---|
This predicate will always match. |
and
public RealmQuery and () |
---|
Logical-and two conditions Realm automatically applies logical-and between all query statements, so this is intended only as a mean to increase readability. Returns the query object |
average
Returns the average of a given field. Does not support dotted field notation. Parameters
Returns the average for the given field amongst objects in query results. This will be of type double for all types of number fields. If no objects exist or they all have Throws
|
averageDecimal128
Returns the average of a given field. Does not support dotted field notation. Parameters
Returns the average for the given field amongst objects in query results. This will be of type Decimal128. If no objects exist or they all have Throws
|
averageRealmAny
Returns the average of a given field. Does not support dotted field notation. Parameters
Returns the average for the given field amongst objects in query results. This will be of type Decimal128. If no objects exist or they all have Throws
|
beginGroup
public RealmQuery beginGroup () |
---|
Begin grouping of conditions ("left parenthesis"). A group must be closed with a call to Returns the query object. |
beginsWith
Condition that the value of field begins with the specified substring. Parameters
Returns the query object Throws
|
Condition that the value of field begins with the specified substring. Parameters
Returns the query object Throws
|
Condition that the value of field begins with the specified string. Parameters
Returns the query object. Throws
|
Condition that the value of field begins with the specified string. Parameters
Returns the query object. Throws
|
between
Between condition. Parameters
Returns the query object. Throws
|
Between condition. Parameters
Returns the query object. Throws
|
Between condition. Parameters
Returns the query object. Throws
|
Between condition. Parameters
Returns the query object. Throws
|
Between condition. Parameters
Returns the query object. Throws
|
Between condition. Parameters
Returns the query object. Throws
|
Between condition. Parameters
Returns the query object. Throws
|
contains
Condition that value of field contains the specified substring. Parameters
Returns The query object. Throws
|
Condition that value of field contains the specified substring. Parameters
Returns The query object. Throws
|
Condition that value of field contains the specified substring. Parameters
Returns the query object. Throws
|
Condition that value of field contains the specified substring. Parameters
Returns the query object. Throws
|
containsEntry
Condition that value, if a dictionary field, contains the specified entry. Parameters
Returns the query object. Throws
|
containsKey
Condition that value, if a dictionary field, contains the specified key. Parameters
Returns the query object. Throws
|
containsValue
Condition that value, if a dictionary field, contains the specified value. Parameters
Returns the query object. Throws
|
Condition that value, if a dictionary field, contains the specified value. Parameters
Returns the query object. Throws
|
Condition that value, if a dictionary field, contains the specified value. Parameters
Returns the query object. Throws
|
Condition that value, if a dictionary field, contains the specified value. Parameters
Returns the query object. Throws
|
Condition that value, if a dictionary field, contains the specified value. Parameters
Returns the query object. Throws
|
Condition that value, if a dictionary field, contains the specified value. Parameters
Returns the query object. Throws
|
Condition that value, if a dictionary field, contains the specified value. Parameters
Returns the query object. Throws
|
Condition that value, if a dictionary field, contains the specified value. Parameters
Returns the query object. Throws
|
Condition that value, if a dictionary field, contains the specified value. Parameters
Returns the query object. Throws
|
Condition that value, if a dictionary field, contains the specified value. Parameters
Returns the query object. Throws
|
Condition that value, if a dictionary field, contains the specified value. Parameters
Returns the query object. Throws
|
Condition that value, if a dictionary field, contains the specified value. Parameters
Returns the query object. Throws
|
count
public long count () |
---|
Counts the number of objects that fulfill the query conditions. Returns the number of matching objects. Throws
|
distinct
Selects a distinct set of objects of a specific class. When multiple distinct fields are given, all unique combinations of values in the fields will be returned. In case of multiple matches, it is undefined which object is returned. Unless the result is sorted, then the first object will be returned. Parameters
Throws
|
endGroup
public RealmQuery endGroup () |
---|
End grouping of conditions ("right parenthesis") which was opened by a call to Returns the query object. |
endsWith
Condition that the value of field ends with the specified substring. Parameters
Returns the query object. Throws
|
Condition that the value of field ends with the specified substring. Parameters
Returns the query object. Throws
|
Condition that the value of field ends with the specified string. Parameters
Returns the query object. Throws
|
Condition that the value of field ends with the specified string. Parameters
Returns the query object. Throws
|
equalTo
Equal-to comparison. Parameters
Returns the query object. Throws
|
Equal-to comparison. Parameters
Returns the query object. Throws
|
Equal-to comparison. Parameters
Returns the query object. Throws
|
Equal-to comparison. Parameters
Returns the query object. Throws
|
Equal-to comparison. Parameters
Returns the query object. Throws
|
findAll
public RealmResults findAll () |
---|
Finds all objects that fulfill the query conditions.Launching heavy queries from the UI thread may result in a drop of frames or even ANRs. We do not recommend doing so and therefore it is not allowed by default. If you want to prevent these behaviors you can obtain a Realm using a RealmConfiguration that explicitly sets RealmConfiguration.Builder.allowQueriesOnUiThread(boolean) to Returns a io.realm.RealmResults containing objects. If no objects match the condition, a list with zero objects is returned. Throws
|
findAllAsync
public RealmResults findAllAsync () |
---|
Finds all objects that fulfill the query conditions. This method is only available from a Looper thread. Returns immediately an empty RealmResults . Users need to register a listener io.realm.RealmResults.addChangeListener(RealmChangeListener) to be notified when the query completes. |
findFirst
public E findFirst () |
---|
Finds the first object that fulfills the query conditions.Launching heavy queries from the UI thread may result in a drop of frames or even ANRs. We do not recommend doing so, but it is allowed by default. If you want to prevent these behaviors you can obtain a Realm using a RealmConfiguration that explicitly sets RealmConfiguration.Builder.allowQueriesOnUiThread(boolean) to Returns the object found or Throws
|
findFirstAsync
public E findFirstAsync () |
---|
Similar to findFirst() but runs asynchronously on a worker thread. A listener should be registered to the returned RealmObject to get the notification when query completes. The registered listener will also be triggered if there are changes made to the queried RealmObject . If the RealmObject is deleted, the listener will be called one last time and then stop. The query will not be re-run. Returns immediately an empty RealmObject with Throws
|
getDescription
public String getDescription () |
---|
Returns a textual description of this query. Returns the textual description of the query. |
getQueryPointer
public long getQueryPointer () |
---|
Returns the pointer to the underlying C++ query. This method is only public due to architectural design choices that are hard to work around and should be considered internal and can change without warning. Returns the pointer to the underlying C++ query. |
getRealm
Returns the Realm instance to which this query belongs. Calling Realm.close() on the returned instance is discouraged as it is the same as calling it on the original Realm instance which may cause the Realm to fully close invalidating the query. Returns Realm instance this query belongs to. Throws
|
getTypeQueried
public String getTypeQueried () |
---|
Returns the internal Realm name of the type being queried. Returns the internal name of the Realm model class being queried. |
greaterThan
Greater-than comparison. Parameters
Returns the query object. Throws
|
Greater-than comparison. Parameters
Returns the query object. Throws
|
Greater-than comparison. Parameters
Returns the query object. Throws
|
Greater-than comparison. Parameters
Returns the query object. Throws
|
Greater-than comparison. Parameters
Returns the query object. Throws
|
Greater-than comparison. Parameters
Returns the query object. Throws
|
Greater-than comparison. Parameters
Returns the query object. Throws
|
Greater-than comparison. Parameters
Returns the query object. Throws
|
greaterThanOrEqualTo
Greater-than-or-equal-to comparison. Parameters
Returns the query object. Throws
|
Greater-than-or-equal-to comparison. Parameters
Returns the query object. Throws
|
Greater-than-or-equal-to comparison. Parameters
Returns the query object. Throws
|
Greater-than-or-equal-to comparison. Parameters
Returns the query object. Throws
|
Greater-than-or-equal-to comparison. Parameters
Returns the query object. Throws
|
Greater-than-or-equal-to comparison. Parameters
Returns the query object. Throws
|
Greater-than-or-equal-to comparison. Parameters
Returns the query object. Throws
|
in
In comparison. This allows you to test if objects match any value in an array of values. Parameters
Returns the query object. Throws
|
In comparison. This allows you to test if objects match any value in an array of values. Parameters
Returns the query object. Throws
|
In comparison. This allows you to test if objects match any value in an array of values. Parameters
Returns the query object. Throws
|
In comparison. This allows you to test if objects match any value in an array of values. Parameters
Returns the query object. Throws
|
In comparison. This allows you to test if objects match any value in an array of values. Parameters
Returns the query object. Throws
|
In comparison. This allows you to test if objects match any value in an array of values. Parameters
Returns the query object. Throws
|
In comparison. This allows you to test if objects match any value in an array of values. Parameters
Returns the query object. Throws
|
In comparison. This allows you to test if objects match any value in an array of values. Parameters
Returns the query object. Throws
|
In comparison. This allows you to test if objects match any value in an array of values. Parameters
Returns the query object. Throws
|
In comparison. This allows you to test if objects match any value in an array of values. Parameters
Returns the query object. Throws
|
In comparison. This allows you to test if objects match any value in an array of values. Parameters
Returns the query object. Throws
|
isEmpty
Condition that finds values that are considered "empty" i.e., an empty list, the 0-length string or byte array. Parameters
Returns the query object. Throws
|
isNotEmpty
Condition that finds values that are considered "Not-empty" i.e., a list, a string or a byte array with not-empty values. Parameters
Returns the query object. Throws
|
isNotNull
Tests if a field is not Parameters
Returns the query object. Throws
|
isNull
Tests if a field is For link queries, if any part of the link path is Parameters
Returns the query object. Throws
|
isValid
public boolean isValid () |
---|
Checks if io.realm.RealmQuery is still valid to use i.e., the io.realm.Realm instance hasn't been closed and any parent io.realm.RealmResults is still valid. Returns
|
lessThan
Less-than comparison. Parameters
Returns the query object. Throws
|
Less-than comparison. Parameters
Returns the query object. Throws
|
Less-than comparison. Parameters
Returns the query object. Throws
|
Less-than comparison. Parameters
Returns the query object. Throws
|
lessThanOrEqualTo
Less-than-or-equal-to comparison. Parameters
Returns the query object. Throws
|
Less-than-or-equal-to comparison. Parameters
Returns the query object. Throws
|
Less-than-or-equal-to comparison. Parameters
Returns the query object. Throws
|
Less-than-or-equal-to comparison. Parameters
Returns the query object. Throws
|
like
Condition that the value of field matches with the specified substring, with wildcards:
Parameters
Returns the query object. Throws
|
Condition that the value of field matches with the specified substring, with wildcards:
Parameters
Returns the query object. Throws
|
Condition that the value of field matches with the specified substring, with wildcards:
Parameters
Returns the query object. Throws
|
Condition that the value of field matches with the specified substring, with wildcards:
Parameters
Returns the query object. Throws
|
limit
Limits the number of objects returned in case the query matched more objects.Note that when using this method in combination with sort(String) and distinct(String, String...) they will be executed in the order they where added which can affect the end result. Parameters
Throws
|
max
Finds the maximum value of a field. Parameters
Returns if no objects exist or they all have Throws
|
maxRealmAny
Finds the maximum value of a RealmAny field. Parameters
Returns if no objects exist or they all have Throws
|
maximumDate
Finds the maximum value of a field. Parameters
Returns if no objects exist or they all have Throws
|
min
Finds the minimum value of a field. Parameters
Returns if no objects exist or they all have Throws
|
minRealmAny
Finds the minimum value of a RealmAny field. Parameters
Returns if no objects exist or they all have Throws
|
minimumDate
Finds the minimum value of a field. Parameters
Returns if no objects exist or they all have Throws
|
not
public RealmQuery not () |
---|
Negate condition. Returns the query object. |
notEqualTo
Not-equal-to comparison. Parameters
Returns the query object. Throws
|
Not-equal-to comparison. Parameters
Returns the query object. Throws
|
Not-equal-to comparison. Parameters
Returns the query object. Throws
|
Not-equal-to comparison. Parameters
Returns the query object. Throws
|
Not-equal-to comparison. Parameters
Returns the query object. Throws
|
or
public RealmQuery or () |
---|
Logical-or two conditions. Returns the query object. |
rawPredicate
Create a text-based predicate using the Realm Query Language. This predicate can be combined with other raw or type safe predicates, it accepts Realm values as arguments.Class and property names used in the raw predicate can be either the names defined in the Realm Model classes or the internal names defined using the io.realm.annotations.RealmClass or io.realm.annotations.RealmField annotations. If a class or property name contains spaces those must be escaped. Arguments are defined in the string predicate as $argument_index, where $argument_index is a decimal integer that specifies the position of the argument in the argument list. The first argument is referenced by $0, the second by $1, etc.See these docs for a more detailed description of the Realm Query Language. Examples:
Parameters
Throws
|
sort
Sorts the query result by the specific field names in the provided orders. Later fields will only be used if the previous field values are equal.Sorting is currently limited to character sets in 'Latin Basic', 'Latin Supplement', 'Latin Extended A', 'Latin Extended B' (UTF-8 range 0-591). For other character sets, sorting will have no effect. Parameters
Throws
|
Sorts the query result by the specific field names in the provided orders. Sorting is currently limited to character sets in 'Latin Basic', 'Latin Supplement', 'Latin Extended A', 'Latin Extended B' (UTF-8 range 0-591). For other character sets, sorting will have no effect. Parameters
Throws
|
Sorts the query result by the specified field name and order.Sorting is currently limited to character sets in 'Latin Basic', 'Latin Supplement', 'Latin Extended A', 'Latin Extended B' (UTF-8 range 0-591). For other character sets, sorting will have no effect. Parameters
Throws
|
Sorts the query result by the specific field name in ascending order.Sorting is currently limited to character sets in 'Latin Basic', 'Latin Supplement', 'Latin Extended A', 'Latin Extended B' (UTF-8 range 0-591). For other character sets, sorting will have no effect. Parameters
Throws
|
sum
Calculates the sum of a given field. Parameters
Returns the sum of fields of the matching objects. If no objects exist or they all have Throws
|