use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class ElasticsearchEntry method toEntity.
DocumentEntity toEntity() {
Document id = Document.of(ID_FIELD, this.id);
List<Document> documents = map.keySet().stream().map(k -> toDocument(k, map)).collect(Collectors.toList());
DocumentEntity entity = DocumentEntity.of(collection, documents);
entity.remove(ID_FIELD);
entity.add(id);
return entity;
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldRemoveEntityById.
@Test
public void shouldRemoveEntityById() {
DocumentEntity documentEntity = entityManager.insert(DocumentEntityGerator.getEntity());
Document id = documentEntity.find("_id").get();
DocumentQuery query = select().from(DocumentEntityGerator.COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(DocumentEntityGerator.COLLECTION_NAME).where(id.getName()).eq(id.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 ElasticsearchDocumentCollectionManagerTest method shouldRemoveEntityByName.
@Test
public void shouldRemoveEntityByName() throws InterruptedException {
DocumentEntity documentEntity = entityManager.insert(DocumentEntityGerator.getEntity());
Document name = documentEntity.find("name").get();
DocumentQuery query = select().from(DocumentEntityGerator.COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(DocumentEntityGerator.COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
SECONDS.sleep(1L);
entityManager.delete(deleteQuery);
SECONDS.sleep(1L);
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
System.out.println(entities);
assertTrue(entities.isEmpty());
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldSaveSubDocument2.
@Test
public void shouldSaveSubDocument2() {
DocumentEntity entity = DocumentEntityGerator.getEntity();
entity.add(Document.of("phones", Arrays.asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
DocumentEntity entitySaved = entityManager.insert(entity);
Document id = entitySaved.find("_id").get();
DocumentQuery query = select().from(DocumentEntityGerator.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")));
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldUpdateSave.
@Test
public void shouldUpdateSave() {
DocumentEntity entity = DocumentEntityGerator.getEntity();
entityManager.insert(entity);
Document newField = Documents.of("newField", "10");
entity.add(newField);
DocumentEntity updated = entityManager.update(entity);
assertEquals(newField, updated.find("newField").get());
}
Aggregations