Interface Query

All Known Implementing Classes:
From, GroupBy, Having, Joins, Limit, OrderBy, Select, Where

public interface Query
A database query built using the fluent interface in QueryBuilder.
  • Method Details

    • getParameters

      @Nullable Parameters getParameters()
      Returns a copies of the current parameters.
    • setParameters

      void setParameters(Parameters parameters)
      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.
    • execute

      @NonNull ResultSet execute() throws CouchbaseLiteException
      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

      @NonNull String explain() throws CouchbaseLiteException
      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 https://www.sqlite.org/eqp.html . 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

      @NonNull ListenerToken addChangeListener(@NonNull QueryChangeListener listener)
      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 listener
      listener - The listener to post changes.
      Returns:
      An opaque listener token object for removing the listener.
    • removeChangeListener

      @Deprecated void removeChangeListener(@NonNull ListenerToken token)
      Deprecated.
      Use ListenerToken.remove()
      Removes a change listener wih the given listener token.
      Parameters:
      token - The listener token.