Package dev.morphia
Interface Datastore
- All Known Subinterfaces:
MorphiaSession
public interface Datastore
Datastore interface to get/delete/save objects
-
Method Summary
Modifier and TypeMethodDescription<T> Aggregation<T>
Returns a new query bound to the kind (a specificMongoCollection
)Returns a new query bound to the kind (a specificMongoCollection
)<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 WriteConcern<T> Query<T>
Find instances of a type<T> Query<T>
Find instances of a type using a native query.default <T> void
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.<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>
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>
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 fieldStarts a new session on the server.startSession
(ClientSessionOptions options) Starts a new session on the server.<T> T
withTransaction
(ClientSessionOptions options, MorphiaTransaction<T> transaction) <T> T
withTransaction
(MorphiaTransaction<T> transaction)
-
Method Details
-
aggregate
Returns a new query bound to the kind (a specificMongoCollection
)- Parameters:
source
- The collection aggregation against- Returns:
- the aggregation pipeline
- Since:
- 2.0
-
aggregate
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
-
delete
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
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
-
find
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
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. -
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
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
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
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
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
-
queryByExample
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
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
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
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
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
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
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
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
-
startSession
MorphiaSession startSession()Starts a new session on the server.- Returns:
- the new session reference
- Since:
- 2.0
-
startSession
Starts a new session on the server.- Parameters:
options
- the options to apply- Returns:
- the new session reference
- Since:
- 2.0
-
withTransaction
- Type Parameters:
T
- the return type- Parameters:
transaction
- the transaction wrapper- Returns:
- the return value
- Since:
- 2.0
-
withTransaction
- Type Parameters:
T
- the return type- Parameters:
options
- the session options to applytransaction
- the transaction wrapper- Returns:
- the return value
- Since:
- 2.0
-