Package dev.morphia.query
Class QueryImpl<T>
- java.lang.Object
-
- dev.morphia.query.QueryImpl<T>
-
- Type Parameters:
T
- The type we will be querying for, and returning.
- All Implemented Interfaces:
Criteria
,CriteriaContainer
,Query<T>
public class QueryImpl<T> extends Object implements CriteriaContainer, Query<T>
Implementation of Query
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(Criteria... criteria)
Adds Criteria to this containerCriteriaContainer
and(Criteria... criteria)
Ands Criteria with this CriteriaContainer.void
attach(CriteriaContainer container)
Used to add this Criteria to a CriteriaContainerlong
count()
Count the total number of values in the result, ignoring limit and offsetlong
count(CountOptions options)
Count the total number of values in the result, ignoring limit and offsetFieldEnd<? extends CriteriaContainer>
criteria(String field)
Creates a criteria against a fieldT
delete(FindAndDeleteOptions options)
Deletes an entity from the database and returns it.Query<T>
disableValidation()
Turns off validation (for all calls made after)Query<T>
enableValidation()
Turns on validation (for all calls made after); by default validation is onboolean
equals(Object o)
dev.morphia.query.internal.MorphiaCursor<T>
execute()
Execute the query and get the results.dev.morphia.query.internal.MorphiaCursor<T>
execute(FindOptions options)
Execute the query and get the results.Map<String,Object>
explain(FindOptions options)
Provides information on the query plan.FieldEnd<? extends Query<T>>
field(String name)
Fluent query interface:createQuery(Ent.class).field("count").greaterThan(7)...
Query<T>
filter(String condition, Object value)
Create a filter based on the specified condition and value.T
first()
Gets the first entity in the result set.T
first(FindOptions options)
Gets the first entity in the result set.com.mongodb.client.MongoCollection<T>
getCollection()
protected Datastore
getDatastore()
Class<T>
getEntityClass()
String
getFieldName()
org.bson.Document
getFieldsObject()
String
getLoggedQuery()
org.bson.Document
getSort()
int
hashCode()
boolean
isValidatingNames()
dev.morphia.query.internal.MorphiaKeyCursor<T>
keys()
Execute the query and get the results (as aMorphiaCursor<Key<T>>
)dev.morphia.query.internal.MorphiaKeyCursor<T>
keys(FindOptions options)
Execute the query and get the results (as aMorphiaCursor<Key<T>>
)Modify<T>
modify()
Create a modify operation based on this queryModify<T>
modify(UpdateOperations<T> operations)
This is only intended for migration of legacy uses of UpdateOperationsCriteriaContainer
or(Criteria... criteria)
Ors Criteria with this CriteriaContainer.Query<T>
order(Meta sort)
Sorts based on a metadata (defines return order).Query<T>
order(Sort... sorts)
Sorts based on a specified sort keys (defines return order).org.bson.Document
prepareQuery()
Converts the query to a Document and updates for any discriminator values as my be necessaryQuery<T>
project(Meta meta)
Adds a metadata field to a projection.Query<T>
project(String field, boolean include)
Adds a field to the projection clause.Query<T>
project(String field, ArraySlice slice)
Adds an sliced array field to a projection.com.mongodb.client.result.DeleteResult
remove(DeleteOptions options)
Deletes documents matching this query.void
remove(Criteria criteria)
Removes Criteria to this containerQuery<T>
retrieveKnownFields()
Limits the fields retrieved to those of the query type -- dangerous with interfaces and abstract classesQuery<T>
search(String search)
Perform a text search on the content of the fields indexed with a text index..Query<T>
search(String search, String language)
Perform a text search on the content of the fields indexed with a text index..void
setQueryObject(org.bson.Document query)
Sets query structure directlyorg.bson.Document
toDocument()
String
toString()
Update<T>
update()
Creates an update operation based on this queryUpdate<T>
update(UpdateOperations operations)
Deprecated, for removal: This API element is subject to removal in a future version.Update<T>
update(org.bson.Document document)
Deprecated, for removal: This API element is subject to removal in a future version.Query<T>
where(String js)
Limit the query using this javascript block; only one per query
-
-
-
Method Detail
-
disableValidation
public Query<T> disableValidation()
Description copied from interface:Query
Turns off validation (for all calls made after)- Specified by:
disableValidation
in interfaceQuery<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 interfaceQuery<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.
-
field
public FieldEnd<? extends Query<T>> field(String name)
Description copied from interface:Query
Fluent query interface:createQuery(Ent.class).field("count").greaterThan(7)...
-
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
.
-
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" }})
-
order
public Query<T> order(Sort... sorts)
Description copied from interface:Query
Sorts based on a specified sort keys (defines return order).
-
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 interfaceQuery<T>
- Parameters:
field
- the field to projectinclude
- true to include the field in the results- Returns:
- this
- See Also:
- Project Fields to Return from Query
-
project
public Query<T> project(String field, ArraySlice slice)
Description copied from interface:Query
Adds an sliced array field to a projection.- Specified by:
project
in interfaceQuery<T>
- Parameters:
field
- the field to projectslice
- the options for projecting an array field- Returns:
- this
- See Also:
- Project Fields to Return from Query
-
project
public Query<T> project(Meta meta)
Description copied from interface:Query
Adds a metadata field to a projection.- Specified by:
project
in interfaceQuery<T>
- Parameters:
meta
- the metadata option for projecting- 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 interfaceQuery<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..
-
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..
-
where
public Query<T> where(String js)
Description copied from interface:Query
Limit the query using this javascript block; only one per query
-
keys
public dev.morphia.query.internal.MorphiaKeyCursor<T> keys()
Description copied from interface:Query
Execute the query and get the results (as aMorphiaCursor<Key<T>>
)
-
keys
public dev.morphia.query.internal.MorphiaKeyCursor<T> keys(FindOptions options)
Description copied from interface:Query
Execute the query and get the results (as aMorphiaCursor<Key<T>>
)
-
count
public long count()
Description copied from interface:Query
Count the total number of values in the result, ignoring limit and offset
-
count
public long count(CountOptions options)
Description copied from interface:Query
Count the total number of values in the result, ignoring limit and offset
-
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 interfaceQuery<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.
-
first
public T first()
Description copied from interface:Query
Gets the first entity in the result set. Obeys theQuery
offset value.
-
first
public T first(FindOptions options)
Description copied from interface:Query
Gets the first entity in the result set. Obeys theQuery
offset value.
-
delete
public T delete(FindAndDeleteOptions options)
Description copied from interface:Query
Deletes an entity from the database and returns it.
-
modify
public Modify<T> modify()
Description copied from interface:Query
Create a modify operation based on this query
-
modify
public Modify<T> modify(UpdateOperations<T> operations)
Description copied from interface:Query
This is only intended for migration of legacy uses of UpdateOperations
-
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.
-
update
public Update<T> update()
Description copied from interface:Query
Creates an update operation based on this query
-
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.
-
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.
-
getLoggedQuery
public String getLoggedQuery()
- Specified by:
getLoggedQuery
in interfaceQuery<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 interfaceCriteria
- 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
-
getFieldName
public String getFieldName()
- Specified by:
getFieldName
in interfaceCriteria
- 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 interfaceCriteriaContainer
- Parameters:
criteria
- the criteria to add
-
and
public CriteriaContainer and(Criteria... criteria)
Description copied from interface:CriteriaContainer
Ands Criteria with this CriteriaContainer.- Specified by:
and
in interfaceCriteriaContainer
- Specified by:
and
in interfaceQuery<T>
- Parameters:
criteria
- the criteria- Returns:
- the container
-
criteria
public FieldEnd<? extends CriteriaContainer> criteria(String field)
Description copied from interface:CriteriaContainer
Creates a criteria against a field- Specified by:
criteria
in interfaceCriteriaContainer
- Specified by:
criteria
in interfaceQuery<T>
- Parameters:
field
- the field- Returns:
- the FieldEnd to define the criteria to apply
-
or
public CriteriaContainer or(Criteria... criteria)
Description copied from interface:CriteriaContainer
Ors Criteria with this CriteriaContainer.- Specified by:
or
in interfaceCriteriaContainer
- Specified by:
or
in interfaceQuery<T>
- Parameters:
criteria
- the criteria- Returns:
- the container
-
remove
public void remove(Criteria criteria)
Description copied from interface:CriteriaContainer
Removes Criteria to this container- Specified by:
remove
in interfaceCriteriaContainer
- 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
-
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()
-
-