Class VitamMongoRepository
- java.lang.Object
-
- fr.gouv.vitam.common.database.api.impl.VitamMongoRepository
-
- All Implemented Interfaces:
VitamRepository
public class VitamMongoRepository extends java.lang.Object implements VitamRepository
-
-
Constructor Summary
Constructors Constructor Description VitamMongoRepository(com.mongodb.client.MongoCollection<org.bson.Document> collection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
count()
Count occurence of documentslong
count(org.bson.conversions.Bson filter)
Count occurence of documentsvoid
delete(java.util.List<java.lang.String> ids, int tenant)
Deleted all documents by idscom.mongodb.client.FindIterable<org.bson.Document>
findByFieldsDocuments(java.util.Map<java.lang.String,java.lang.String> fields, int mongoBatchSize, java.lang.Integer tenant)
Return iterable over document for the given collection for a specific tenant and fieldsjava.util.Optional<org.bson.Document>
findByIdentifier(java.lang.String identifier)
Find by identifier for collections cross tenantjava.util.Optional<org.bson.Document>
findByIdentifierAndTenant(java.lang.String identifier, java.lang.Integer tenant)
find by identifier for all tenantcom.mongodb.client.FindIterable<org.bson.Document>
findDocuments(int mongoBatchSize)
Return iterable over document for the given collectioncom.mongodb.client.FindIterable<org.bson.Document>
findDocuments(int mongoBatchSize, java.lang.Integer tenant)
Return iterable over document for the given collection for a specific tenantcom.mongodb.client.FindIterable<org.bson.Document>
findDocuments(java.util.Collection<java.lang.String> ids, org.bson.conversions.Bson projection)
Find collection of document by there id and return only projection fieldscom.mongodb.client.FindIterable<org.bson.Document>
findDocuments(org.bson.conversions.Bson query, int mongoBatchSize)
Return iterable over document for the given collectionjava.util.Optional<org.bson.Document>
getByID(java.lang.String id, java.lang.Integer tenant)
Get vitam document by idlong
purge()
Be careful when using this method Remove by tenant for collection cross-tenantlong
purge(java.lang.Integer tenant)
Be careful when using this method Remove by tenant for collection multi-tenantvoid
remove(java.lang.String id, java.lang.Integer tenant)
Remove document by idlong
remove(org.bson.conversions.Bson query)
Be careful when using this method Remove by queryvoid
removeByNameAndTenant(java.lang.String name, java.lang.Integer tenant)
Be careful when using this method Remove collection by name and tenantvoid
save(java.util.List<org.bson.Document> documents)
Save a list of vitam documentsvoid
save(org.bson.Document document)
Save vitam documentvoid
saveOrUpdate(java.util.List<org.bson.Document> documents)
Save or update a list of vitam documentsVitamRepositoryStatus
saveOrUpdate(org.bson.Document document)
Save or updatevitam documentvoid
update(java.util.List<com.mongodb.client.model.WriteModel<org.bson.Document>> queries)
Used to execute a bulk update If document exists then update If document do not exists then create document throw Duplicate key exception if document exists by _id but not exists by filter in the update one model
-
-
-
Method Detail
-
save
public void save(org.bson.Document document) throws DatabaseException
Description copied from interface:VitamRepository
Save vitam document- Specified by:
save
in interfaceVitamRepository
- Parameters:
document
- the document to be saved- Throws:
DatabaseException
- in case error with database occurs
-
saveOrUpdate
public VitamRepositoryStatus saveOrUpdate(org.bson.Document document) throws DatabaseException
Description copied from interface:VitamRepository
Save or updatevitam document- Specified by:
saveOrUpdate
in interfaceVitamRepository
- Parameters:
document
- the document to be saved- Returns:
- status CREATED or UPDATED
- Throws:
DatabaseException
- in case error with database occurs
-
save
public void save(java.util.List<org.bson.Document> documents) throws DatabaseException
Description copied from interface:VitamRepository
Save a list of vitam documents- Specified by:
save
in interfaceVitamRepository
- Parameters:
documents
- the list of documents to be saved- Throws:
DatabaseException
- in case error with database occurs
-
saveOrUpdate
public void saveOrUpdate(java.util.List<org.bson.Document> documents) throws DatabaseException
Description copied from interface:VitamRepository
Save or update a list of vitam documents- Specified by:
saveOrUpdate
in interfaceVitamRepository
- Parameters:
documents
- the list of document to be saved orupdated- Throws:
DatabaseException
- in case error with database occurs
-
update
public void update(java.util.List<com.mongodb.client.model.WriteModel<org.bson.Document>> queries) throws DatabaseException
Description copied from interface:VitamRepository
Used to execute a bulk update If document exists then update If document do not exists then create document throw Duplicate key exception if document exists by _id but not exists by filter in the update one model- Specified by:
update
in interfaceVitamRepository
- Throws:
DatabaseException
-
remove
public void remove(java.lang.String id, java.lang.Integer tenant) throws DatabaseException
Description copied from interface:VitamRepository
Remove document by id- Specified by:
remove
in interfaceVitamRepository
- Parameters:
id
- the id of the document to be removedtenant
- the tenant of the document to be removed- Throws:
DatabaseException
- in case error with database occurs
-
remove
public long remove(org.bson.conversions.Bson query) throws DatabaseException
Description copied from interface:VitamRepository
Be careful when using this method Remove by query- Specified by:
remove
in interfaceVitamRepository
- Throws:
DatabaseException
-
removeByNameAndTenant
public void removeByNameAndTenant(java.lang.String name, java.lang.Integer tenant) throws DatabaseException
Description copied from interface:VitamRepository
Be careful when using this method Remove collection by name and tenant- Specified by:
removeByNameAndTenant
in interfaceVitamRepository
- Parameters:
name
- the name of the collection to be removedtenant
- the tenant of the collection to be removed- Throws:
DatabaseException
- in case error with database occurs
-
purge
public long purge(java.lang.Integer tenant) throws DatabaseException
Description copied from interface:VitamRepository
Be careful when using this method Remove by tenant for collection multi-tenant- Specified by:
purge
in interfaceVitamRepository
- Parameters:
tenant
- the tenant- Returns:
- the number of deleted documents
- Throws:
DatabaseException
- in case error with database occurs
-
purge
public long purge() throws DatabaseException
Description copied from interface:VitamRepository
Be careful when using this method Remove by tenant for collection cross-tenant- Specified by:
purge
in interfaceVitamRepository
- Returns:
- number of purged documents
- Throws:
DatabaseException
- in case error with database occurs
-
getByID
public java.util.Optional<org.bson.Document> getByID(java.lang.String id, java.lang.Integer tenant) throws DatabaseException
Description copied from interface:VitamRepository
Get vitam document by id- Specified by:
getByID
in interfaceVitamRepository
- Parameters:
id
- the document idtenant
- the tenant of the document- Returns:
- the document if found
- Throws:
DatabaseException
- in case error with database occurs
-
findByIdentifierAndTenant
public java.util.Optional<org.bson.Document> findByIdentifierAndTenant(java.lang.String identifier, java.lang.Integer tenant) throws DatabaseException
Description copied from interface:VitamRepository
find by identifier for all tenant- Specified by:
findByIdentifierAndTenant
in interfaceVitamRepository
- Parameters:
identifier
- the identifier of the documenttenant
- the tenant of the document- Returns:
- the document if found
- Throws:
DatabaseException
- in case error with database occurs
-
findByIdentifier
public java.util.Optional<org.bson.Document> findByIdentifier(java.lang.String identifier) throws DatabaseException
Description copied from interface:VitamRepository
Find by identifier for collections cross tenant- Specified by:
findByIdentifier
in interfaceVitamRepository
- Parameters:
identifier
- the identifier of the document- Returns:
- the document if found
- Throws:
DatabaseException
- in case error with database occurs
-
findByFieldsDocuments
public com.mongodb.client.FindIterable<org.bson.Document> findByFieldsDocuments(java.util.Map<java.lang.String,java.lang.String> fields, int mongoBatchSize, java.lang.Integer tenant)
Description copied from interface:VitamRepository
Return iterable over document for the given collection for a specific tenant and fields- Specified by:
findByFieldsDocuments
in interfaceVitamRepository
- Parameters:
fields
- list of fields for filtermongoBatchSize
- mongoBatchSizetenant
- tenant id- Returns:
- iterable over document for the given collection
-
findDocuments
public com.mongodb.client.FindIterable<org.bson.Document> findDocuments(java.util.Collection<java.lang.String> ids, org.bson.conversions.Bson projection)
Description copied from interface:VitamRepository
Find collection of document by there id and return only projection fields- Specified by:
findDocuments
in interfaceVitamRepository
- Parameters:
ids
- list of documents idprojection
- the fields wanted in the result- Returns:
- An iterable of documents
-
findDocuments
public com.mongodb.client.FindIterable<org.bson.Document> findDocuments(int mongoBatchSize, java.lang.Integer tenant)
Description copied from interface:VitamRepository
Return iterable over document for the given collection for a specific tenant- Specified by:
findDocuments
in interfaceVitamRepository
- Parameters:
mongoBatchSize
- mongoBatchSizetenant
- tenant id- Returns:
- iterable over document for the given collection
-
findDocuments
public com.mongodb.client.FindIterable<org.bson.Document> findDocuments(int mongoBatchSize)
Description copied from interface:VitamRepository
Return iterable over document for the given collection- Specified by:
findDocuments
in interfaceVitamRepository
- Parameters:
mongoBatchSize
- mongoBatchSize- Returns:
- iterable over document for the given collection
-
findDocuments
public com.mongodb.client.FindIterable<org.bson.Document> findDocuments(org.bson.conversions.Bson query, int mongoBatchSize)
Description copied from interface:VitamRepository
Return iterable over document for the given collection- Specified by:
findDocuments
in interfaceVitamRepository
- Parameters:
query
- the mongo query to be executedmongoBatchSize
- mongoBatchSize- Returns:
- iterable over document for the given collection
-
delete
public void delete(java.util.List<java.lang.String> ids, int tenant)
Description copied from interface:VitamRepository
Deleted all documents by ids- Specified by:
delete
in interfaceVitamRepository
-
count
public long count()
Description copied from interface:VitamRepository
Count occurence of documents- Specified by:
count
in interfaceVitamRepository
- Returns:
- the number of documents
-
count
public long count(org.bson.conversions.Bson filter)
Description copied from interface:VitamRepository
Count occurence of documents- Specified by:
count
in interfaceVitamRepository
- Parameters:
filter
- filtre- Returns:
- the number of documents
-
-