use of net.ravendb.client.documents.session.IDocumentSession 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));
}
use of net.ravendb.client.documents.session.IDocumentSession in project jnosql-diana-driver by eclipse.
the class RavenDBDocumentCollectionManager method update.
@Override
public DocumentEntity update(DocumentEntity entity) {
Objects.requireNonNull(entity, "entity is required");
try (IDocumentSession session = store.openSession()) {
Document id = entity.find(EntityConverter.ID_FIELD).orElseThrow(() -> new RavenException("Id is required to Raven Update operation"));
HashMap<String, Object> map = session.load(HashMap.class, id.get(String.class));
map.putAll(EntityConverter.getMap(entity));
session.saveChanges();
}
return entity;
}
use of net.ravendb.client.documents.session.IDocumentSession in project jnosql-diana-driver by eclipse.
the class RavenDBDocumentCollectionManager method delete.
@Override
public void delete(DocumentDeleteQuery query) {
Objects.requireNonNull(query, "query is required");
try (IDocumentSession session = store.openSession()) {
Stream<Map> entities = getQueryMaps(new RavenDeleteQuery(query), session);
entities.map(EntityConverter::getId).forEach(session::delete);
session.saveChanges();
}
}
use of net.ravendb.client.documents.session.IDocumentSession in project jnosql-diana-driver by eclipse.
the class RavenDBDocumentCollectionManager method insert.
@Override
public DocumentEntity insert(DocumentEntity entity, Duration ttl) {
Objects.requireNonNull(entity, "entity is required");
Objects.requireNonNull(ttl, "ttl is required");
LocalDateTime time = LocalDateTime.now(Clock.systemUTC()).plus(ttl);
try (IDocumentSession session = store.openSession()) {
insert(entity, time, session);
}
return entity;
}
Aggregations