public class DatastoreImpl extends Object implements AdvancedDatastore
| Constructor and Description |
|---|
DatastoreImpl(Morphia morphia,
Mapper mapper,
MongoClient mongoClient,
DB db)
Create a new DatastoreImpl
|
DatastoreImpl(Morphia morphia,
Mapper mapper,
MongoClient mongoClient,
String dbName)
Create a new DatastoreImpl
|
DatastoreImpl(Morphia morphia,
MongoClient mongoClient,
String dbName)
Create a new DatastoreImpl
|
| Modifier and Type | Method and Description |
|---|---|
DatastoreImpl |
copy(String database)
Creates a copy of this Datastore and all its configuration but with a new database
|
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> Query<T> |
createQuery(Class<T> clazz,
DBObject q) |
<T> Query<T> |
createQuery(String collection,
Class<T> type) |
<T> Query<T> |
createQuery(String collection,
Class<T> type,
DBObject q) |
<T,V> DBRef |
createRef(Class<T> clazz,
V id)
Creates a reference to the entity (using the current DB -can be null-, the collectionName, and id)
|
<T> DBRef |
createRef(T entity)
Creates a reference to the entity (using the current DB -can be null-, the collectionName, and id)
|
<T> UpdateOperations<T> |
createUpdateOperations(Class<T> clazz)
The builder for all update operations
|
<T> UpdateOperations<T> |
createUpdateOperations(Class<T> type,
DBObject ops)
Creates an UpdateOperations instance for the given type.
|
<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,V> WriteResult |
delete(Class<T> clazz,
V id,
WriteConcern wc)
Deletes entities based on the query, with the WriteConcern
|
<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,V> WriteResult |
delete(String kind,
Class<T> clazz,
V id)
Deletes an entity of the given type T, with the given
id, from the collection with the name in the kind param. |
<T,V> WriteResult |
delete(String kind,
Class<T> clazz,
V id,
WriteConcern wc)
Deletes an entity of the given type T, with the given
id, from the collection with the name in the kind param. |
<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> type,
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})
|
protected <T> void |
ensureIndex(Class<T> clazz,
String name,
BasicDBObject fields,
boolean unique,
boolean dropDupsOnCreate,
boolean background,
boolean sparse,
int expireAfterSeconds) |
<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})
|
protected void |
ensureIndex(DBCollection dbColl,
DBObject keys,
DBObject options) |
protected void |
ensureIndex(DBCollection dbColl,
String name,
BasicDBObject fields,
boolean unique,
boolean dropDupsOnCreate,
boolean background,
boolean sparse,
int expireAfterSeconds) |
protected void |
ensureIndex(MappedClass mc,
DBCollection dbColl,
Field[] fields,
IndexOptions options,
boolean background,
List<MappedClass> parentMCs,
List<MappedField> parentMFs) |
<T> void |
ensureIndex(String collection,
Class<T> type,
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(String collection,
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 |
protected void |
ensureIndexes(DBCollection dbColl,
MappedClass mc,
boolean background,
List<MappedClass> parentMCs,
List<MappedField> parentMFs) |
protected void |
ensureIndexes(MappedClass mc,
boolean background) |
protected void |
ensureIndexes(MappedClass mc,
boolean background,
List<MappedClass> parentMCs,
List<MappedField> parentMFs) |
<T> void |
ensureIndexes(String collection,
Class<T> clazz)
Ensures (creating if necessary) the indexes found during class mapping (using
@Indexed, @Indexes) on the given collection
name. |
<T> void |
ensureIndexes(String collection,
Class<T> clazz,
boolean background)
Ensures (creating if necessary) the indexes found during class mapping (using
@Indexed, @Indexes) on the given collection
name, possibly in the background |
protected void |
ensureIndexes(String collName,
MappedClass mc,
boolean background) |
Key<?> |
exists(Object entityOrKey)
Does a query to check if the keyOrEntity exists in mongodb
|
Key<?> |
exists(Object entityOrKey,
ReadPreference readPreference)
Checks that an entity exists for the given key or entity
|
<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> Query<T> |
find(String collection,
Class<T> clazz)
Find all instances by type in a different collection than what is mapped on the class given.
|
<T,V> Query<T> |
find(String collection,
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,V> Query<T> |
find(String collection,
Class<T> clazz,
String property,
V value,
int offset,
int size,
boolean validate)
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> T |
get(Class<T> clazz,
DBRef ref)
Find the given entity (by collectionName/id);
|
<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,V> T |
get(String collection,
Class<T> clazz,
V id)
Finds an entity in the named collection whose id matches the value given.
|
<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) |
DBCollection |
getCollection(Object obj) |
protected DBCollection |
getCollection(String kind) |
<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() |
long |
getCount(String collection)
Gets the count this collection
|
<T> long |
getCount(T entity)
Gets the count this kind (
DBCollection) |
DB |
getDB() |
DBDecoderFactory |
getDecoderFact()
Returns the DBDecoderFactory used by this Datastore
|
WriteConcern |
getDefaultWriteConcern() |
protected Object |
getId(Object entity)
Deprecated.
|
<T> Key<T> |
getKey(T entity)
Deprecated.
|
Mapper |
getMapper() |
MongoClient |
getMongo()
Get the underlying MongoClient that allows connection to the MongoDB instance being used.
|
QueryFactory |
getQueryFactory() |
protected <T> Key<T> |
insert(DBCollection dbColl,
T entity,
WriteConcern wc) |
<T> Iterable<Key<T>> |
insert(Iterable<T> entities)
Inserts entities in to the database
|
<T> Iterable<Key<T>> |
insert(Iterable<T> entities,
WriteConcern wc)
Inserts entities in to the mapped collection.
|
<T> Iterable<Key<T>> |
insert(String collection,
Iterable<T> entities)
Inserts an entity in to the named collection.
|
<T> Iterable<Key<T>> |
insert(String collection,
Iterable<T> entities,
WriteConcern wc)
Inserts an entity in to the named collection.
|
<T> Key<T> |
insert(String collection,
T entity)
Inserts an entity in to the named collection.
|
<T> Key<T> |
insert(String collection,
T entity,
WriteConcern wc)
Inserts an entity in to the database
|
<T> Iterable<Key<T>> |
insert(T... entities)
Inserts entities in to the mapped collection.
|
<T> Key<T> |
insert(T entity)
Inserts an entity in to the mapped collection.
|
<T> Key<T> |
insert(T entity,
WriteConcern wc)
Inserts an entity in to the mapped collection.
|
<T> MapreduceResults<T> |
mapReduce(MapreduceType type,
Query query,
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 query,
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(String collection,
T ex)
Returns a new query based on the example object
|
<T> Query<T> |
queryByExample(T ex)
Returns a new query based on the example object
|
protected <T> Key<T> |
save(DBCollection dbColl,
T entity,
WriteConcern wc) |
<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> Key<T> |
save(String collection,
T entity)
Saves an entity in to the named collection.
|
<T> Key<T> |
save(String collection,
T entity,
WriteConcern wc)
Saves an entity in to the named collection.
|
<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 |
setDecoderFact(DBDecoderFactory fact)
Sets the DBDecoderFactory to use in this Datastore
|
void |
setDefaultWriteConcern(WriteConcern wc)
Sets the default WriteConcern for this Datastore
|
void |
setMapper(Mapper mapper)
Sets the Mapper this Datastore uses
|
void |
setQueryFactory(QueryFactory queryFactory)
Replaces the current
QueryFactory with the given value. |
protected <T> WriteResult |
tryVersionedUpdate(DBCollection dbColl,
T entity,
DBObject dbObj,
Object idValue,
WriteConcern wc,
MappedClass mc) |
<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.
|
public DatastoreImpl(Morphia morphia, MongoClient mongoClient, String dbName)
morphia - the Morphia instancemongoClient - the connection to the MongoDB instancedbName - the name of the database for this data store.public DatastoreImpl(Morphia morphia, Mapper mapper, MongoClient mongoClient, String dbName)
morphia - the Morphia instancemapper - an initialised MappermongoClient - the connection to the MongoDB instancedbName - the name of the database for this data store.public DatastoreImpl(Morphia morphia, Mapper mapper, MongoClient mongoClient, DB db)
morphia - the Morphia instancemapper - an initialised MappermongoClient - the connection to the MongoDB instancedb - the database for this data store.public DatastoreImpl copy(String database)
database - the new database to use for operationspublic AggregationPipeline createAggregation(Class source)
DatastoreDBCollection)createAggregation in interface Datastoresource - the initial type/collection to aggregate againstDBCollection)public <T> Query<T> createQuery(Class<T> collection)
DatastoreDBCollection)createQuery in interface DatastoreT - the type of the querycollection - The collection to querypublic <T> UpdateOperations<T> createUpdateOperations(Class<T> clazz)
DatastorecreateUpdateOperations in interface DatastoreT - the type to updateclazz - the type to updatepublic <T,V> WriteResult delete(Class<T> clazz, V id)
Datastorepublic <T,V> WriteResult delete(Class<T> clazz, Iterable<V> ids)
Datastorepublic <T> WriteResult delete(Query<T> query)
Datastorepublic <T> WriteResult delete(Query<T> query, WriteConcern wc)
Datastorepublic <T> WriteResult delete(T entity)
Datastorepublic <T> WriteResult delete(T entity, WriteConcern wc)
Datastorepublic void ensureCaps()
DatastoreEntity(s)ensureCaps in interface Datastorepublic <T> void ensureIndex(Class<T> type, String fields)
DatastoreensureIndex in interface DatastoreT - the type to indextype - the class from which to get the index definitionsfields - the fields to indexpublic <T> void ensureIndex(Class<T> clazz, String name, String fields, boolean unique, boolean dropDupsOnCreate)
DatastoreensureIndex in interface DatastoreT - 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.public void ensureIndexes()
Datastore@Indexed, @Indexes)ensureIndexes in interface Datastorepublic void ensureIndexes(boolean background)
Datastore@Indexed, @Indexes) on the given collection
name, possibly in the backgroundensureIndexes in interface Datastorebackground - if true, the index will be built in the background. If false, the method will block until the index is created.public <T> void ensureIndexes(Class<T> clazz)
Datastore@Indexed, @Indexes)ensureIndexes in interface DatastoreT - the type to indexclazz - the class from which to get the index definitionspublic <T> void ensureIndexes(Class<T> clazz, boolean background)
Datastore@Indexed, @Indexes), possibly in the
backgroundensureIndexes in interface DatastoreT - 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.public Key<?> exists(Object entityOrKey)
Datastorepublic <T> Query<T> find(Class<T> clazz)
Datastorepublic <T,V> Query<T> find(Class<T> clazz, String property, V value)
DatastoreFind all instances by collectionName, and filter property.
This is the same as: find(clazzOrEntity).filter
(property, value);
public <T,V> Query<T> find(Class<T> clazz, String property, V value, int offset, int size)
Datastorefind in interface DatastoreT - 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 returnpublic <T> T findAndDelete(Query<T> query)
DatastorefindAndDelete in interface DatastoreT - the type to queryquery - the query to use when finding entities to deletepublic <T> T findAndModify(Query<T> query, UpdateOperations<T> operations)
DatastorefindAndModify in interface DatastoreT - the type to queryquery - the query to use when finding entities to updateoperations - the updates to apply to the matched documentspublic <T> T findAndModify(Query<T> query, UpdateOperations<T> operations, boolean oldVersion)
DatastorefindAndModify in interface DatastoreT - 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 returnedpublic <T> T findAndModify(Query<T> query, UpdateOperations<T> operations, boolean oldVersion, boolean createIfMissing)
DatastorefindAndModify in interface DatastoreT - 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)public <T,V> Query<T> get(Class<T> clazz, Iterable<V> ids)
Datastorefind("_id in", ids)public <T,V> T get(Class<T> clazz, V id)
Datastorefind("_id ", id)public <T> T get(T entity)
Datastorepublic <T> T getByKey(Class<T> clazz, Key<T> key)
Datastorepublic <T> List<T> getByKeys(Class<T> clazz, Iterable<Key<T>> keys)
Datastorefind("_id in", ids)public <T> List<T> getByKeys(Iterable<Key<T>> keys)
Datastorefind("_id in", ids)public DBCollection getCollection(Class clazz)
getCollection in interface Datastoreclazz - the class to use for mappingpublic <T> long getCount(T entity)
DatastoreDBCollection)public <T> long getCount(Class<T> clazz)
DatastoreDBCollection)public <T> long getCount(Query<T> query)
Datastorequery.countAll()public DB getDB()
public WriteConcern getDefaultWriteConcern()
getDefaultWriteConcern in interface Datastorepublic void setDefaultWriteConcern(WriteConcern wc)
DatastoresetDefaultWriteConcern in interface Datastorewc - the default WriteConcern to be used by this Datastore@Deprecated public <T> Key<T> getKey(T entity)
DatastoreDBRefpublic MongoClient getMongo()
Datastorepublic QueryFactory getQueryFactory()
getQueryFactory in interface DatastoreQueryFactory.QueryFactorypublic void setQueryFactory(QueryFactory queryFactory)
DatastoreQueryFactory with the given value.setQueryFactory in interface DatastorequeryFactory - the QueryFactory to useQueryFactorypublic <T> MapreduceResults<T> mapReduce(MapreduceType type, Query query, String map, String reduce, String finalize, Map<String,Object> scopeFields, Class<T> outputType)
DatastoremapReduce in interface DatastoreT - The type of resulting datatype - MapreduceTypequery - 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 nulloutputType - The type of resulting data; inline is not working yetpublic <T> MapreduceResults<T> mapReduce(MapreduceType type, Query query, Class<T> outputType, MapReduceCommand baseCommand)
DatastoremapReduce in interface DatastoreT - The type of resulting datatype - MapreduceTypequery - 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 serverpublic <T> Key<T> merge(T entity)
Datastorepublic <T> Key<T> merge(T entity, WriteConcern wc)
Datastorepublic <T> Query<T> queryByExample(T ex)
DatastorequeryByExample in interface DatastoreT - the type of the entityex - the example entity to use when creating the querypublic <T> Iterable<Key<T>> save(Iterable<T> entities)
Datastorepublic <T> Iterable<Key<T>> save(Iterable<T> entities, WriteConcern wc)
Datastorepublic <T> Iterable<Key<T>> save(T... entities)
Datastorepublic <T> Key<T> save(T entity)
Datastorepublic <T> Key<T> save(T entity, WriteConcern wc)
Datastorepublic <T> UpdateResults update(T entity, UpdateOperations<T> operations)
Datastoreupdate in interface DatastoreT - the type of the entityentity - the entity to updateoperations - the update operations to performUpdateResultspublic <T> UpdateResults update(Key<T> key, UpdateOperations<T> operations)
Datastoreupdate in interface DatastoreT - the type of the entitykey - the key of entity to updateoperations - the update operations to performUpdateResultspublic <T> UpdateResults update(Query<T> query, UpdateOperations<T> operations)
Datastorepublic <T> UpdateResults update(Query<T> query, UpdateOperations<T> operations, boolean createIfMissing)
Datastoreupdate in interface DatastoreT - 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 querypublic <T> UpdateResults update(Query<T> query, UpdateOperations<T> operations, boolean createIfMissing, WriteConcern wc)
Datastoreupdate in interface DatastoreT - 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 usepublic <T> UpdateResults updateFirst(Query<T> query, UpdateOperations<T> operations)
DatastoreupdateFirst in interface DatastoreT - the type of the entityquery - the query used to match the document to updateoperations - the update operations to performpublic <T> UpdateResults updateFirst(Query<T> query, UpdateOperations<T> operations, boolean createIfMissing)
DatastoreupdateFirst in interface DatastoreT - 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 querypublic <T> UpdateResults updateFirst(Query<T> query, UpdateOperations<T> operations, boolean createIfMissing, WriteConcern wc)
DatastoreupdateFirst in interface DatastoreT - 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 usepublic <T> UpdateResults updateFirst(Query<T> query, T entity, boolean createIfMissing)
DatastoreupdateFirst in interface DatastoreT - 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 querypublic <T> Query<T> createQuery(String collection, Class<T> type)
createQuery in interface AdvancedDatastoreT - The type of the entitycollection - the collection to querytype - the class of objects to be returnedpublic <T> Query<T> createQuery(Class<T> clazz, DBObject q)
createQuery in interface AdvancedDatastoreT - The type of the entityclazz - the class of objects to be returnedq - the query which will be passed to a QueryFactorypublic <T> Query<T> createQuery(String collection, Class<T> type, DBObject q)
createQuery in interface AdvancedDatastoreT - The type of the entitycollection - the collection to querytype - the class of objects to be returnedq - the query which will be passed to a QueryFactorypublic <T,V> DBRef createRef(Class<T> clazz, V id)
AdvancedDatastorecreateRef in interface AdvancedDatastoreT - The type of the entityV - The type of the ID valueclazz - The type of the entityid - The ID value of the entitypublic <T> DBRef createRef(T entity)
AdvancedDatastorecreateRef in interface AdvancedDatastoreT - The type of the entityentity - the entity to create a DBRef forpublic <T> UpdateOperations<T> createUpdateOperations(Class<T> type, DBObject ops)
AdvancedDatastorecreateUpdateOperations in interface AdvancedDatastoreT - The type of the entitytype - The type of the entityops - The operations to performpublic <T,V> WriteResult delete(String kind, Class<T> clazz, V id)
AdvancedDatastoreid, from the collection with the name in the kind param.
Validates the id, checking it's the correct type for an ID for entities of type T. The entity type clazz is
used only for validation, not for filtering, therefore if you have entities of different types in the same collection (kind),
this method will delete any entity with the given id, regardless of its type.delete in interface AdvancedDatastoreT - the entity typeV - is the type of the ID, for example ObjectIdkind - the collection nameclazz - the Class of the entity to deleteid - the value of the IDpublic <T,V> WriteResult delete(String kind, Class<T> clazz, V id, WriteConcern wc)
AdvancedDatastoreid, from the collection with the name in the kind param.
Validates the id, checking it's the correct type for an ID for entities of type T. The entity type clazz is
used only for validation, not for filtering, therefore if you have entities of different types in the same collection (kind),
this method will delete any entity with the given id, regardless of its type.delete in interface AdvancedDatastoreT - the entity typeV - is the type of the ID, for example ObjectIdkind - the collection nameclazz - the Class of the entity to deleteid - the value of the IDwc - the WriteConcern for this operationpublic <T> void ensureIndex(String collection, Class<T> type, String fields)
AdvancedDatastoreensureIndex in interface AdvancedDatastoreT - the type to indexcollection - the collection to updatetype - the class from which to get the index definitionsfields - the fields to indexpublic <T> void ensureIndex(String collection, Class<T> clazz, String name, String fields, boolean unique, boolean dropDupsOnCreate)
AdvancedDatastoreensureIndex in interface AdvancedDatastoreT - the type to indexcollection - the collection to updateclazz - 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.public <T> void ensureIndexes(String collection, Class<T> clazz)
AdvancedDatastore@Indexed, @Indexes) on the given collection
name.ensureIndexes in interface AdvancedDatastoreT - the type to indexcollection - the collection to updateclazz - the class from which to get the index definitionspublic <T> void ensureIndexes(String collection, Class<T> clazz, boolean background)
AdvancedDatastore@Indexed, @Indexes) on the given collection
name, possibly in the backgroundensureIndexes in interface AdvancedDatastoreT - the type to indexcollection - the collection to updateclazz - 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.public Key<?> exists(Object entityOrKey, ReadPreference readPreference)
AdvancedDatastoreexists in interface AdvancedDatastoreentityOrKey - the value to check forreadPreference - Uses the supplied ReadPreference for the check. If readPreference is null the preference is taken from the
annotation or uses the default preference.Datastore.exists(Object)public <T> Query<T> find(String collection, Class<T> clazz)
AdvancedDatastorefind in interface AdvancedDatastoreT - the type to querycollection - the collection to query againstclazz - the class to use for mapping the resultspublic <T,V> Query<T> find(String collection, Class<T> clazz, String property, V value, int offset, int size)
AdvancedDatastorefind in interface AdvancedDatastoreT - the type to queryV - the type to filter valuecollection - the collection to query againstclazz - 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 returnpublic <T> T get(Class<T> clazz, DBRef ref)
AdvancedDatastoreget in interface AdvancedDatastoreT - the type to fetchclazz - the class to use for mappingref - the DBRef to use when queryingpublic <T,V> T get(String collection, Class<T> clazz, V id)
AdvancedDatastoreget in interface AdvancedDatastoreT - the type to fetchV - the type of the IDcollection - the collection to queryclazz - the class to use for mappingid - the ID to querypublic long getCount(String collection)
AdvancedDatastoregetCount in interface AdvancedDatastorecollection - the collection to countpublic DBDecoderFactory getDecoderFact()
AdvancedDatastoregetDecoderFact in interface AdvancedDatastoreDBDecoderFactorypublic void setDecoderFact(DBDecoderFactory fact)
AdvancedDatastoresetDecoderFact in interface AdvancedDatastorefact - the DBDecoderFactory to usepublic <T> Key<T> insert(String collection, T entity)
AdvancedDatastoreinsert in interface AdvancedDatastoreT - the type of the entitycollection - the collection to updateentity - the entity to insertpublic <T> Key<T> insert(T entity)
AdvancedDatastoreinsert in interface AdvancedDatastoreT - the type of the entityentity - the entity to insertpublic <T> Key<T> insert(T entity, WriteConcern wc)
AdvancedDatastoreinsert in interface AdvancedDatastoreT - the type of the entityentity - the entity to insertwc - the WriteConcern to use when insertingWriteConcernpublic <T> Iterable<Key<T>> insert(T... entities)
AdvancedDatastoreinsert in interface AdvancedDatastoreT - the type of the entityentities - the entities to insertpublic <T> Iterable<Key<T>> insert(Iterable<T> entities, WriteConcern wc)
AdvancedDatastoreinsert in interface AdvancedDatastoreT - the type of the entityentities - the entities to insertwc - the WriteConcern to use when insertingpublic <T> Iterable<Key<T>> insert(String collection, Iterable<T> entities)
AdvancedDatastoreinsert in interface AdvancedDatastoreT - the type of the entitycollection - the collection to updateentities - the entities to insertWriteConcernpublic <T> Iterable<Key<T>> insert(String collection, Iterable<T> entities, WriteConcern wc)
AdvancedDatastoreinsert in interface AdvancedDatastoreT - the type of the entitycollection - the collection to updateentities - the entities to insertwc - the WriteConcern to use when insertingWriteConcernpublic <T> Query<T> queryByExample(String collection, T ex)
AdvancedDatastorequeryByExample in interface AdvancedDatastoreT - the type of the entitycollection - the collection to queryex - the example entity to use when building the querypublic <T> Key<T> save(String collection, T entity)
AdvancedDatastoresave in interface AdvancedDatastoreT - the type of the entitycollection - the collection to updateentity - the entity to insertpublic <T> Key<T> save(String collection, T entity, WriteConcern wc)
AdvancedDatastoresave in interface AdvancedDatastoreT - the type of the entitycollection - the collection to updateentity - the entity to insertwc - the WriteConcern to use when insertingpublic <T,V> WriteResult delete(Class<T> clazz, V id, WriteConcern wc)
T - the type to deleteV - the type of the keyclazz - the clazz to query against when finding documents to deleteid - the ID to look forwc - the WriteConcern to use when deletingpublic <T,V> Query<T> find(String collection, Class<T> clazz, String property, V value, int offset, int size, boolean validate)
T - the type to queryV - the type to filter valuecollection - The collection use when queryingclazz - 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 returnvalidate - if true, validate the querypublic DBCollection getCollection(Object obj)
obj - the instance to use for looking up the collection mappingpublic Mapper getMapper()
public void setMapper(Mapper mapper)
mapper - the new Mapperpublic <T> Iterable<Key<T>> insert(Iterable<T> entities)
insert in interface AdvancedDatastoreT - the type of the entitiesentities - the entities to insertpublic <T> Key<T> insert(String collection, T entity, WriteConcern wc)
T - the type of the entitiescollection - the collection to query againstentity - the entity to insertwc - the WriteConcern to use when deletingprotected <T> void ensureIndex(Class<T> clazz, String name, BasicDBObject fields, boolean unique, boolean dropDupsOnCreate, boolean background, boolean sparse, int expireAfterSeconds)
protected void ensureIndex(DBCollection dbColl, String name, BasicDBObject fields, boolean unique, boolean dropDupsOnCreate, boolean background, boolean sparse, int expireAfterSeconds)
protected void ensureIndex(MappedClass mc, DBCollection dbColl, Field[] fields, IndexOptions options, boolean background, List<MappedClass> parentMCs, List<MappedField> parentMFs)
protected void ensureIndex(DBCollection dbColl, DBObject keys, DBObject options)
protected void ensureIndexes(MappedClass mc, boolean background, List<MappedClass> parentMCs, List<MappedField> parentMFs)
protected void ensureIndexes(String collName, MappedClass mc, boolean background)
protected void ensureIndexes(DBCollection dbColl, MappedClass mc, boolean background, List<MappedClass> parentMCs, List<MappedField> parentMFs)
protected void ensureIndexes(MappedClass mc, boolean background)
protected DBCollection getCollection(String kind)
@Deprecated protected Object getId(Object entity)
protected <T> Key<T> insert(DBCollection dbColl, T entity, WriteConcern wc)
protected <T> Key<T> save(DBCollection dbColl, T entity, WriteConcern wc)
protected <T> WriteResult tryVersionedUpdate(DBCollection dbColl, T entity, DBObject dbObj, Object idValue, WriteConcern wc, MappedClass mc)