Package dev.morphia
Interface Datastore
-
- All Known Subinterfaces:
AdvancedDatastore
,MorphiaSession
public interface Datastore
Datastore interface to get/delete/save objects
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description <T> Aggregation<T>
aggregate(Class<T> source)
Returns a new query bound to the kind (a specificMongoCollection
)Aggregation<Document>
aggregate(String source)
Returns a new query bound to the kind (a specificMongoCollection
)AggregationPipeline
createAggregation(Class<?> source)
Deprecated, for removal: This API element is subject to removal in a future version.useaggregate(Class)
insteaddefault <T> Query<T>
createQuery(Class<T> type)
Deprecated, for removal: This API element is subject to removal in a future version.usefind(Class)
default <T> UpdateOperations<T>
createUpdateOperations(Class<T> clazz)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.update(UpdateOperator, UpdateOperator...)
insteaddefault <T> DeleteResult
delete(Query<T> query)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.delete()
insteaddefault <T> DeleteResult
delete(Query<T> query, DeleteOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.delete(DeleteOptions)
instead<T> DeleteResult
delete(T entity)
Deletes the given entity (by @Id)<T> DeleteResult
delete(T entity, DeleteOptions options)
Deletes the given entity (by @Id), with the WriteConcernvoid
enableDocumentValidation()
Deprecated, for removal: This API element is subject to removal in a future version.this is handled by the config file and should not be called directlyvoid
ensureCaps()
Deprecated, for removal: This API element is subject to removal in a future version.this is handled by the config file and should not be called directlyvoid
ensureIndexes()
Deprecated, for removal: This API element is subject to removal in a future version.this is configured by the config file and doesn't need to be called directly<T> Query<T>
find(Class<T> type)
Find instances of a type<T> Query<T>
find(Class<T> type, Document nativeQuery)
Find instances of a type using a native query.<T> Query<T>
find(String collection)
Find all instances by type in a different collection than what is mapped on the class given.<T> Query<T>
find(String collection, Class<T> type)
Deprecated, for removal: This API element is subject to removal in a future version.useFindOptions.collection(String)
insteaddefault <T> T
findAndDelete(Query<T> query)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.findAndDelete()
insteaddefault <T> T
findAndDelete(Query<T> query, FindAndModifyOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.findAndDelete(FindAndDeleteOptions)
insteaddefault <T> T
findAndModify(Query<T> query, UpdateOperations<T> operations)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.modify(UpdateOperations)
insteaddefault <T> T
findAndModify(Query<T> query, UpdateOperations<T> operations, FindAndModifyOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.modify(UpdateOperations)
insteadCodecRegistry
getCodecRegistry()
<T> MongoCollection<T>
getCollection(Class<T> type)
MongoDatabase
getDatabase()
String
getLoggedQuery(FindOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.UseQuery.getLoggedQuery()
insteadMapper
getMapper()
default <T> void
insert(List<T> entities)
Inserts a List of entities in to the mapped collection.<T> void
insert(List<T> entities, InsertManyOptions options)
Inserts entities in to the mapped collection.default <T> void
insert(T entity)
Inserts an entity in to the mapped collection.<T> void
insert(T entity, InsertOneOptions options)
Inserts an entity in to the mapped collection.<T> 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.default <T> void
merge(T entity, WriteConcern wc)
Deprecated, for removal: This API element is subject to removal in a future version.usemerge(Object, InsertOneOptions)
instead<T> T
merge(T entity, InsertOneOptions options)
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> void
refresh(T entity)
Refreshes an existing entity to its current state in the database.default <T> List<T>
replace(List<T> entities)
Replaces a list of documents in the database<T> List<T>
replace(List<T> entities, ReplaceOptions options)
Replaces a list of documents in the databasedefault <T> T
replace(T entity)
Replaces a document in the database<T> T
replace(T entity, ReplaceOptions options)
Replaces a document in the databasedefault <T> List<T>
save(Iterable<T> entities)
Deprecated, for removal: This API element is subject to removal in a future version.usesave(List)
insteaddefault <T> List<T>
save(Iterable<T> entities, InsertOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.usesave(List, InsertManyOptions)
insteaddefault <T> List<T>
save(List<T> entities)
Saves the entities (Objects) and updates the @Id field<T> List<T>
save(List<T> entities, InsertManyOptions options)
Saves the entities (Objects) and updates the @Id fielddefault <T> T
save(T entity)
Saves an entity (Object) and updates the @Id field<T> T
save(T entity, InsertOneOptions options)
Saves an entity (Object) and updates the @Id fielddefault <T> T
save(T entity, InsertOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.usesave(Object, InsertOneOptions)
insteadvoid
shardCollections()
Shards any collections with sharding definitions.MorphiaSession
startSession()
Starts a new session on the server.MorphiaSession
startSession(ClientSessionOptions options)
Starts a new session on the server.default <T> UpdateResult
update(Query<T> query, UpdateOperations<T> operations)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.update(UpdateOperator, UpdateOperator...)
instead.default <T> UpdateResult
update(Query<T> query, UpdateOperations<T> operations, UpdateOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.update(UpdateOperator, UpdateOperator...)
instead<T> T
withTransaction(ClientSessionOptions options, MorphiaTransaction<T> transaction)
<T> T
withTransaction(MorphiaTransaction<T> transaction)
-
-
-
Method Detail
-
aggregate
Aggregation<Document> aggregate(String source)
Returns a new query bound to the kind (a specificMongoCollection
)- Parameters:
source
- The collection aggregation against- Returns:
- the aggregation pipeline
- Since:
- 2.0
-
aggregate
<T> Aggregation<T> aggregate(Class<T> source)
Returns a new query bound to the kind (a specificMongoCollection
)- Type Parameters:
T
- the source type- Parameters:
source
- The class to create aggregation against- Returns:
- the aggregation pipeline
- Since:
- 2.0
-
createAggregation
@Deprecated(since="2.0", forRemoval=true) AggregationPipeline createAggregation(Class<?> source)
Deprecated, for removal: This API element is subject to removal in a future version.useaggregate(Class)
insteadReturns a new query bound to the kind (a specificMongoCollection
)- Parameters:
source
- The class to create aggregation against- Returns:
- the aggregation pipeline
-
createQuery
@Deprecated(since="2.0", forRemoval=true) default <T> Query<T> createQuery(Class<T> type)
Deprecated, for removal: This API element is subject to removal in a future version.usefind(Class)
Returns a new query bound to the collection (a specificMongoCollection
)- Type Parameters:
T
- the type of the query- Parameters:
type
- The collection to query- Returns:
- the query
-
createUpdateOperations
@Deprecated(since="2.0", forRemoval=true) default <T> UpdateOperations<T> createUpdateOperations(Class<T> clazz)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.update(UpdateOperator, UpdateOperator...)
insteadThe builder for all update operations- Type Parameters:
T
- the type to update- Parameters:
clazz
- the type to update- Returns:
- the new UpdateOperations instance
-
delete
@Deprecated(since="2.0", forRemoval=true) default <T> DeleteResult delete(Query<T> query)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.delete()
insteadDeletes entities based on the query- Type Parameters:
T
- the type to delete- Parameters:
query
- the query to use when finding documents to delete- Returns:
- results of the delete
-
delete
@Deprecated(since="2.0", forRemoval=true) default <T> DeleteResult delete(Query<T> query, DeleteOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.delete(DeleteOptions)
insteadDeletes entities based on the query- Type Parameters:
T
- the type to delete- Parameters:
query
- the query to use when finding documents to deleteoptions
- the options to apply to the delete- Returns:
- results of the delete
- Since:
- 1.3
-
delete
<T> DeleteResult delete(T entity)
Deletes the given entity (by @Id)- Type Parameters:
T
- the type to delete- Parameters:
entity
- the entity to delete- Returns:
- results of the delete
-
delete
<T> DeleteResult delete(T entity, DeleteOptions options)
Deletes the given entity (by @Id), with the WriteConcern- Type Parameters:
T
- the type to delete- Parameters:
entity
- the entity to deleteoptions
- the options to use when deleting- Returns:
- results of the delete
- Since:
- 1.3
-
enableDocumentValidation
@Deprecated(since="2.4.0", forRemoval=true) void enableDocumentValidation()
Deprecated, for removal: This API element is subject to removal in a future version.this is handled by the config file and should not be called directlyProcess anyValidation
annotations for document validation.- Since:
- 1.3
- MongoDB documentation
- core/document-validation/
-
ensureCaps
@Deprecated(since="2.4.0", forRemoval=true) void ensureCaps()
Deprecated, for removal: This API element is subject to removal in a future version.this is handled by the config file and should not be called directlyensure capped collections forEntity
(s)
-
ensureIndexes
@Deprecated(since="2.4.0", forRemoval=true) void ensureIndexes()
Deprecated, for removal: This API element is subject to removal in a future version.this is configured by the config file and doesn't need to be called directlyEnsures (creating if necessary) the indexes found during class mapping
-
find
<T> Query<T> find(Class<T> type)
Find instances of a type- Type Parameters:
T
- the type to query- Parameters:
type
- the class to use for mapping the results- Returns:
- the query
-
find
@MorphiaExperimental <T> Query<T> find(Class<T> type, Document nativeQuery)
Find instances of a type using a native query. This method is intended as an aid when copying queries from external sources such as the shell or Compass whose structure is already in json form.- Type Parameters:
T
- the type to query- Parameters:
type
- the class to use for mapping the resultsnativeQuery
- the full query structure to use for this Query- Returns:
- the query
- Since:
- 2.3
Developer note.This is an experimental item. Its function and presence are subject to change. Feedback on features and usability extremely welcome.
-
find
@Deprecated(forRemoval=true, since="2.3") <T> Query<T> find(String collection, Class<T> type)
Deprecated, for removal: This API element is subject to removal in a future version.useFindOptions.collection(String)
insteadFind all instances by type from an alternate collection- Type Parameters:
T
- the type to query- Parameters:
collection
- the actual collection to query. This overrides any mapped on collection on type.type
- the class to use for mapping the results- Returns:
- the query
-
find
@MorphiaInternal <T> Query<T> find(String collection)
Find all instances by type in a different collection than what is mapped on the class given.- Type Parameters:
T
- the type to query- Parameters:
collection
- the collection to query against- Returns:
- the query
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
findAndDelete
@Nullable @Deprecated(since="2.0", forRemoval=true) default <T> T findAndDelete(Query<T> query)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.findAndDelete()
insteadDeletes the given entities based on the query (first item only).- Type Parameters:
T
- the type to query- Parameters:
query
- the query to use when finding entities to delete- Returns:
- the deleted Entity
-
findAndDelete
@Nullable @Deprecated(since="2.0", forRemoval=true) default <T> T findAndDelete(Query<T> query, FindAndModifyOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.findAndDelete(FindAndDeleteOptions)
insteadDeletes the given entities based on the query (first item only).- Type Parameters:
T
- the type to query- Parameters:
query
- the query to use when finding entities to deleteoptions
- the options to apply to the delete- Returns:
- the deleted Entity
- Since:
- 1.3
-
findAndModify
@Nullable @Deprecated(since="2.0", forRemoval=true) default <T> T findAndModify(Query<T> query, UpdateOperations<T> operations, FindAndModifyOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.modify(UpdateOperations)
insteadFind the first Entity from the Query, and modify it.- Type Parameters:
T
- the type to query- Parameters:
query
- the query to use when finding entities to updateoperations
- the updates to apply to the matched documentsoptions
- the options to apply- Returns:
- The modified Entity (the result of the update)
-
findAndModify
@Nullable @Deprecated(since="2.0", forRemoval=true) default <T> T findAndModify(Query<T> query, UpdateOperations<T> operations)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.modify(UpdateOperations)
insteadFind the first Entity from the Query, and modify it.- Type Parameters:
T
- the type to query- Parameters:
query
- the query to use when finding entities to updateoperations
- the updates to apply to the matched documents- Returns:
- The modified Entity (the result of the update)
-
getCodecRegistry
@MorphiaInternal CodecRegistry getCodecRegistry()
- Returns:
- the codec registry
- Since:
- 2.3
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
getCollection
@MorphiaInternal <T> MongoCollection<T> getCollection(Class<T> type)
- Type Parameters:
T
- the class type- Parameters:
type
- the type look up- Returns:
- the collection mapped for this class
- Since:
- 2.3
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
getDatabase
@MorphiaInternal MongoDatabase getDatabase()
- Returns:
- the MongoDatabase used by this DataStore
- Since:
- 1.5
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
getLoggedQuery
@MorphiaInternal @Deprecated(forRemoval=true) String getLoggedQuery(FindOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.UseQuery.getLoggedQuery()
instead- Parameters:
options
- the options used when requesting logging- Returns:
- the logged query
- Since:
- 2.0
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
getMapper
@MorphiaInternal Mapper getMapper()
- Returns:
- the Mapper used by this Datastore
- Since:
- 1.5
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
insert
default <T> void insert(T entity)
Inserts an entity in to the mapped collection.- Type Parameters:
T
- the type of the entity- Parameters:
entity
- the entity to insert
-
insert
<T> void insert(T entity, InsertOneOptions options)
Inserts an entity in to the mapped collection.- Type Parameters:
T
- the type of the entity- Parameters:
entity
- the entity to insertoptions
- the options to apply to the insert operation- Since:
- 2.0
-
insert
default <T> void insert(List<T> entities)
Inserts a List of entities in to the mapped collection.- Type Parameters:
T
- the type of the entity- Parameters:
entities
- the entities to insert- Since:
- 2.0
-
insert
<T> void insert(List<T> entities, InsertManyOptions options)
Inserts entities in to the mapped collection.- Type Parameters:
T
- the type of the entity- Parameters:
entities
- the entities to insertoptions
- the options to apply to the insert operation- Since:
- 2.0
-
merge
<T> 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.- Type Parameters:
T
- the type of the entity- Parameters:
entity
- the entity to merge back in to the database- Returns:
- the new merged entity. NOTE: this is a database fetch.
-
merge
<T> T merge(T entity, InsertOneOptions options)
Work as if you did an update with each field in the entity doing a $set; Only at the top level of the entity.- Type Parameters:
T
- the type of the entity- Parameters:
entity
- the entity to merge back in to the databaseoptions
- the options to apply- Returns:
- the new merged entity. NOTE: this is a database fetch.
- Since:
- 2.0
-
merge
@Deprecated(since="2.0", forRemoval=true) default <T> void merge(T entity, WriteConcern wc)
Deprecated, for removal: This API element is subject to removal in a future version.usemerge(Object, InsertOneOptions)
insteadWork as if you did an update with each field in the entity doing a $set; Only at the top level of the entity.- Type Parameters:
T
- the type of the entity- Parameters:
entity
- the entity to merge back in to the databasewc
- the WriteConcern to use
-
queryByExample
<T> Query<T> queryByExample(T example)
Returns a new query based on the example object- Type Parameters:
T
- the type of the entity- Parameters:
example
- the example entity to use when creating the query- Returns:
- the query
-
refresh
<T> void refresh(T entity)
Refreshes an existing entity to its current state in the database. Essentially, any existing mapped state is replaced by the latest persisted state while preserving the entity's reference and object identity.- Type Parameters:
T
- the entity type- Parameters:
entity
- the entity to refresh- Since:
- 2.0
-
replace
default <T> T replace(T entity)
Replaces a document in the database- Type Parameters:
T
- the type of the entity- Parameters:
entity
- the entity to replace- Returns:
- the replaced entity
- Since:
- 2.3
-
replace
<T> T replace(T entity, ReplaceOptions options)
Replaces a document in the database- Type Parameters:
T
- the type of the entity- Parameters:
entity
- the entity to replaceoptions
- the options to apply to the replace operation- Returns:
- the replaced entity
- Since:
- 2.3
-
replace
default <T> List<T> replace(List<T> entities)
Replaces a list of documents in the database- Type Parameters:
T
- the type of the entity- Parameters:
entities
- the entities to replace- Returns:
- the saved entities
- Since:
- 2.3
-
replace
<T> List<T> replace(List<T> entities, ReplaceOptions options)
Replaces a list of documents in the database- Type Parameters:
T
- the type of the entity- Parameters:
entities
- the entities to replaceoptions
- the options to apply to the replace operation- Returns:
- the saved entities
- Since:
- 2.3
-
save
@Deprecated(since="2.0", forRemoval=true) default <T> List<T> save(Iterable<T> entities)
Deprecated, for removal: This API element is subject to removal in a future version.usesave(List)
insteadSaves the entities (Objects) and updates the @Id field- Type Parameters:
T
- the type of the entity- Parameters:
entities
- the entities to save- Returns:
- the list of updated entities
-
save
default <T> List<T> save(List<T> entities)
Saves the entities (Objects) and updates the @Id field- Type Parameters:
T
- the type of the entity- Parameters:
entities
- the entities to save- Returns:
- the saved entities
-
save
<T> List<T> save(List<T> entities, InsertManyOptions options)
Saves the entities (Objects) and updates the @Id field- Type Parameters:
T
- the type of the entity- Parameters:
entities
- the entities to saveoptions
- the options to apply to the save operation- Returns:
- the saved entities
- Since:
- 2.0
-
save
@Deprecated(since="2.0", forRemoval=true) default <T> List<T> save(Iterable<T> entities, InsertOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.usesave(List, InsertManyOptions)
insteadSaves the entities (Objects) and updates the @Id field- Type Parameters:
T
- the type of the entity- Parameters:
entities
- the entities to saveoptions
- the options to apply to the save operation- Returns:
- the saved entities
-
save
default <T> T save(T entity)
Saves an entity (Object) and updates the @Id field- Type Parameters:
T
- the type of the entity- Parameters:
entity
- the entity to save- Returns:
- the saved entity
-
save
@Deprecated(since="2.0", forRemoval=true) default <T> T save(T entity, InsertOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.usesave(Object, InsertOneOptions)
insteadSaves an entity (Object) and updates the @Id field- Type Parameters:
T
- the type of the entity- Parameters:
entity
- the entity to saveoptions
- the options to apply to the save operation- Returns:
- the saved entity
-
save
<T> T save(T entity, InsertOneOptions options)
Saves an entity (Object) and updates the @Id field- Type Parameters:
T
- the type of the entity- Parameters:
entity
- the entity to saveoptions
- the options to apply to the save operation- Returns:
- the saved entity
-
shardCollections
@MorphiaExperimental void shardCollections()
Shards any collections with sharding definitions.- Since:
- 2.3
Developer note.This is an experimental item. Its function and presence are subject to change. Feedback on features and usability extremely welcome.
-
startSession
MorphiaSession startSession()
Starts a new session on the server.- Returns:
- the new session reference
- Since:
- 2.0
-
startSession
MorphiaSession startSession(ClientSessionOptions options)
Starts a new session on the server.- Parameters:
options
- the options to apply- Returns:
- the new session reference
- Since:
- 2.0
-
update
@Deprecated(since="2.0", forRemoval=true) default <T> UpdateResult update(Query<T> query, UpdateOperations<T> operations, UpdateOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.update(UpdateOperator, UpdateOperator...)
insteadUpdates all entities found with the operations; this is an atomic operation per entity- Type Parameters:
T
- the type of the entity- Parameters:
query
- the query used to match the documents to updateoperations
- the update operations to performoptions
- the options to apply to the update- Returns:
- the results of the updates
- Since:
- 1.3
-
update
@Deprecated(since="2.0", forRemoval=true) default <T> UpdateResult update(Query<T> query, UpdateOperations<T> operations)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.update(UpdateOperator, UpdateOperator...)
instead. Please note the default has changed from multi- to single-document updates.Updates all entities found with the operations; this is an atomic operation per entity- Type Parameters:
T
- the type of the entity- Parameters:
query
- the query used to match the documents to updateoperations
- the update operations to perform- Returns:
- the results of the updates
-
withTransaction
@Nullable <T> T withTransaction(MorphiaTransaction<T> transaction)
- Type Parameters:
T
- the return type- Parameters:
transaction
- the transaction wrapper- Returns:
- the return value
- Since:
- 2.0
-
withTransaction
@Nullable <T> T withTransaction(ClientSessionOptions options, MorphiaTransaction<T> transaction)
- Type Parameters:
T
- the return type- Parameters:
options
- the session options to applytransaction
- the transaction wrapper- Returns:
- the return value
- Since:
- 2.0
-
-