Package dev.morphia.query
Class LegacyQuery<T>
- java.lang.Object
-
- dev.morphia.query.LegacyQuery<T>
-
- Type Parameters:
T
- The type we will be querying for, and returning.
- All Implemented Interfaces:
Criteria
,CriteriaContainer
,Query<T>
,Iterable<T>
public class LegacyQuery<T> extends Object implements CriteriaContainer, Query<T>
Implementation of QueryDeveloper note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
LegacyQuery(Datastore datastore, String collectionName, Class<T> clazz)
Creates a Query for the given type and collection
-
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 fieldcom.mongodb.client.result.DeleteResult
delete(DeleteOptions options)
Deletes documents matching this query.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)
MorphiaCursor<T>
execute()
Deprecated, for removal: This API element is subject to removal in a future version.MorphiaCursor<T>
execute(FindOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.Map<String,Object>
explain(FindOptions options, com.mongodb.ExplainVerbosity verbosity)
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
findAndDelete(FindAndDeleteOptions options)
Deletes an entity from the database and returns it.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()
org.bson.Document
getSort()
int
hashCode()
boolean
isValidatingNames()
MorphiaCursor<T>
iterator(FindOptions options)
Execute the query and get the results.MorphiaKeyCursor<T>
keys()
Execute the query and get the results (as aMorphiaCursor<Key<T>>
)MorphiaKeyCursor<T>
keys(FindOptions options)
Execute the query and get the results (as aMorphiaCursor<Key<T>>
)Modify<T>
modify(UpdateOperator first, UpdateOperator... updates)
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.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()
Converts the query to a Document and updates for any discriminator values as my be necessaryString
toString()
Update<T>
update(UpdateOperator first, UpdateOperator... updates)
Creates an update operation based on this queryUpdate<T>
update(UpdateOperations<T> operations)
Deprecated, for removal: This API element is subject to removal in a future version.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
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
-
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
-
execute
@Deprecated(since="2.0", forRemoval=true) public 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 interfaceQuery<T>
- Returns:
- a MorphiaCursor
- See Also:
iterator(FindOptions)
-
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
-
findAndDelete
public T findAndDelete(FindAndDeleteOptions options)
Description copied from interface:Query
Deletes an entity from the database and returns it.- Specified by:
findAndDelete
in interfaceQuery<T>
- Parameters:
options
- the options to apply- Returns:
- the deleted entity
-
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.
-
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
-
execute
@Deprecated(since="2.0", forRemoval=true) public 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.
-
explain
public Map<String,Object> explain(FindOptions options, @Nullable com.mongodb.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.
-
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
.
-
modify
public Modify<T> modify(UpdateOperator first, UpdateOperator... updates)
Description copied from interface:Query
Create a modify operation based on this query
-
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.
-
getEntityClass
public Class<T> getEntityClass()
- Specified by:
getEntityClass
in interfaceQuery<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.
-
update
public Update<T> update(UpdateOperator first, UpdateOperator... updates)
Description copied from interface:Query
Creates an update operation based on this query
-
iterator
public MorphiaCursor<T> iterator(FindOptions options)
Description copied from interface:Query
Execute the query and get the results.
-
keys
public MorphiaKeyCursor<T> keys()
Description copied from interface:Query
Execute the query and get the results (as aMorphiaCursor<Key<T>>
)
-
keys
public MorphiaKeyCursor<T> keys(FindOptions options)
Description copied from interface:Query
Execute the query and get the results (as aMorphiaCursor<Key<T>>
)
-
modify
public Modify<T> modify(UpdateOperations<T> operations)
Description copied from interface:Query
This is only intended for migration of legacy uses of UpdateOperations
-
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..
-
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.
-
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.
-
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 interfaceCriteria
- Specified by:
toDocument
in interfaceQuery<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.
-
getFieldsObject
@Nullable 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.
-
getSort
@Nullable 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
-
setQueryObject
public void setQueryObject(org.bson.Document query)
Sets query structure directly- Parameters:
query
- the Document containing the query
-
getDatastore
protected Datastore getDatastore()
-
-