Class QueryImpl<T>

    • Constructor Detail

      • QueryImpl

        public QueryImpl​(java.lang.Class<T> clazz,
                         com.mongodb.DBCollection coll,
                         Datastore ds)
        Creates a Query for the given type and collection
        Parameters:
        clazz - the type to return
        coll - the collection to query
        ds - the Datastore to use
    • Method Detail

      • 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.
      • getKey

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

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

        @Deprecated
        public Query<T> batchSize​(int value)
        Deprecated.
        Description copied from interface: Query
        Batch-size of the fetched result (cursor).
        Specified by:
        batchSize in interface Query<T>
        Parameters:
        value - must be >= 0. A value of 0 indicates the server default.
        Returns:
        this
        See Also:
        FindOptions.batchSize(int)
      • 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 java.util.Map<java.lang.String,​java.lang.Object> explain()
        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>
        Returns:
        Map describing the process used to return the query results.
      • explain

        public java.util.Map<java.lang.String,​java.lang.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​(java.lang.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​(java.lang.String condition,
                               java.lang.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
      • getCollection

        public com.mongodb.DBCollection 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.
      • getEntityClass

        public java.lang.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.
      • getFieldsObject

        public com.mongodb.DBObject getFieldsObject()
        Returns:
        the Mongo fields DBObject.
        Developer note. This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • getQueryObject

        public com.mongodb.DBObject getQueryObject()
        Returns:
        the query object
        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​(com.mongodb.DBObject query)
        Sets query structure directly
        Parameters:
        query - the DBObject containing the query
      • getSortObject

        public com.mongodb.DBObject getSortObject()
        Returns:
        the Mongo sort DBObject.
        Developer note. This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • hintIndex

        @Deprecated
        public Query<T> hintIndex​(java.lang.String idxName)
        Deprecated.
        Description copied from interface: Query
        Hints as to which index should be used.
        Specified by:
        hintIndex in interface Query<T>
        Parameters:
        idxName - the index name to hint
        Returns:
        this
        See Also:
        FindOptions.modifier(String, Object)
      • limit

        @Deprecated
        public Query<T> limit​(int value)
        Deprecated.
        Description copied from interface: Query
        Limit the fetched result set to a certain number of values.
        Specified by:
        limit in interface Query<T>
        Parameters:
        value - must be >= 0. A value of 0 indicates no limit. For values < 0, use FindOptions.batchSize(int) which is the preferred method
        Returns:
        this
        See Also:
        FindOptions.limit(int)
      • lowerIndexBound

        @Deprecated
        public Query<T> lowerIndexBound​(com.mongodb.DBObject lowerBound)
        Deprecated.
        Description copied from interface: Query

        Specify the inclusive lower bound for a specific index in order to constrain the results of this query.

        You can chain key/value pairs to build a constraint for a compound index. For instance:

        query.lowerIndexBound(new BasicDBObject("a", 1).append("b", 2));

        to build a constraint on index {"a", "b"}

        Specified by:
        lowerIndexBound in interface Query<T>
        Parameters:
        lowerBound - The inclusive lower bound.
        Returns:
        this
        See Also:
        FindOptions.modifier(String, Object)
      • maxScan

        @Deprecated
        public Query<T> maxScan​(int value)
        Deprecated.
        Description copied from interface: Query
        Constrains the query to only scan the specified number of documents when fulfilling the query.
        Specified by:
        maxScan in interface Query<T>
        Parameters:
        value - must be > 0. A value < 0 indicates no limit
        Returns:
        this
        See Also:
        FindOptions.modifier(String, Object)
      • maxTime

        @Deprecated
        public Query<T> maxTime​(long value,
                                java.util.concurrent.TimeUnit unit)
        Deprecated.
        Description copied from interface: Query
        Specifies a time limit for executing the query. Requires server version 2.6 or above.
        Specified by:
        maxTime in interface Query<T>
        Parameters:
        value - must be > 0. A value < 0 indicates no limit
        unit - the unit of time to use
        Returns:
        this
        See Also:
        FindOptions.modifier(String, Object)
      • offset

        @Deprecated
        public Query<T> offset​(int value)
        Deprecated.
        Description copied from interface: Query
        Starts the query results at a particular zero-based offset.
        Specified by:
        offset in interface Query<T>
        Parameters:
        value - must be >= 0
        Returns:
        this
        See Also:
        FindOptions.skip(int)
      • 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
      • queryNonPrimary

        @Deprecated
        public Query<T> queryNonPrimary()
        Deprecated.
        Description copied from interface: Query
        Route query to non-primary node
        Specified by:
        queryNonPrimary in interface Query<T>
        Returns:
        this
        See Also:
        ReadPreference.secondary(), ReadPreference.secondaryPreferred(), FindOptions.readPreference(ReadPreference), ReadPreference.secondary(), ReadPreference.secondaryPreferred()
      • 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
      • project

        public Query<T> project​(java.lang.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
      • project

        public Query<T> project​(java.lang.String field,
                                ArraySlice slice)
        Description copied from interface: Query
        Adds an sliced array field to a projection.
        Specified by:
        project in interface Query<T>
        Parameters:
        field - the field to project
        slice - the options for projecting an array field
        Returns:
        this
        See Also:
        Project Fields to Return from Query
      • retrievedFields

        @Deprecated
        public Query<T> retrievedFields​(boolean include,
                                        java.lang.String... list)
        Deprecated.
        Description copied from interface: Query
        Limits the fields retrieved
        Specified by:
        retrievedFields in interface Query<T>
        Parameters:
        include - true if the fields should be included in the results. false to exclude them.
        list - the fields in question
        Returns:
        this
      • returnKey

        @Deprecated
        public Query<T> returnKey()
        Deprecated.
        Description copied from interface: Query
        Only return the index field or fields for the results of the query. If $returnKey is set to true and the query does not use an index to perform the read operation, the returned documents will not contain any fields
        Specified by:
        returnKey in interface Query<T>
        Returns:
        the Query to enable chaining of commands
        See Also:
        FindOptions.modifier(String, Object)
      • search

        public Query<T> search​(java.lang.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​(java.lang.String search,
                               java.lang.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
      • upperIndexBound

        @Deprecated
        public Query<T> upperIndexBound​(com.mongodb.DBObject upperBound)
        Deprecated.
        Description copied from interface: Query

        Specify the exclusive upper bound for a specific index in order to constrain the results of this query.

        You can chain key/value pairs to build a constraint for a compound index. For instance:

        query.upperIndexBound(new BasicDBObject("a", 1).append("b", 2));

        to build a constraint on index {"a", "b"}

        Specified by:
        upperIndexBound in interface Query<T>
        Parameters:
        upperBound - The exclusive upper bound.
        Returns:
        this
        See Also:
        FindOptions.modifier(String, Object)
      • useReadPreference

        @Deprecated
        public Query<T> useReadPreference​(com.mongodb.ReadPreference readPref)
        Deprecated.
        Description copied from interface: Query
        Updates the ReadPreference to use
        Specified by:
        useReadPreference in interface Query<T>
        Parameters:
        readPref - the ReadPreference to use
        Returns:
        this
        See Also:
        ReadPreference, FindOptions.readPreference(ReadPreference)
      • where

        public Query<T> where​(java.lang.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
      • where

        public Query<T> where​(org.bson.types.CodeWScope 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
      • delete

        public T delete()
        Specified by:
        delete in interface Query<T>
      • modify

        public Modify modify​(UpdateOperations<T> operations)
        Description copied from interface: Query
        This is only intended for use as a bridge for the deprecated methods. Any use will break in the future.
        Specified by:
        modify in interface Query<T>
        Parameters:
        operations - the prebuilt operations
        Returns:
        the Modify instance
      • update

        @Deprecated(since="2.0",
                    forRemoval=true)
        public QueryImpl.Update update​(UpdateOperations operations)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Description copied from interface: Query
        This is only intended for use as a bridge for the deprecated methods. Any use will break in the future.
        Specified by:
        update in interface Query<T>
        Parameters:
        operations - the prebuilt operations
        Returns:
        the Updates instance
      • update

        @Deprecated(since="2.0",
                    forRemoval=true)
        public QueryImpl.Update update​(com.mongodb.DBObject dbObject)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Specified by:
        update in interface Query<T>
      • getFieldName

        public java.lang.String getFieldName()
        Specified by:
        getFieldName in interface Criteria
        Returns:
        the field name for the criteria
      • isValidatingNames

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

        @Deprecated
        public com.mongodb.DBCursor prepareCursor()
        Deprecated.
        this is an internal method. no replacement is planned.
        Prepares cursor for iteration
        Returns:
        the cursor
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • 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
      • toDBObject

        public com.mongodb.DBObject toDBObject()
        Specified by:
        toDBObject in interface Criteria
        Returns:
        the DBObject form of this type
      • 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