Class QueryImpl<T>

    • Constructor Detail

      • QueryImpl

        public QueryImpl​(Class<T> clazz,
                         Datastore datastore)
        Creates a Query for the given type and collection
        Parameters:
        clazz - the type to return
        datastore - the Datastore to use
    • Method Detail

      • 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
      • order

        public Query<T> order​(Meta sort)
        Description copied from interface: Query
        Sorts based on a metadata (defines return order). Example: order(Meta.textScore()) ({textScore : { $meta: "textScore" }})
        Specified by:
        order in interface Query<T>
        Parameters:
        sort - the sort order to apply
        Returns:
        this
      • order

        public Query<T> order​(Sort... sorts)
        Description copied from interface: Query
        Sorts based on a specified sort keys (defines return order).
        Specified by:
        order in interface Query<T>
        Parameters:
        sorts - the sort order to apply
        Returns:
        this
      • project

        public Query<T> project​(String field,
                                boolean include)
        Description copied from interface: Query
        Adds a field to the projection clause. Passing true for include will include the field in the results. Projected fields must all be inclusions or exclusions. You can not include and exclude fields at the same time with the exception of the _id field. The _id field is always included unless explicitly suppressed.
        Specified by:
        project in interface Query<T>
        Parameters:
        field - the field to project
        include - true to include the field in the results
        Returns:
        this
        See Also:
        Project Fields to Return from Query
      • 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
      • 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
      • where

        public Query<T> where​(String js)
        Description copied from interface: Query
        Limit the query using this javascript block; only one per query
        Specified by:
        where in interface Query<T>
        Parameters:
        js - the javascript block to apply
        Returns:
        this
      • 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
      • 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
      • execute

        public dev.morphia.query.internal.MorphiaCursor<T> execute()
        Description copied from interface: Query
        Execute the query and get the results.

        *note* the return type of this will change in 2.0.

        Specified by:
        execute in interface Query<T>
        Returns:
        a MorphiaCursor
        See Also:
        Query.execute(FindOptions)
      • execute

        public dev.morphia.query.internal.MorphiaCursor<T> execute​(FindOptions options)
        Description copied from interface: Query
        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
      • 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.
      • delete

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

        public Modify<T> modify()
        Description copied from interface: Query
        Create a modify operation based on this query
        Specified by:
        modify in interface Query<T>
        Returns:
        the modify operation
      • modify

        public Modify<T> modify​(UpdateOperations<T> operations)
        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
      • remove

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

        public Update<T> update()
        Description copied from interface: Query
        Creates an update operation based on this query
        Specified by:
        update in interface Query<T>
        Returns:
        the update operation
      • update

        @Deprecated(since="2.0",
                    forRemoval=true)
        public Update<T> update​(org.bson.Document document)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Specified by:
        update in interface Query<T>
        Parameters:
        document - the seed document
        Returns:
        the update operation
      • update

        @Deprecated(since="2.0",
                    forRemoval=true)
        public Update<T> update​(UpdateOperations 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
      • getLoggedQuery

        public String getLoggedQuery()
        Specified by:
        getLoggedQuery in interface Query<T>
        Returns:
        the logged query
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getCollection

        public com.mongodb.client.MongoCollection<T> getCollection()
        Returns:
        the collection this query targets
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • toDocument

        public org.bson.Document toDocument()
        Specified by:
        toDocument in interface Criteria
        Returns:
        the Document form of this type
      • 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
      • 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
      • getEntityClass

        public Class<T> getEntityClass()
        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.
      • setQueryObject

        public void setQueryObject​(org.bson.Document query)
        Sets query structure directly
        Parameters:
        query - the Document containing the query
      • getSort

        public org.bson.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.
      • isValidatingNames

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

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

        public org.bson.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.
      • prepareQuery

        public org.bson.Document prepareQuery()
        Converts the query to a Document and updates for any discriminator values as my be necessary
        Returns:
        th query
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getDatastore

        protected Datastore getDatastore()