use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.
the class AbstractDocumentTemplate method delete.
@Override
public <T, K> void delete(Class<T> entityClass, K id) {
requireNonNull(entityClass, "entityClass is required");
requireNonNull(id, "id is required");
ClassMapping classMapping = getClassMappings().get(entityClass);
FieldMapping idField = classMapping.getId().orElseThrow(() -> IdNotFoundException.newInstance(entityClass));
Object value = ConverterUtil.getValue(id, classMapping, idField.getFieldName(), getConverters());
DocumentDeleteQuery query = DocumentDeleteQuery.delete().from(classMapping.getName()).where(idField.getName()).eq(value).build();
delete(query);
}
use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.
the class AbstractReactiveDocumentRepositoryProxy method invoke.
@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
RepositoryType type = ReactiveRepositoryType.of(method);
Class<?> typeClass = getClassMapping().getClassInstance();
switch(type) {
case DEFAULT:
return method.invoke(getRepository(), args);
case FIND_BY:
DocumentQuery query = getQuery(method, args);
return executeQuery(method, args, typeClass, query);
case FIND_ALL:
DocumentQuery queryFindAll = select().from(getClassMapping().getName()).build();
return executeQuery(method, args, typeClass, getQuerySorts(args, queryFindAll));
case DELETE_BY:
DocumentDeleteQuery documentDeleteQuery = getDeleteQuery(method, args);
Iterable<Void> iterable = () -> {
getTemplate().delete(documentDeleteQuery);
return Collections.emptyIterator();
};
return ReactiveStreams.fromIterable(iterable).buildRs();
case OBJECT_METHOD:
return method.invoke(this, args);
case JNOSQL_QUERY:
DynamicQueryMethodReturn methodReturn = DynamicQueryMethodReturn.builder().withArgs(args).withMethod(method).withTypeClass(typeClass).withPrepareConverter(q -> getTemplate().prepare(q)).withQueryConverter(q -> getTemplate().query(q)).build();
return methodReturn.execute();
default:
return Void.class;
}
}
use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.
the class DefaultReactiveDocumentTemplateTest method shouldDelete.
@Test
public void shouldDelete() {
AtomicLong atomicLong = new AtomicLong();
DocumentDeleteQuery query = Mockito.mock(DocumentDeleteQuery.class);
final Observable<Void> observable = manager.delete(query);
Mockito.verify(template, Mockito.never()).delete(query);
CompletionStage<Optional<Void>> completion = observable.getFirst();
completion.thenAccept(o -> atomicLong.incrementAndGet());
Mockito.verify(template).delete(query);
assertEquals(1L, atomicLong.get());
}
use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.
the class DefaultDocumentEventPersistManagerTest method shouldFirePreDeleteQuery.
@Test
public void shouldFirePreDeleteQuery() {
DocumentDeleteQuery query = DocumentDeleteQuery.delete().from("collection").build();
subject.firePreDeleteQuery(query);
ArgumentCaptor<DocumentDeleteQueryExecute> captor = ArgumentCaptor.forClass(DocumentDeleteQueryExecute.class);
verify(documentDeleteQueryExecute).fire(captor.capture());
assertEquals(query, captor.getValue().getQuery());
}
use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.
the class DefaultDocumentTemplateTest method shouldDeleteEntity.
@Test
public void shouldDeleteEntity() {
subject.delete(Person.class, "10");
ArgumentCaptor<DocumentDeleteQuery> queryCaptor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
verify(managerMock).delete(queryCaptor.capture());
DocumentDeleteQuery query = queryCaptor.getValue();
DocumentCondition condition = query.getCondition().get();
assertEquals("Person", query.getDocumentCollection());
assertEquals(DocumentCondition.eq(Document.of("_id", 10L)), condition);
}
Aggregations