use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class DefaultSolrDocumentCollectionManagerTest method shouldFindDocument3.
@Test
public void shouldFindDocument3() {
DocumentEntity entity = entityManager.insert(getEntity());
Optional<Document> id = entity.find(ID);
DocumentQuery query = select().from(COLLECTION_NAME).where("name").eq("Poliana").or("city").eq("Salvador").and(id.get().getName()).eq(id.get().get()).build();
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
assertFalse(entities.isEmpty());
final DocumentEntity result = entities.get(0);
assertEquals(entity.find("name").get(), result.find("name").get());
assertEquals(entity.find("city").get(), result.find("city").get());
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class DefaultSolrDocumentCollectionManagerTest method shouldRemoveEntity.
@Test
public void shouldRemoveEntity() {
DocumentEntity documentEntity = entityManager.insert(getEntity());
Optional<Document> id = documentEntity.find(ID);
DocumentQuery query = select().from(COLLECTION_NAME).where(ID).eq(id.get().get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(ID).eq(id.get().get()).build();
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(query).collect(Collectors.toList()).isEmpty());
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class DefaultSolrDocumentCollectionManagerTest method shouldInsert.
@Test
public void shouldInsert() {
DocumentEntity entity = getEntity();
DocumentEntity documentEntity = entityManager.insert(entity);
assertTrue(documentEntity.getDocuments().stream().map(Document::getName).anyMatch(s -> s.equals(ID)));
}
use of jakarta.nosql.document.Document 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 jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class RavenDBDocumentCollectionManagerTest method shouldSaveSubDocument2.
@Test
public void shouldSaveSubDocument2() {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
DocumentEntity entitySaved = entityManager.insert(entity);
Document id = entitySaved.find("_id").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentEntity entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
Document subDocument = entityFound.find("phones").get();
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
});
assertThat(documents, containsInAnyOrder(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));
}
Aggregations