public interface Datastore
| Modifier and Type | Method and Description |
|---|---|
AggregationPipeline |
createAggregation(Class source)
Returns a new query bound to the kind (a specific
DBCollection) |
<T> Query<T> |
createQuery(Class<T> collection)
Returns a new query bound to the collection (a specific
DBCollection) |
<T> UpdateOperations<T> |
createUpdateOperations(Class<T> clazz)
The builder for all update operations
|
<T,V> WriteResult |
delete(Class<T> clazz,
Iterable<V> ids)
Deletes the given entities (by id)
|
<T,V> WriteResult |
delete(Class<T> clazz,
V id)
Deletes the given entity (by id)
|
<T> WriteResult |
delete(Query<T> query)
Deletes entities based on the query
|
<T> WriteResult |
delete(Query<T> query,
WriteConcern wc)
Deletes entities based on the query, with the WriteConcern
|
<T> WriteResult |
delete(T entity)
Deletes the given entity (by @Id)
|
<T> WriteResult |
delete(T entity,
WriteConcern wc)
Deletes the given entity (by @Id), with the WriteConcern
|
void |
ensureCaps()
ensure capped DBCollections for
Entity(s) |
<T> void |
ensureIndex(Class<T> clazz,
String fields)
Ensures (creating if necessary) the index including the field(s) + directions on the given collection name; eg fields = "field1,
-field2" ({field1:1, field2:-1})
|
<T> void |
ensureIndex(Class<T> clazz,
String name,
String fields,
boolean unique,
boolean dropDupsOnCreate)
Ensures (creating if necessary) the index including the field(s) + directions on the given collection name; eg fields = "field1,
-field2" ({field1:1, field2:-1})
|
void |
ensureIndexes()
Ensures (creating if necessary) the indexes found during class mapping (using
@Indexed, @Indexes) |
void |
ensureIndexes(boolean background)
Ensures (creating if necessary) the indexes found during class mapping (using
@Indexed, @Indexes) on the given collection
name, possibly in the background |
<T> void |
ensureIndexes(Class<T> clazz)
Ensures (creating if necessary) the indexes found during class mapping (using
@Indexed, @Indexes) |
<T> void |
ensureIndexes(Class<T> clazz,
boolean background)
Ensures (creating if necessary) the indexes found during class mapping (using
@Indexed, @Indexes), possibly in the
background |
Key<?> |
exists(Object keyOrEntity)
Does a query to check if the keyOrEntity exists in mongodb
|
<T> Query<T> |
find(Class<T> clazz)
Find all instances by type
|
<T,V> Query<T> |
find(Class<T> clazz,
String property,
V value)
Find all instances by collectionName, and filter property.
|
<T,V> Query<T> |
find(Class<T> clazz,
String property,
V value,
int offset,
int size)
Find all instances by type in a different collection than what is mapped on the class given skipping some documents and returning a
fixed number of the remaining.
|
<T> T |
findAndDelete(Query<T> query)
Deletes the given entities based on the query (first item only).
|
<T> T |
findAndModify(Query<T> query,
UpdateOperations<T> operations)
Find the first Entity from the Query, and modify it.
|
<T> T |
findAndModify(Query<T> query,
UpdateOperations<T> operations,
boolean oldVersion)
Find the first Entity from the Query, and modify it.
|
<T> T |
findAndModify(Query<T> query,
UpdateOperations<T> operations,
boolean oldVersion,
boolean createIfMissing)
Find the first Entity from the Query, and modify it.
|
<T,V> Query<T> |
get(Class<T> clazz,
Iterable<V> ids)
Find the given entities (by id); shorthand for
find("_id in", ids) |
<T,V> T |
get(Class<T> clazz,
V id)
Find the given entity (by id); shorthand for
find("_id ", id) |
<T> T |
get(T entity)
Find the given entity (by collectionName/id); think of this as refresh
|
<T> T |
getByKey(Class<T> clazz,
Key<T> key)
Find the given entity (by collectionName/id);
|
<T> List<T> |
getByKeys(Class<T> clazz,
Iterable<Key<T>> keys)
Find the given entities (by id), verifying they are of the correct type; shorthand for
find("_id in", ids) |
<T> List<T> |
getByKeys(Iterable<Key<T>> keys)
Find the given entities (by id); shorthand for
find("_id in", ids) |
DBCollection |
getCollection(Class<?> clazz) |
<T> long |
getCount(Class<T> clazz)
Gets the count this kind (
DBCollection) |
<T> long |
getCount(Query<T> query)
Gets the count of items returned by this query; same as
query.countAll() |
<T> long |
getCount(T entity)
Gets the count this kind (
DBCollection) |
DB |
getDB() |
WriteConcern |
getDefaultWriteConcern() |
<T> Key<T> |
getKey(T entity)
Creates a (type-safe) reference to the entity; if stored this will become a
DBRef |
MongoClient |
getMongo()
Get the underlying MongoClient that allows connection to the MongoDB instance being used.
|
QueryFactory |
getQueryFactory() |
<T> MapreduceResults<T> |
mapReduce(MapreduceType type,
Query q,
Class<T> outputType,
MapReduceCommand baseCommand)
Runs a map/reduce job at the server; this should be used with a server version 1.7.4 or higher
|
<T> MapreduceResults<T> |
mapReduce(MapreduceType type,
Query q,
String map,
String reduce,
String finalize,
Map<String,Object> scopeFields,
Class<T> outputType)
Runs a map/reduce job at the server; this should be used with a server version 1.7.4 or higher
|
<T> Key<T> |
merge(T entity)
Work as if you did an update with each field in the entity doing a $set; Only at the top level of the entity.
|
<T> Key<T> |
merge(T entity,
WriteConcern wc)
Work as if you did an update with each field in the entity doing a $set; Only at the top level of the entity.
|
<T> Query<T> |
queryByExample(T example)
Returns a new query based on the example object
|
<T> Iterable<Key<T>> |
save(Iterable<T> entities)
Saves the entities (Objects) and updates the @Id field
|
<T> Iterable<Key<T>> |
save(Iterable<T> entities,
WriteConcern wc)
Saves the entities (Objects) and updates the @Id field, with the WriteConcern
|
<T> Iterable<Key<T>> |
save(T... entities)
Saves the entities (Objects) and updates the @Id field
|
<T> Key<T> |
save(T entity)
Saves an entity (Object) and updates the @Id field
|
<T> Key<T> |
save(T entity,
WriteConcern wc)
Saves an entity (Object) and updates the @Id field, with the WriteConcern
|
void |
setDefaultWriteConcern(WriteConcern wc)
Sets the default WriteConcern for this Datastore
|
void |
setQueryFactory(QueryFactory queryFactory)
Replaces the current
QueryFactory with the given value. |
<T> UpdateResults |
update(Key<T> key,
UpdateOperations<T> operations)
Updates an entity with the operations; this is an atomic operation
|
<T> UpdateResults |
update(Query<T> query,
UpdateOperations<T> operations)
Updates all entities found with the operations; this is an atomic operation per entity
|
<T> UpdateResults |
update(Query<T> query,
UpdateOperations<T> operations,
boolean createIfMissing)
Updates all entities found with the operations, if nothing is found insert the update as an entity if "createIfMissing" is true;
this
is an atomic operation per entity
|
<T> UpdateResults |
update(Query<T> query,
UpdateOperations<T> operations,
boolean createIfMissing,
WriteConcern wc)
Updates all entities found with the operations, if nothing is found insert the update as an entity if "createIfMissing" is true;
this
is an atomic operation per entity
|
<T> UpdateResults |
update(T entity,
UpdateOperations<T> operations)
Updates an entity with the operations; this is an atomic operation
|
<T> UpdateResults |
updateFirst(Query<T> query,
T entity,
boolean createIfMissing)
updates the first entity found using the entity as a template, if nothing is found insert the update as an entity if
"createIfMissing" is true.
|
<T> UpdateResults |
updateFirst(Query<T> query,
UpdateOperations<T> operations)
Updates the first entity found with the operations; this is an atomic operation
|
<T> UpdateResults |
updateFirst(Query<T> query,
UpdateOperations<T> operations,
boolean createIfMissing)
Updates the first entity found with the operations, if nothing is found insert the update as an entity if "createIfMissing" is true.
|
<T> UpdateResults |
updateFirst(Query<T> query,
UpdateOperations<T> operations,
boolean createIfMissing,
WriteConcern wc)
Updates the first entity found with the operations, if nothing is found insert the update as an entity if "createIfMissing" is true.
|
AggregationPipeline createAggregation(Class source)
DBCollection)source - The class to create aggregation against<T> Query<T> createQuery(Class<T> collection)
DBCollection)T - the type of the querycollection - The collection to query<T> UpdateOperations<T> createUpdateOperations(Class<T> clazz)
T - the type to updateclazz - the type to update<T,V> WriteResult delete(Class<T> clazz, V id)
T - the type to deleteV - the type of the idclazz - the type to deleteid - the ID of the entity to delete<T,V> WriteResult delete(Class<T> clazz, Iterable<V> ids)
T - the type to deleteV - the type of the idclazz - the type to deleteids - the IDs of the entity to delete<T> WriteResult delete(Query<T> query)
T - the type to deletequery - the query to use when finding documents to delete<T> WriteResult delete(Query<T> query, WriteConcern wc)
T - the type to deletequery - the query to use when finding documents to deletewc - the WriteConcern to use when deleting<T> WriteResult delete(T entity)
T - the type to deleteentity - the entity to delete<T> WriteResult delete(T entity, WriteConcern wc)
T - the type to deleteentity - the entity to deletewc - the WriteConcern to use when deletingvoid ensureCaps()
Entity(s)<T> void ensureIndex(Class<T> clazz, String fields)
T - the type to indexclazz - the class from which to get the index definitionsfields - the fields to index<T> void ensureIndex(Class<T> clazz, String name, String fields, boolean unique, boolean dropDupsOnCreate)
T - the type to indexclazz - the class from which to get the index definitionsname - the name of the index to createfields - the fields to indexunique - true if the index should enforce uniqueness on the fields indexeddropDupsOnCreate - if unique is true and this is true, any documents with duplicated fields being indexed will be dropped. If
this is false, index creation will fail.void ensureIndexes()
@Indexed, @Indexes)void ensureIndexes(boolean background)
@Indexed, @Indexes) on the given collection
name, possibly in the backgroundbackground - if true, the index will be built in the background. If false, the method will block until the index is created.<T> void ensureIndexes(Class<T> clazz)
@Indexed, @Indexes)T - the type to indexclazz - the class from which to get the index definitions<T> void ensureIndexes(Class<T> clazz, boolean background)
@Indexed, @Indexes), possibly in the
backgroundT - the type to indexclazz - the class from which to get the index definitionsbackground - if true, the index will be built in the background. If false, the method will block until the index is created.Key<?> exists(Object keyOrEntity)
keyOrEntity - the value to check for<T> Query<T> find(Class<T> clazz)
T - the type to queryclazz - the class to use for mapping the results<T,V> Query<T> find(Class<T> clazz, String property, V value)
Find all instances by collectionName, and filter property.
This is the same as: find(clazzOrEntity).filter
(property, value);
T - the type to queryV - the type to filter valueclazz - the class to use for mapping the resultsproperty - the document property to query againstvalue - the value to check for<T,V> Query<T> find(Class<T> clazz, String property, V value, int offset, int size)
T - the type to queryV - the type to filter valueclazz - the class to use for mapping the resultsproperty - the document property to query againstvalue - the value to check foroffset - the number of results to skipsize - the maximum number of results to return<T> T findAndDelete(Query<T> query)
T - the type to queryquery - the query to use when finding entities to delete<T> T findAndModify(Query<T> query, UpdateOperations<T> operations)
T - the type to queryquery - the query to use when finding entities to updateoperations - the updates to apply to the matched documents<T> T findAndModify(Query<T> query, UpdateOperations<T> operations, boolean oldVersion)
T - the type to queryquery - the query to find the Entity with; You are not allowed to offset/skip in the query.operations - the updates to apply to the matched documentsoldVersion - indicated the old version of the Entity should be returned<T> T findAndModify(Query<T> query, UpdateOperations<T> operations, boolean oldVersion, boolean createIfMissing)
T - the type of the entityquery - the query to find the Entity with; You are not allowed to offset/skip in the query.operations - the updates to apply to the matched documentsoldVersion - indicated the old version of the Entity should be returnedcreateIfMissing - if the query returns no results, then a new object will be created (sets upsert=true)<T,V> Query<T> get(Class<T> clazz, Iterable<V> ids)
find("_id in", ids)T - the type to fetchV - the type of the IDclazz - the class to use for mappingids - the IDs to query<T,V> T get(Class<T> clazz, V id)
find("_id ", id)T - the type to fetchV - the type of the IDclazz - the class to use for mappingid - the ID to query<T> T get(T entity)
T - the type to fetchentity - The entity to search for<T> T getByKey(Class<T> clazz, Key<T> key)
T - the type to fetchclazz - the class to use for mappingkey - the key search with<T> List<T> getByKeys(Class<T> clazz, Iterable<Key<T>> keys)
find("_id in", ids)T - the type to fetchclazz - the class to use for mappingkeys - the keys to search with<T> List<T> getByKeys(Iterable<Key<T>> keys)
find("_id in", ids)T - the type to fetchkeys - the keys to search withDBCollection getCollection(Class<?> clazz)
clazz - the class to use for mapping<T> long getCount(T entity)
DBCollection)T - the type to countentity - The entity whose type to count<T> long getCount(Class<T> clazz)
DBCollection)T - the type to countclazz - The clazz type to count<T> long getCount(Query<T> query)
query.countAll()T - the type to countquery - the query to filter the documents to countDB getDB()
WriteConcern getDefaultWriteConcern()
void setDefaultWriteConcern(WriteConcern wc)
wc - the default WriteConcern to be used by this Datastore<T> Key<T> getKey(T entity)
DBRefT - the type of the entityentity - the entity whose key is to be returnedMongoClient getMongo()
QueryFactory getQueryFactory()
QueryFactory.QueryFactoryvoid setQueryFactory(QueryFactory queryFactory)
QueryFactory with the given value.queryFactory - the QueryFactory to useQueryFactory<T> MapreduceResults<T> mapReduce(MapreduceType type, Query q, String map, String reduce, String finalize, Map<String,Object> scopeFields, Class<T> outputType)
T - The type of resulting dataoutputType - The type of resulting data; inline is not working yettype - MapreduceTypeq - The query (only the criteria, limit and sort will be used)map - The map function, in javascript, as a stringreduce - The reduce function, in javascript, as a stringfinalize - The finalize function, in javascript, as a string; can be nullscopeFields - Each map entry will be a global variable in all the functions; can be null<T> MapreduceResults<T> mapReduce(MapreduceType type, Query q, Class<T> outputType, MapReduceCommand baseCommand)
T - The type of resulting datatype - MapreduceTypeq - The query (only the criteria, limit and sort will be used)outputType - The type of resulting data; inline is not working yetbaseCommand - The base command to fill in and send to the server<T> Key<T> merge(T entity)
T - the type of the entityentity - the entity to merge back in to the database<T> Key<T> merge(T entity, WriteConcern wc)
T - the type of the entityentity - the entity to merge back in to the databasewc - the WriteConcern to use<T> Query<T> queryByExample(T example)
T - the type of the entityexample - the example entity to use when creating the query<T> Iterable<Key<T>> save(Iterable<T> entities)
T - the type of the entityentities - the entities to save<T> Iterable<Key<T>> save(Iterable<T> entities, WriteConcern wc)
T - the type of the entityentities - the entities to savewc - the WriteConcern to use<T> Iterable<Key<T>> save(T... entities)
T - the type of the entityentities - the entities to save<T> Key<T> save(T entity)
T - the type of the entityentity - the entity to save<T> Key<T> save(T entity, WriteConcern wc)
T - the type of the entityentity - the entity to savewc - the WriteConcern to use<T> UpdateResults update(T entity, UpdateOperations<T> operations)
T - the type of the entityentity - the entity to updateoperations - the update operations to performUpdateResults<T> UpdateResults update(Key<T> key, UpdateOperations<T> operations)
T - the type of the entitykey - the key of entity to updateoperations - the update operations to performUpdateResults<T> UpdateResults update(Query<T> query, UpdateOperations<T> operations)
T - the type of the entityquery - the query used to match the documents to updateoperations - the update operations to perform<T> UpdateResults update(Query<T> query, UpdateOperations<T> operations, boolean createIfMissing)
T - the type of the entityquery - the query used to match the documents to updateoperations - the update operations to performcreateIfMissing - if true, a document will be created if none can be found that match the query<T> UpdateResults update(Query<T> query, UpdateOperations<T> operations, boolean createIfMissing, WriteConcern wc)
T - the type of the entityquery - the query used to match the documents to updateoperations - the update operations to performcreateIfMissing - if true, a document will be created if none can be found that match the querywc - the WriteConcern to use<T> UpdateResults updateFirst(Query<T> query, UpdateOperations<T> operations)
T - the type of the entityquery - the query used to match the document to updateoperations - the update operations to perform<T> UpdateResults updateFirst(Query<T> query, UpdateOperations<T> operations, boolean createIfMissing)
T - the type of the entityquery - the query used to match the documents to updateoperations - the update operations to performcreateIfMissing - if true, a document will be created if none can be found that match the query<T> UpdateResults updateFirst(Query<T> query, UpdateOperations<T> operations, boolean createIfMissing, WriteConcern wc)
T - the type of the entityquery - the query used to match the documents to updateoperations - the update operations to performcreateIfMissing - if true, a document will be created if none can be found that match the querywc - the WriteConcern to use<T> UpdateResults updateFirst(Query<T> query, T entity, boolean createIfMissing)
T - the type of the entityquery - the query used to match the documents to updateentity - the entity whose state will be used as an update template for any matching documentscreateIfMissing - if true, a document will be created if none can be found that match the query