Package dev.morphia
Interface Datastore
-
- All Known Subinterfaces:
AdvancedDatastore
,MorphiaSession
- All Known Implementing Classes:
BaseMorphiaSession
,DatastoreImpl
,MorphiaSessionImpl
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 AggregationPipeline
createAggregation(Class source)
Returns a new query bound to the kind (a specificDBCollection
)default <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()
insteaddefault <T> com.mongodb.client.result.DeleteResult
delete(Query<T> query)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.remove()
insteaddefault <T> com.mongodb.client.result.DeleteResult
delete(Query<T> query, DeleteOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.remove(DeleteOptions)
instead<T> com.mongodb.client.result.DeleteResult
delete(T entity)
Deletes the given entity (by @Id)<T> com.mongodb.client.result.DeleteResult
delete(T entity, DeleteOptions options)
Deletes the given entity (by @Id), with the WriteConcernvoid
enableDocumentValidation()
Process anyValidation
annotations for document validation.void
ensureCaps()
ensure capped collections forEntity
(s)void
ensureIndexes()
Ensures (creating if necessary) the indexes found during class mapping<T> void
ensureIndexes(Class<T> clazz)
Ensures (creating if necessary) the indexes found during class mapping<T> Query<T>
find(Class<T> clazz)
Find all instances by typedefault <T> T
findAndDelete(Query<T> query)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.delete()
insteaddefault <T> T
findAndDelete(Query<T> query, FindAndModifyOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.delete(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()
insteaddefault <T,V>
Query<T>get(Class<T> clazz, Iterable<V> ids)
Deprecated.useQuery
instead.default <T> T
get(T entity)
Deprecated.useQuery
instead<T> T
getByKey(Class<T> clazz, Key<T> key)
Deprecated.use aQuery
instead<T> List<T>
getByKeys(Class<T> clazz, Iterable<Key<T>> keys)
Deprecated.use aQuery
instead<T> List<T>
getByKeys(Iterable<Key<T>> keys)
Deprecated.use aQuery
instead<T> com.mongodb.client.MongoCollection<T>
getCollection(Class<T> clazz)
com.mongodb.client.MongoDatabase
getDatabase()
<T> Key<T>
getKey(T entity)
Creates a (type-safe) reference to the entity; if stored this will become aDBRef
Mapper
getMapper()
QueryFactory
getQueryFactory()
default com.mongodb.client.ClientSession
getSession()
Returns the session this datastore is attached to or null if none is attached.<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> void
merge(T entity, com.mongodb.WriteConcern wc)
Deprecated, for removal: This API element is subject to removal in a future version.<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 objectdefault <T> void
save(Iterable<T> entities)
Deprecated, for removal: This API element is subject to removal in a future version.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)
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 field<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.use#save(T, InsertOneOptions)
insteadvoid
setQueryFactory(QueryFactory queryFactory)
Replaces the currentQueryFactory
with the given value.MorphiaSession
startSession()
Starts a new session on the server.MorphiaSession
startSession(com.mongodb.ClientSessionOptions options)
Starts a new session on the server.default <T> com.mongodb.client.result.UpdateResult
update(Query<T> query, UpdateOperations<T> operations)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.update()
instead.default <T> com.mongodb.client.result.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()
instead<T> T
withTransaction(com.mongodb.ClientSessionOptions options, MorphiaTransaction<T> transaction)
<T> T
withTransaction(MorphiaTransaction<T> transaction)
-
-
-
Method Detail
-
createAggregation
AggregationPipeline createAggregation(Class source)
Returns a new query bound to the kind (a specificDBCollection
)- 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 specificDBCollection
)- Type Parameters:
T
- the type of the query- Parameters:
type
- The collection to query- Returns:
- the query
-
find
<T> Query<T> find(Class<T> clazz)
Find all instances by type- Type Parameters:
T
- the type to query- Parameters:
clazz
- the class to use for mapping the results- 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()
insteadThe builder for all update operations- Type Parameters:
T
- the type to update- Parameters:
clazz
- the type to update- Returns:
- the new UpdateOperations instance
-
getMapper
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.
-
delete
@Deprecated(since="2.0", forRemoval=true) default <T> com.mongodb.client.result.DeleteResult delete(Query<T> query)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.remove()
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> com.mongodb.client.result.DeleteResult delete(Query<T> query, DeleteOptions options)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.remove(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> com.mongodb.client.result.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> com.mongodb.client.result.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
void enableDocumentValidation()
Process anyValidation
annotations for document validation.- Since:
- 1.3
- MongoDB documentation
- core/document-validation/
-
ensureCaps
void ensureCaps()
ensure capped collections forEntity
(s)
-
ensureIndexes
void ensureIndexes()
Ensures (creating if necessary) the indexes found during class mapping
-
ensureIndexes
<T> void ensureIndexes(Class<T> clazz)
Ensures (creating if necessary) the indexes found during class mapping
-
findAndDelete
@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.delete()
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
@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.delete(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
@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()
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)
-
get
@Deprecated default <T,V> Query<T> get(Class<T> clazz, Iterable<V> ids)
Deprecated.useQuery
instead.Find the given entities (by id); shorthand forfind("_id in", ids)
- Type Parameters:
T
- the type to fetchV
- the type of the ID- Parameters:
clazz
- the class to use for mappingids
- the IDs to query- Returns:
- the query to find the entities
Developer note. Inline this method to update to the new usage
-
get
@Deprecated default <T> T get(T entity)
Deprecated.useQuery
insteadFind the given entity (by collectionName/id); think of this as refresh- Type Parameters:
T
- the type to fetch- Parameters:
entity
- The entity to search for- Returns:
- the matched entity. may be null.
Developer note. Inline this method to update to the new usage
-
getByKey
@Deprecated <T> T getByKey(Class<T> clazz, Key<T> key)
Deprecated.use aQuery
insteadFind the given entity (by collectionName/id);- Type Parameters:
T
- the type to fetch- Parameters:
clazz
- the class to use for mappingkey
- the key search with- Returns:
- the matched entity. may be null.
-
getByKeys
@Deprecated <T> List<T> getByKeys(Class<T> clazz, Iterable<Key<T>> keys)
Deprecated.use aQuery
insteadFind the given entities (by id), verifying they are of the correct type; shorthand forfind("_id in", ids)
- Type Parameters:
T
- the type to fetch- Parameters:
clazz
- the class to use for mappingkeys
- the keys to search with- Returns:
- the matched entities. may be null.
-
getByKeys
@Deprecated <T> List<T> getByKeys(Iterable<Key<T>> keys)
Deprecated.use aQuery
insteadFind the given entities (by id); shorthand forfind("_id in", ids)
- Type Parameters:
T
- the type to fetch- Parameters:
keys
- the keys to search with- Returns:
- the matched entities. may be null.
-
getCollection
<T> com.mongodb.client.MongoCollection<T> getCollection(Class<T> clazz)
- Type Parameters:
T
- the type of the collection- Parameters:
clazz
- the class to use for mapping- Returns:
- the mapped collection for the collection
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
getDatabase
com.mongodb.client.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.
-
getKey
<T> Key<T> getKey(T entity)
Creates a (type-safe) reference to the entity; if stored this will become aDBRef
- Type Parameters:
T
- the type of the entity- Parameters:
entity
- the entity whose key is to be returned- Returns:
- the Key
-
getQueryFactory
QueryFactory getQueryFactory()
- Returns:
- the current
QueryFactory
. - See Also:
QueryFactory
-
setQueryFactory
void setQueryFactory(QueryFactory queryFactory)
Replaces the currentQueryFactory
with the given value.- Parameters:
queryFactory
- the QueryFactory to use- See Also:
QueryFactory
-
getSession
default com.mongodb.client.ClientSession getSession()
Returns the session this datastore is attached to or null if none is attached.- Returns:
- the session
- Since:
- 2.0
Developer note.This is an experimental item. Its function and presence are subject to change. Feedback on features and usability extremely welcome.
-
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) <T> void merge(T entity, com.mongodb.WriteConcern wc)
Deprecated, for removal: This API element is subject to removal in a future version.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 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
-
save
@Deprecated(since="2.0", forRemoval=true) default <T> void save(Iterable<T> entities)
Deprecated, for removal: This API element is subject to removal in a future version.Saves the entities (Objects) and updates the @Id field- Type Parameters:
T
- the type of the entity- Parameters:
entities
- the entities to save
-
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
<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.use#save(T, 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
-
startSession
MorphiaSession startSession()
Starts a new session on the server.- Returns:
- the new session reference
- Since:
- 2.0
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(com.mongodb.ClientSessionOptions options)
Starts a new session on the server.- Parameters:
options
- the options to apply- Returns:
- the new session reference
- Since:
- 2.0
Developer note.This is an experimental item. Its function and presence are subject to change. Feedback on features and usability extremely welcome.
-
update
@Deprecated(since="2.0", forRemoval=true) default <T> com.mongodb.client.result.UpdateResult update(Query<T> query, UpdateOperations<T> operations)
Deprecated, for removal: This API element is subject to removal in a future version.useQuery.update()
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
-
update
@Deprecated(since="2.0", forRemoval=true) default <T> com.mongodb.client.result.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()
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
-
withTransaction
<T> T withTransaction(MorphiaTransaction<T> transaction)
- Type Parameters:
T
- the return type- Parameters:
transaction
- the transaction wrapper- Returns:
- the return value
- Since:
- 2.0
Developer note.This is an experimental item. Its function and presence are subject to change. Feedback on features and usability extremely welcome.
-
withTransaction
<T> T withTransaction(com.mongodb.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
Developer note.This is an experimental item. Its function and presence are subject to change. Feedback on features and usability extremely welcome.
-
-