T
- The type we will be querying for, and returning.public class QueryImpl<T> extends CriteriaContainerImpl implements Query<T>
Implementation of Query
Constructor and Description |
---|
QueryImpl(Class<T> clazz,
com.mongodb.DBCollection coll,
Datastore ds) |
Modifier and Type | Method and Description |
---|---|
List<Key<T>> |
asKeyList()
Execute the query and get the results (as a
List<Key<T>> ) This method is provided as a convenience; |
List<T> |
asList()
Execute the query and get the results (as a
List<T> ). |
Query<T> |
batchSize(int value)
Batch-size of the fetched result (cursor).
|
QueryImpl<T> |
cloneQuery()
Creates and returns a copy of this
Query . |
Query<T> |
comment(String comment)
This makes it possible to attach a comment to a query.
|
long |
countAll()
Count the total number of values in the result, ignoring limit and offset.
|
FieldEnd<? extends CriteriaContainerImpl> |
criteria(String field)
Criteria builder interface
|
Query<T> |
disableCursorTimeout()
Disables cursor timeout on server.
|
Query<T> |
disableSnapshotMode()
Disable snapshotted mode (default mode).
|
Query<T> |
disableValidation()
Turns off validation (for all calls made after)
|
Query<T> |
enableCursorTimeout()
Enables cursor timeout on server.
|
Query<T> |
enableSnapshotMode()
Enabled snapshotted mode where duplicate results (which may be updated during the lifetime of the cursor) will not be returned.
|
Query<T> |
enableValidation()
Turns on validation (for all calls made after); by default validation is on
|
Map<String,Object> |
explain()
Provides information on the query plan.
|
MorphiaIterator<T,T> |
fetch()
Execute the query and get the results.
|
MorphiaIterator<T,T> |
fetchEmptyEntities()
Execute the query and get only the ids of the results.
|
MorphiaKeyIterator<T> |
fetchKeys()
Execute the query and get the keys for the objects.
|
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 |
get()
Gets the first entity in the result set.
|
int |
getBatchSize()
Returns the batch size
|
com.mongodb.DBCollection |
getCollection()
Returns the
DBCollection of the Query . |
DatastoreImpl |
getDatastore() |
Class<T> |
getEntityClass()
Returns the entity
Class . |
String |
getFieldName() |
com.mongodb.DBObject |
getFieldsObject()
Returns the Mongo fields
DBObject . |
Key<T> |
getKey()
Get the key of the first entity in the result set.
|
int |
getLimit()
Returns the limit
|
int |
getOffset()
Returns the offset.
|
com.mongodb.DBObject |
getQueryObject()
Returns the Mongo query
DBObject . |
com.mongodb.DBObject |
getSortObject()
Returns the Mongo sort
DBObject . |
Query<T> |
hintIndex(String idxName)
Hints as to which index should be used.
|
boolean |
isValidatingNames() |
boolean |
isValidatingTypes() |
MorphiaIterator<T,T> |
iterator() |
Query<T> |
limit(int value)
Limit the fetched result set to a certain number of values.
|
Query<T> |
lowerIndexBound(com.mongodb.DBObject lowerBound)
Specify the inclusive lower bound for a specific index in order to constrain the results of this query.
|
Query<T> |
maxScan(int value)
Constrains the query to only scan the specified number of documents when fulfilling the query.
|
Query<T> |
maxTime(long value,
TimeUnit timeUnitValue)
Specifies a time limit for executing the query.
|
Query<T> |
offset(int value)
Starts the query results at a particular zero-based offset.
|
Query<T> |
order(String condition)
Sorts based on a property (defines return order).
|
static com.mongodb.BasicDBObject |
parseFieldsString(String str,
Class clazz,
Mapper mapper,
boolean validate)
parses the string and validates each part
|
com.mongodb.DBCursor |
prepareCursor() |
Query<T> |
queryNonPrimary()
Route query to non-primary node
|
Query<T> |
queryPrimaryOnly()
Route query to primary node
|
Query<T> |
retrievedFields(boolean include,
String... list)
Limits the fields retrieved
|
Query<T> |
retrieveKnownFields()
Limits the fields retrieved to those of the query type -- dangerous with interfaces and abstract classes
|
Query<T> |
returnKey()
Only return the index field or fields for the results of the query.
|
Query<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(com.mongodb.DBObject query) |
MorphiaIterator<T,T> |
tail()
Calls
tail(true); |
MorphiaIterator<T,T> |
tail(boolean awaitData)
Returns an tailing iterator over a set of elements of type T.
|
String |
toString()
Generates a string that consistently and uniquely specifies this query.
|
Query<T> |
upperIndexBound(com.mongodb.DBObject upperBound)
Specify the exclusive upper bound for a specific index in order to constrain the results of this query.
|
Query<T> |
useReadPreference(com.mongodb.ReadPreference readPref)
Route query ReadPreference
|
Query<T> |
where(org.bson.types.CodeWScope js)
Limit the query using this javascript block; only one per query
|
Query<T> |
where(String js)
Limit the query using this javascript block; only one per query
|
add, addTo, and, getChildren, getJoinMethod, getQuery, or, remove, setChildren, setJoinMethod, setQuery
attach, getAttachedTo, setAttachedTo
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public QueryImpl<T> cloneQuery()
Query
Query
.cloneQuery
in interface Query<T>
public com.mongodb.DBCollection getCollection()
Query
DBCollection
of the Query
.getCollection
in interface Query<T>
public void setQueryObject(com.mongodb.DBObject query)
public int getOffset()
Query
getOffset
in interface Query<T>
Query.offset(int)
public int getLimit()
Query
getLimit
in interface Query<T>
Query.limit(int)
public com.mongodb.DBObject getQueryObject()
Query
DBObject
.getQueryObject
in interface Query<T>
public DatastoreImpl getDatastore()
public com.mongodb.DBObject getFieldsObject()
Query
DBObject
.getFieldsObject
in interface Query<T>
public com.mongodb.DBObject getSortObject()
Query
DBObject
.getSortObject
in interface Query<T>
public boolean isValidatingNames()
public boolean isValidatingTypes()
public long countAll()
QueryResults
Count the total number of values in the result, ignoring limit and offset.
countAll
in interface QueryResults<T>
public com.mongodb.DBCursor prepareCursor()
public MorphiaIterator<T,T> fetch()
QueryResults
fetch
in interface QueryResults<T>
public MorphiaKeyIterator<T> fetchKeys()
QueryResults
fetchKeys
in interface QueryResults<T>
public List<T> asList()
QueryResults
Execute the query and get the results (as a List<T>
).
This method is provided as a convenience; List<T>
results = new ArrayList<T>; for(T ent : fetch()) results.add(ent); return results;
asList
in interface QueryResults<T>
public List<Key<T>> asKeyList()
QueryResults
List<Key<T>>
) This method is provided as a convenience;asKeyList
in interface QueryResults<T>
public MorphiaIterator<T,T> fetchEmptyEntities()
QueryResults
fetchEmptyEntities
in interface QueryResults<T>
public Query<T> filter(String condition, Object value)
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
public Query<T> where(org.bson.types.CodeWScope js)
Query
public Query<T> where(String js)
Query
public Query<T> enableValidation()
Query
enableValidation
in interface Query<T>
public Query<T> disableValidation()
Query
disableValidation
in interface Query<T>
public T get()
QueryResults
Query
offset value.get
in interface QueryResults<T>
public Key<T> getKey()
QueryResults
Query
offset value.getKey
in interface QueryResults<T>
public Query<T> limit(int value)
Query
limit
in interface Query<T>
value
- must be >= 0. A value of 0 indicates no limit. For values < 0, use Query.batchSize(int)
which is the preferred
methodpublic Query<T> batchSize(int value)
Query
public Query<T> maxScan(int value)
Query
maxScan
in interface Query<T>
value
- must be > 0. A value < 0 indicates no limitpublic Query<T> maxTime(long value, TimeUnit timeUnitValue)
Query
public Query<T> comment(String comment)
Query
comment
in interface Query<T>
comment
- the comment to addpublic Query<T> returnKey()
Query
returnKey
in interface Query<T>
public Query<T> search(String search)
Query
search
in interface Query<T>
search
- the text to search forpublic Query<T> search(String search, String language)
Query
search
in interface Query<T>
search
- the text to search forlanguage
- the language to use during the searchpublic int getBatchSize()
Query
getBatchSize
in interface Query<T>
Query.batchSize(int)
public Query<T> offset(int value)
Query
public Query<T> order(String condition)
Query
Sorts based on a property (defines return order). Examples:
order("age")
order("-age")
(descending order)order("age, date")
order("age,-date")
(age ascending, date descending)public Query<T> upperIndexBound(com.mongodb.DBObject upperBound)
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"}
upperIndexBound
in interface Query<T>
upperBound
- The exclusive upper bound.public Query<T> lowerIndexBound(com.mongodb.DBObject lowerBound)
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"}
lowerIndexBound
in interface Query<T>
lowerBound
- The inclusive lower bound.public static com.mongodb.BasicDBObject parseFieldsString(String str, Class clazz, Mapper mapper, boolean validate)
public MorphiaIterator<T,T> tail()
QueryResults
tail(true);
tail
in interface QueryResults<T>
QueryResults.tail(boolean)
public MorphiaIterator<T,T> tail(boolean awaitData)
QueryResults
tail
in interface QueryResults<T>
public Class<T> getEntityClass()
Query
Class
.getEntityClass
in interface Query<T>
public String toString()
Query
Generates a string that consistently and uniquely specifies this query. There is no way to convert this string back into a query and there is no guarantee that the string will be consistent across versions.
In particular, this value is useful as a key for a simple memcache query cache.
public FieldEnd<? extends Query<T>> field(String name)
Query
createQuery(Ent.class).field("count").greaterThan(7)...
public FieldEnd<? extends CriteriaContainerImpl> criteria(String field)
Query
criteria
in interface CriteriaContainer
criteria
in interface Query<T>
criteria
in class CriteriaContainerImpl
public Query<T> hintIndex(String idxName)
Query
public Query<T> retrievedFields(boolean include, String... list)
Query
retrievedFields
in interface Query<T>
public Query<T> retrieveKnownFields()
Query
retrieveKnownFields
in interface Query<T>
public Query<T> enableSnapshotMode()
enableSnapshotMode
in interface Query<T>
public Query<T> disableSnapshotMode()
disableSnapshotMode
in interface Query<T>
public Query<T> useReadPreference(com.mongodb.ReadPreference readPref)
Query
useReadPreference
in interface Query<T>
public Query<T> queryNonPrimary()
Query
queryNonPrimary
in interface Query<T>
ReadPreference.secondary()
,
ReadPreference.secondaryPreferred()
public Query<T> queryPrimaryOnly()
Query
queryPrimaryOnly
in interface Query<T>
ReadPreference.primary()
public Query<T> disableCursorTimeout()
disableCursorTimeout
in interface Query<T>
public Query<T> enableCursorTimeout()
enableCursorTimeout
in interface Query<T>
public String getFieldName()
getFieldName
in interface Criteria
getFieldName
in class CriteriaContainerImpl
public Map<String,Object> explain()
Query
explain
in interface Query<T>
Copyright © 2016. All rights reserved.