Class LegacyQuery<T>

  • Type Parameters:
    T - The type we will be querying for, and returning.
    All Implemented Interfaces:
    Criteria, CriteriaContainer, Query<T>, Iterable<T>

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

      • LegacyQuery

        protected LegacyQuery​(Datastore datastore,
                              @Nullable
                              String collectionName,
                              Class<T> type)
        Creates a Query for the given type and collection
        Parameters:
        datastore - the Datastore to use
        type - the type to return
    • Method Detail

      • add

        public void add​(Criteria... criteria)
        Description copied from interface: CriteriaContainer
        Adds Criteria to this container
        Specified by:
        add in interface CriteriaContainer
        Parameters:
        criteria - the criteria to add
      • remove

        public void remove​(Criteria criteria)
        Description copied from interface: CriteriaContainer
        Removes Criteria to this container
        Specified by:
        remove in interface CriteriaContainer
        Parameters:
        criteria - the criteria to remove
      • attach

        public void attach​(CriteriaContainer container)
        Description copied from interface: Criteria
        Used to add this Criteria to a CriteriaContainer
        Specified by:
        attach in interface Criteria
        Parameters:
        container - the container to add to
      • getFieldName

        public String getFieldName()
        Specified by:
        getFieldName in interface Criteria
        Returns:
        the field name for the criteria
      • 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
      • 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
      • execute

        @Deprecated(since="2.0",
                    forRemoval=true)
        public dev.morphia.query.internal.MorphiaCursor<T> execute()
        Deprecated, for removal: This API element is subject to removal in a future version.
        Execute the query and get the results.
        Specified by:
        execute in interface Query<T>
        Returns:
        a MorphiaCursor
        See Also:
        iterator(FindOptions)
      • delete

        public 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
      • explain

        public Map<String,​Object> explain​(FindOptions options,
                                                @Nullable
                                                ExplainVerbosity verbosity)
        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
        verbosity - the verbosity of the explanation
        Returns:
        Map describing the process used to return the query 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
      • execute

        @Deprecated(since="2.0",
                    forRemoval=true)
        public dev.morphia.query.internal.MorphiaCursor<T> execute​(FindOptions options)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Execute the query and get the results.
        Specified by:
        execute in interface Query<T>
        Parameters:
        options - the options to apply to the find operation
        Returns:
        a MorphiaCursor
      • getLoggedQuery

        public String getLoggedQuery()
        Specified by:
        getLoggedQuery in interface Query<T>
        Returns:
        The query logged during the previous execution of this query
      • 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
      • 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
      • getEntityClass

        @MorphiaInternal
        public Class<T> getEntityClass()
        Specified by:
        getEntityClass in interface Query<T>
        Returns:
        the entity Class.
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • 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.
      • 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
      • modify

        public T modify​(ModifyOptions options,
                        UpdateOperator... updates)
        Description copied from interface: Query
        Create a modify operation based on this query
        Specified by:
        modify in interface Query<T>
        Parameters:
        options - the options to apply
        updates - lists the set of updates to apply
        Returns:
        the modify operation
      • 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​(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
      • 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
      • modify

        @Deprecated
        public Modify<T> modify​(UpdateOperations<T> operations)
        Deprecated.
        Description copied from interface: Query
        This is only intended for migration of legacy uses of UpdateOperations
        Specified by:
        modify in interface Query<T>
        Parameters:
        operations - the prebuilt operations
        Returns:
        the Modify instance
      • search

        public Query<T> search​(String search,
                               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:
        search - the text to search for
        language - the language to use during the search
        Returns:
        the Query to enable chaining of commands
      • retrieveKnownFields

        public Query<T> retrieveKnownFields()
        Description copied from interface: Query
        Limits the fields retrieved to those of the query type -- dangerous with interfaces and abstract classes
        Specified by:
        retrieveKnownFields in interface Query<T>
        Returns:
        this
      • search

        public Query<T> search​(String search)
        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:
        search - the text to search for
        Returns:
        the Query to enable chaining of commands
      • update

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

        @Deprecated(since="2.0",
                    forRemoval=true)
        public Update<T> update​(UpdateOperations<T> operations)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Specified by:
        update in interface Query<T>
        Parameters:
        operations - the prebuilt operations
        Returns:
        the Updates instance
      • update

        public UpdateResult update​(UpdateOptions options,
                                   Stage... updates)
        Description copied from interface: Query
        Creates an update operation based on this query
        Specified by:
        update in interface Query<T>
        Parameters:
        options - the options to apply
        updates - lists the set of updates to apply
        Returns:
        the update operation
      • update

        public UpdateResult update​(UpdateOptions options,
                                   UpdateOperator... updates)
        Description copied from interface: Query
        Creates an update operation based on this query
        Specified by:
        update in interface Query<T>
        Parameters:
        options - the options to apply
        updates - lists the set of updates to apply
        Returns:
        the update operation
      • getFieldsObject

        @Nullable
        @MorphiaInternal
        public Document getFieldsObject()
        Returns:
        the Mongo fields Document.
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getSort

        @Nullable
        @MorphiaInternal
        public Document getSort()
        Returns:
        the Mongo sort Document.
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • toDocument

        @MorphiaInternal
        public 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.
      • isValidatingNames

        public boolean isValidatingNames()
        Returns:
        true if field names are being validated
      • setQueryObject

        public void setQueryObject​(Document query)
        Sets query structure directly
        Parameters:
        query - the Document containing the query
      • getDatastore

        protected Datastore getDatastore()