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,
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
|
DBCollection |
getCollection()
Returns the
DBCollection of the Query. |
DatastoreImpl |
getDatastore() |
Class<T> |
getEntityClass()
Returns the entity
Class. |
String |
getFieldName() |
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.
|
DBObject |
getQueryObject()
Returns the Mongo query
DBObject. |
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(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 BasicDBObject |
parseFieldsString(String str,
Class clazz,
Mapper mapper,
boolean validate)
parses the string and validates each part
|
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(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.
|
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)
Route query ReadPreference
|
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, setAttachedTopublic QueryImpl(Class<T> clazz, DBCollection coll, Datastore ds)
public QueryImpl<T> cloneQuery()
QueryQuery.cloneQuery in interface Query<T>public DBCollection getCollection()
QueryDBCollection of the Query.getCollection in interface Query<T>public void setQueryObject(DBObject query)
public int getOffset()
QuerygetOffset in interface Query<T>Query.offset(int)public int getLimit()
QuerygetLimit in interface Query<T>Query.limit(int)public DBObject getQueryObject()
QueryDBObject.getQueryObject in interface Query<T>public DatastoreImpl getDatastore()
public DBObject getFieldsObject()
QueryDBObject.getFieldsObject in interface Query<T>public DBObject getSortObject()
QueryDBObject.getSortObject in interface Query<T>public boolean isValidatingNames()
public boolean isValidatingTypes()
public long countAll()
QueryResultsCount the total number of values in the result, ignoring limit and offset.
countAll in interface QueryResults<T>public DBCursor prepareCursor()
public MorphiaIterator<T,T> fetch()
QueryResultsfetch in interface QueryResults<T>public MorphiaKeyIterator<T> fetchKeys()
QueryResultsfetchKeys in interface QueryResults<T>public List<T> asList()
QueryResultsExecute 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()
QueryResultsList<Key<T>>) This method is provided as a convenience;asKeyList in interface QueryResults<T>public MorphiaIterator<T,T> fetchEmptyEntities()
QueryResultsfetchEmptyEntities in interface QueryResults<T>protected FilterOperator translate(String operator)
public Query<T> filter(String condition, Object value)
QueryCreate 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(CodeWScope js)
Querypublic Query<T> where(String js)
Querypublic Query<T> enableValidation()
QueryenableValidation in interface Query<T>public Query<T> disableValidation()
QuerydisableValidation in interface Query<T>public T get()
QueryResultsQuery offset value.get in interface QueryResults<T>public Key<T> getKey()
QueryResultsQuery offset value.getKey in interface QueryResults<T>public 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> batchSize(int value)
Querypublic Query<T> maxScan(int value)
QuerymaxScan in interface Query<T>value - must be > 0. A value < 0 indicates no limitpublic Query<T> maxTime(long value, TimeUnit timeUnitValue)
Querypublic Query<T> comment(String comment)
Querycomment in interface Query<T>comment - the comment to addpublic Query<T> returnKey()
QueryreturnKey in interface Query<T>public Query<T> search(String search)
Querysearch in interface Query<T>search - the text to search forpublic Query<T> search(String search, String language)
Querysearch in interface Query<T>search - the text to search forlanguage - the language to use during the searchpublic int getBatchSize()
QuerygetBatchSize in interface Query<T>Query.batchSize(int)public Query<T> offset(int value)
Querypublic Query<T> order(String condition)
QuerySorts 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(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> 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 static BasicDBObject parseFieldsString(String str, Class clazz, Mapper mapper, boolean validate)
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>public Class<T> getEntityClass()
QueryClass.getEntityClass in interface Query<T>public String toString()
QueryGenerates 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)
QuerycreateQuery(Ent.class).field("count").greaterThan(7)...public FieldEnd<? extends CriteriaContainerImpl> criteria(String field)
Querycriteria in interface CriteriaContainercriteria in interface Query<T>criteria in class CriteriaContainerImplpublic Query<T> hintIndex(String idxName)
Querypublic Query<T> retrievedFields(boolean include, String... list)
QueryretrievedFields in interface Query<T>public Query<T> retrieveKnownFields()
QueryretrieveKnownFields 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(ReadPreference readPref)
QueryuseReadPreference in interface Query<T>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> disableCursorTimeout()
disableCursorTimeout in interface Query<T>public Query<T> enableCursorTimeout()
enableCursorTimeout in interface Query<T>public String getFieldName()
getFieldName in interface CriteriagetFieldName in class CriteriaContainerImplpublic Map<String,Object> explain()
Queryexplain in interface Query<T>