use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldRemoveEntityByName.
@Test
public void shouldRemoveEntityByName() {
DocumentEntity documentEntity = entityManager.insert(getEntity());
Document name = documentEntity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(name.getName()).eq(name.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 DefaultCouchbaseDocumentCollectionManager method insert.
@Override
public DocumentEntity insert(DocumentEntity entity, Duration ttl) {
requireNonNull(entity, "entity is required");
requireNonNull(ttl, "ttl is required");
JsonObject jsonObject = convert(entity);
Document id = entity.find(ID_FIELD).orElseThrow(() -> new CouchbaseNoKeyFoundException(entity.toString()));
String prefix = getPrefix(id, entity.getName());
jsonObject.put(KEY_FIELD, prefix);
bucket.upsert(JsonDocument.create(prefix, (int) ttl.getSeconds(), jsonObject));
return entity;
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class DocumentQueryTest method shouldShouldDefineLimit.
@Test
public void shouldShouldDefineLimit() {
DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id"), Document.of("name", "name")));
Document name = entity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).limit(2L).build();
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
assertEquals(2, entities.size());
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class DocumentQueryTest method shouldFindDocumentByName.
@Test
public void shouldFindDocumentByName() {
DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id4"), Document.of("name", "name3"), Document.of("_key", "person:id4")));
Document name = entity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
assertFalse(entities.isEmpty());
assertThat(entities, contains(entity));
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class EntityConverter method convertDocument.
private static void convertDocument(JsonObject jsonObject, Document d, Object value) {
Document document = Document.class.cast(value);
jsonObject.put(d.getName(), Collections.singletonMap(document.getName(), document.get()));
}
Aggregations