Search in sources :

Example 1 with IMetadataDictionary

use of net.ravendb.client.documents.session.IMetadataDictionary in project jnosql-diana-driver by eclipse.

the class RavenDBDocumentCollectionManager method insert.

private void insert(DocumentEntity entity, LocalDateTime time, IDocumentSession session) {
    String collection = entity.getName();
    Map<String, Object> entityMap = EntityConverter.getMap(entity);
    String id = entity.find(EntityConverter.ID_FIELD).map(d -> d.get(String.class)).orElse(collection + '/');
    session.store(entityMap, id);
    IMetadataDictionary metadata = session.advanced().getMetadataFor(entityMap);
    metadata.put(COLLECTION, collection);
    if (Objects.nonNull(time)) {
        metadata.put(EXPIRES, time.toString());
    }
    session.saveChanges();
    entity.add(EntityConverter.ID_FIELD, session.advanced().getDocumentId(entityMap));
}
Also used : LocalDateTime(java.time.LocalDateTime) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) HashMap(java.util.HashMap) RavenException(net.ravendb.client.exceptions.RavenException) DocumentQuery(jakarta.nosql.document.DocumentQuery) Duration(java.time.Duration) Map(java.util.Map) IDocumentSession(net.ravendb.client.documents.session.IDocumentSession) StreamSupport(java.util.stream.StreamSupport) DocumentCollectionManager(jakarta.nosql.document.DocumentCollectionManager) IMetadataDictionary(net.ravendb.client.documents.session.IMetadataDictionary) IEnumerableQuery(net.ravendb.client.documents.session.IEnumerableQuery) DocumentStore(net.ravendb.client.documents.DocumentStore) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) Query(net.ravendb.client.documents.queries.Query) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) IDocumentQuery(net.ravendb.client.documents.session.IDocumentQuery) List(java.util.List) Stream(java.util.stream.Stream) Clock(java.time.Clock) EXPIRES(net.ravendb.client.Constants.Documents.Metadata.EXPIRES) Collections(java.util.Collections) COLLECTION(net.ravendb.client.Constants.Documents.Metadata.COLLECTION) IMetadataDictionary(net.ravendb.client.documents.session.IMetadataDictionary)

Aggregations

Document (jakarta.nosql.document.Document)1 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)1 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)1 DocumentEntity (jakarta.nosql.document.DocumentEntity)1 DocumentQuery (jakarta.nosql.document.DocumentQuery)1 Clock (java.time.Clock)1 Duration (java.time.Duration)1 LocalDateTime (java.time.LocalDateTime)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 COLLECTION (net.ravendb.client.Constants.Documents.Metadata.COLLECTION)1 EXPIRES (net.ravendb.client.Constants.Documents.Metadata.EXPIRES)1 DocumentStore (net.ravendb.client.documents.DocumentStore)1 Query (net.ravendb.client.documents.queries.Query)1