Class MorphiaQuery<T>

  • Type Parameters:
    T - the type
    All Implemented Interfaces:
    Criteria, CriteriaContainer, Query<T>, Iterable<T>

    public class MorphiaQuery<T>
    extends Object
    implements Query<T>
    Developer note.
    This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
    • Constructor Detail

      • MorphiaQuery

        protected MorphiaQuery​(Datastore datastore)
      • MorphiaQuery

        protected MorphiaQuery​(Datastore datastore,
                               Class<T> clazz,
                               org.bson.Document query)
    • Method Detail

      • count

        public long count()
        Description copied from interface: Query
        Count the total number of values in the result, ignoring limit and offset
        Specified by:
        count in interface Query<T>
        Returns:
        the count
      • count

        public long count​(CountOptions options)
        Description copied from interface: Query
        Count the total number of values in the result, ignoring limit and offset
        Specified by:
        count in interface Query<T>
        Parameters:
        options - the options to apply to the count operation
        Returns:
        the count
      • delete

        public com.mongodb.client.result.DeleteResult delete​(DeleteOptions options)
        Description copied from interface: Query
        Deletes documents matching this query. Optionally deleting the first or all matched documents.
        Specified by:
        delete in interface Query<T>
        Parameters:
        options - the options to apply
        Returns:
        the results
      • disableValidation

        public Query<T> disableValidation()
        Description copied from interface: Query
        Turns off validation (for all calls made after)
        Specified by:
        disableValidation in interface Query<T>
        Returns:
        this
      • enableValidation

        public Query<T> enableValidation()
        Description copied from interface: Query
        Turns on validation (for all calls made after); by default validation is on
        Specified by:
        enableValidation in interface Query<T>
        Returns:
        this
      • explain

        public Map<String,​Object> explain​(FindOptions options)
        Description copied from interface: Query
        Provides information on the query plan. The query plan is the plan the server uses to find the matches for a query. This information may be useful when optimizing a query.
        Specified by:
        explain in interface Query<T>
        Parameters:
        options - the options to apply to the explain operation
        Returns:
        Map describing the process used to return the query results.
      • field

        public FieldEnd<? extends Query<T>> field​(String name)
        Description copied from interface: Query
        Fluent query interface: createQuery(Ent.class).field("count").greaterThan(7)...
        Specified by:
        field in interface Query<T>
        Parameters:
        name - the field
        Returns:
        the FieldEnd to define the criteria
      • filter

        public Query<T> filter​(String condition,
                               Object value)
        Description copied from interface: Query
        Create a filter based on the specified condition and value.

        Note: Property is in the form of "name op" ("age >").

        Valid operators are ["=", "==","!=", "<>", ">", "<", ">=", "<=", "in", "nin", "all", "size", "exists"]

        Examples:

        • filter("yearsOfOperation >", 5)
        • filter("rooms.maxBeds >=", 2)
        • filter("rooms.bathrooms exists", 1)
        • filter("stars in", new Long[]{3, 4}) //3 and 4 stars (midrange?)
        • filter("quantity mod", new Long[]{4, 0}) // customers ordered in packs of 4)
        • filter("age >=", age)
        • filter("age =", age)
        • filter("age", age) (if no operator, = is assumed)
        • filter("age !=", age)
        • filter("age in", ageList)
        • filter("customers.loyaltyYears in", yearsList)

        You can filter on id properties if this query is restricted to a Class.

        Specified by:
        filter in interface Query<T>
        Parameters:
        condition - the condition to apply
        value - the value to apply against
        Returns:
        this
      • filter

        public Query<T> filter​(Filter... additional)
        Description copied from interface: Query
        Adds filters to this query. This operation is cumulative.
        Specified by:
        filter in interface Query<T>
        Parameters:
        additional - the filters to add
        Returns:
        this
      • findAndDelete

        public T findAndDelete​(FindAndDeleteOptions options)
        Description copied from interface: Query
        Deletes an entity from the database and returns it.
        Specified by:
        findAndDelete in interface Query<T>
        Parameters:
        options - the options to apply
        Returns:
        the deleted entity
      • first

        public T first()
        Description copied from interface: Query
        Gets the first entity in the result set. Obeys the Query offset value.
        Specified by:
        first in interface Query<T>
        Returns:
        the only instance in the result, or null if the result set is empty.
      • first

        public T first​(FindOptions options)
        Description copied from interface: Query
        Gets the first entity in the result set. Obeys the Query offset value.
        Specified by:
        first in interface Query<T>
        Parameters:
        options - the options to apply to the find operation
        Returns:
        the only instance in the result, or null if the result set is empty.
      • iterator

        public dev.morphia.query.internal.MorphiaCursor<T> iterator​(FindOptions options)
        Description copied from interface: Query
        Execute the query and get the results.
        Specified by:
        iterator in interface Query<T>
        Parameters:
        options - the options to apply to the find operation
        Returns:
        a MorphiaCursor
      • keys

        public dev.morphia.query.internal.MorphiaKeyCursor<T> keys()
        Description copied from interface: Query
        Execute the query and get the results (as a MorphiaCursor<Key<T>>)
        Specified by:
        keys in interface Query<T>
        Returns:
        the keys of the documents returned by this query
      • keys

        public dev.morphia.query.internal.MorphiaKeyCursor<T> keys​(FindOptions options)
        Description copied from interface: Query
        Execute the query and get the results (as a MorphiaCursor<Key<T>>)
        Specified by:
        keys in interface Query<T>
        Parameters:
        options - the options to apply to the find operation
        Returns:
        the keys of the documents returned by this query
      • modify

        public Modify<T> modify​(UpdateOperator first,
                                UpdateOperator... updates)
        Description copied from interface: Query
        Create a modify operation based on this query
        Specified by:
        modify in interface Query<T>
        Parameters:
        first - the first and required update operator
        updates - lists the set of updates to apply
        Returns:
        the modify operation
      • search

        public Query<T> search​(String searchText)
        Description copied from interface: Query
        Perform a text search on the content of the fields indexed with a text index..
        Specified by:
        search in interface Query<T>
        Parameters:
        searchText - the text to search for
        Returns:
        the Query to enable chaining of commands
      • search

        public Query<T> search​(String searchText,
                               String language)
        Description copied from interface: Query
        Perform a text search on the content of the fields indexed with a text index..
        Specified by:
        search in interface Query<T>
        Parameters:
        searchText - the text to search for
        language - the language to use during the search
        Returns:
        the Query to enable chaining of commands
      • toDocument

        public org.bson.Document toDocument()
        Converts the query to a Document and updates for any discriminator values as my be necessary
        Specified by:
        toDocument in interface Criteria
        Specified by:
        toDocument in interface Query<T>
        Returns:
        the query
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • update

        public Update<T> update​(UpdateOperator first,
                                UpdateOperator... updates)
        Description copied from interface: Query
        Creates an update operation based on this query
        Specified by:
        update in interface Query<T>
        Parameters:
        first - the first and required update operator
        updates - lists the set of updates to apply
        Returns:
        the update operation
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object