T - The type we will be querying for, and returning.public class QueryImpl<T> extends CriteriaContainerImpl implements Query<T>
| Constructor and Description |
|---|
QueryImpl(Class<T> clazz,
DBCollection coll,
Datastore ds)
Creates a Query for the given type and collection
|
| 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.
|
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)
Creates a criteria against a field
|
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() |
DBCollection |
getCollection() |
DatastoreImpl |
getDatastore() |
Class<T> |
getEntityClass() |
String |
getFieldName() |
DBObject |
getFieldsObject() |
Key<T> |
getKey()
Get the key of the first entity in the result set.
|
int |
getLimit() |
int |
getOffset() |
DBObject |
getQueryObject() |
DBObject |
getSortObject() |
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(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 sort)
Sorts based on a property (defines return order).
|
static BasicDBObject |
parseFieldsString(String str,
Class clazz,
Mapper mapper,
boolean validate,
List<MappedClass> parentMCs,
List<MappedField> parentMFs)
Parses the string and validates each part
|
DBCursor |
prepareCursor()
Prepares cursor for iteration
|
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(DBObject query)
Sets query structure directly
|
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() |
protected FilterOperator |
translate(String operator)
Converts the textual operator (">", "<=", etc) into a FilterOperator.
|
Query<T> |
upperIndexBound(DBObject upperBound)
Specify the exclusive upper bound for a specific index in order to constrain the results of this query.
|
Query<T> |
useReadPreference(ReadPreference readPref)
Updates the ReadPreference to use
|
Query<T> |
where(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, setQueryattach, getAttachedTo, setAttachedToclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic QueryImpl(Class<T> clazz, DBCollection coll, Datastore ds)
clazz - the type to returncoll - the collection to queryds - the Datastore to usepublic static BasicDBObject parseFieldsString(String str, Class clazz, Mapper mapper, boolean validate, List<MappedClass> parentMCs, List<MappedField> parentMFs)
str - the String to parseclazz - the class to use when validatingmapper - the Mapper to usevalidate - true if the results should be validatedparentMCs - List of parent MappedClasses for tracking potential naming schemesparentMFs - List of parent MappedFields for tracking potential naming schemespublic List<Key<T>> asKeyList()
QueryResultsList<Key<T>>) This method is provided as a convenience;asKeyList in interface QueryResults<T>public List<T> asList()
QueryResultsasList in interface QueryResults<T>public long countAll()
QueryResultscountAll in interface QueryResults<T>public MorphiaIterator<T,T> fetch()
QueryResultsfetch in interface QueryResults<T>public MorphiaIterator<T,T> fetchEmptyEntities()
QueryResultsfetchEmptyEntities in interface QueryResults<T>public MorphiaKeyIterator<T> fetchKeys()
QueryResultsfetchKeys in interface QueryResults<T>QueryResults.fetchEmptyEntities()public T get()
QueryResultsQuery offset value.get in interface QueryResults<T>public Key<T> getKey()
QueryResultsQuery offset value.getKey in interface QueryResults<T>public MorphiaIterator<T,T> tail()
QueryResultstail(true);tail in interface QueryResults<T>QueryResults.tail(boolean)public MorphiaIterator<T,T> tail(boolean awaitData)
QueryResultstail in interface QueryResults<T>awaitData - passes the awaitData to the cursorBytes.QUERYOPTION_AWAITDATApublic Query<T> batchSize(int value)
Querypublic QueryImpl<T> cloneQuery()
QueryQuery.cloneQuery in interface Query<T>public Query<T> comment(String comment)
Querypublic Query<T> disableCursorTimeout()
QuerydisableCursorTimeout in interface Query<T>public Query<T> disableSnapshotMode()
QuerydisableSnapshotMode in interface Query<T>public Query<T> disableValidation()
QuerydisableValidation in interface Query<T>public Query<T> enableCursorTimeout()
QueryenableCursorTimeout in interface Query<T>public Query<T> enableSnapshotMode()
QueryenableSnapshotMode in interface Query<T>public Query<T> enableValidation()
QueryenableValidation in interface Query<T>public Map<String,Object> explain()
Querypublic FieldEnd<? extends Query<T>> field(String name)
QuerycreateQuery(Ent.class).field("count").greaterThan(7)...public Query<T> filter(String condition, Object value)
QueryNote: 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 int getBatchSize()
getBatchSize in interface Query<T>Query.batchSize(int)public DBCollection getCollection()
getCollection in interface Query<T>DBCollection of the Query.public Class<T> getEntityClass()
getEntityClass in interface Query<T>Class.public DBObject getFieldsObject()
getFieldsObject in interface Query<T>DBObject.public int getLimit()
getLimit in interface Query<T>Query.limit(int)public int getOffset()
getOffset in interface Query<T>Query.offset(int)public DBObject getQueryObject()
getQueryObject in interface Query<T>DBObject.public void setQueryObject(DBObject query)
query - the DBObject containing the querypublic DBObject getSortObject()
getSortObject in interface Query<T>DBObject.public Query<T> hintIndex(String idxName)
Querypublic Query<T> limit(int value)
Querylimit 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> lowerIndexBound(DBObject lowerBound)
QuerySpecify 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 Query<T> maxScan(int value)
Querypublic Query<T> maxTime(long value, TimeUnit timeUnitValue)
Querypublic Query<T> offset(int value)
Querypublic Query<T> order(String sort)
Queryorder("age")order("-age") (descending order)order("age, date")order("age,-date") (age ascending, date descending)public Query<T> queryNonPrimary()
QueryqueryNonPrimary in interface Query<T>ReadPreference.secondary(),
ReadPreference.secondaryPreferred()public Query<T> queryPrimaryOnly()
QueryqueryPrimaryOnly in interface Query<T>ReadPreference.primary()public Query<T> retrieveKnownFields()
QueryretrieveKnownFields in interface Query<T>public Query<T> retrievedFields(boolean include, String... list)
QueryretrievedFields in interface Query<T>include - true if the fields should be included in the results. false to exclude them.list - the fields in questionpublic Query<T> returnKey()
Querypublic Query<T> search(String search)
Querypublic Query<T> search(String search, String language)
Querypublic Query<T> upperIndexBound(DBObject upperBound)
QuerySpecify 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> useReadPreference(ReadPreference readPref)
QueryuseReadPreference in interface Query<T>readPref - the ReadPreference to useReadPreferencepublic Query<T> where(String js)
Querypublic Query<T> where(CodeWScope js)
Querypublic FieldEnd<? extends CriteriaContainerImpl> criteria(String field)
CriteriaContainercriteria in interface CriteriaContainercriteria in interface Query<T>criteria in class CriteriaContainerImplfield - the fieldpublic String getFieldName()
getFieldName in interface CriteriagetFieldName in class CriteriaContainerImplpublic DatastoreImpl getDatastore()
public boolean isValidatingNames()
public boolean isValidatingTypes()
public DBCursor prepareCursor()
public String toString()
protected FilterOperator translate(String operator)