Package com.couchbase.lite
Interface Query
public interface Query
A database query built using the fluent interface in
QueryBuilder
.-
Method Summary
Modifier and TypeMethodDescriptionaddChangeListener
(QueryChangeListener listener) Adds a change listener for the changes that occur in the query results.addChangeListener
(Executor executor, QueryChangeListener listener) Adds a change listener for the changes that occur in the query results with an executor on which the changes will be posted to the listener.execute()
Executes the query.explain()
Returns a string describing the implementation of the compiled query.Returns a copies of the current parameters.void
Deprecated.Use ListenerToken.remove()void
setParameters
(Parameters parameters) Set parameters should copy the given parameters.
-
Method Details
-
getParameters
Returns a copies of the current parameters. -
setParameters
Set parameters should copy the given parameters. Set a new parameter will also re-execute the query if there is at least one listener listening for changes.- Throws:
CouchbaseLiteException
-
execute
Executes the query. The returning a result set that enumerates result rows one at a time. You can run the query any number of times, and you can even have multiple ResultSet active at once.The results come from a snapshot of the database taken at the moment the run() method is called, so they will not reflect any changes made to the database afterwards.
- Returns:
- the ResultSet for the query result.
- Throws:
CouchbaseLiteException
- if there is an error when running the query.
-
explain
Returns a string describing the implementation of the compiled query. This is intended to be read by a developer for purposes of optimizing the query, especially to add database indexes. It's not machine-readable and its format may change. As currently implemented, the result is two or more lines separated by newline characters: * The first line is the SQLite SELECT statement. * The subsequent lines are the output of SQLite's "EXPLAIN QUERY PLAN" command applied to that statement; for help interpreting this, see eqp. The most important thing to know is that if you see "SCAN TABLE", it means that SQLite is doing a slow linear scan of the documents instead of using an index.- Returns:
- a string describing the implementation of the compiled query.
- Throws:
CouchbaseLiteException
- if an error occurs
-
addChangeListener
Adds a change listener for the changes that occur in the query results. The changes will be delivered on the UI thread for the Android platform and on an arbitrary thread for the Java platform. When developing a Java Desktop application using Swing or JavaFX that needs to update the UI after receiving the changes, make sure to schedule the UI update on the UI thread by using SwingUtilities.invokeLater(Runnable) or Platform.runLater(Runnable) respectively.- Parameters:
listener
- The listener to post changes.- Returns:
- An opaque listener token object for removing the listener.
-
addChangeListener
@NonNull ListenerToken addChangeListener(@Nullable Executor executor, @NonNull QueryChangeListener listener) Adds a change listener for the changes that occur in the query results with an executor on which the changes will be posted to the listener. If the executor is not specified, the changes will be delivered on the UI thread for the Android platform and on an arbitrary thread for the Java platform.- Parameters:
executor
- The executor object that calls listenerlistener
- The listener to post changes.- Returns:
- An opaque listener token object for removing the listener.
-
removeChangeListener
Deprecated.Use ListenerToken.remove()Removes a change listener wih the given listener token.- Parameters:
token
- The listener token.
-