Search in sources :

Example 81 with DocumentDeleteQuery

use of org.jnosql.diana.api.document.DocumentDeleteQuery in project jnosql-artemis by eclipse.

the class DocumentRepositoryAsyncProxyTest method shouldDeleteByName.

@Test
public void shouldDeleteByName() {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    personRepository.deleteByName("name");
    verify(template).delete(captor.capture());
    DocumentDeleteQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals(Document.of("name", "name"), condition.getDocument());
}
Also used : DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 82 with DocumentDeleteQuery

use of org.jnosql.diana.api.document.DocumentDeleteQuery in project jnosql-artemis by eclipse.

the class DocumentRepositoryAsyncProxyTest method shouldExecuteDeleteQuery.

// 
@Test
public void shouldExecuteDeleteQuery() {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    DocumentDeleteQuery deleteQuery = delete().from("Person").where("name").eq("Ada").build();
    personRepository.deleteQuery(deleteQuery);
    verify(template).delete(captor.capture());
    assertEquals(deleteQuery, captor.getValue());
}
Also used : DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 83 with DocumentDeleteQuery

use of org.jnosql.diana.api.document.DocumentDeleteQuery in project jnosql-artemis by eclipse.

the class AbstractDocumentRepositoryAsyncProxy method invoke.

@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
    String methodName = method.getName();
    DocumentRepositoryType type = DocumentRepositoryType.of(method, args);
    switch(type) {
        case DEFAULT:
            return method.invoke(getRepository(), args);
        case FIND_BY:
            DocumentQuery query = getQueryParser().parse(methodName, args, getClassRepresentation(), getConverters());
            return executeQuery(getCallBack(args), query);
        case FIND_ALL:
            return executeQuery(getCallBack(args), select().from(getClassRepresentation().getName()).build());
        case DELETE_BY:
            DocumentDeleteQuery deleteQuery = getDeleteParser().parse(methodName, args, getClassRepresentation(), getConverters());
            return executeDelete(args, deleteQuery);
        case QUERY:
            DocumentQuery documentQuery = getQuery(args).get();
            return executeQuery(getCallBack(args), documentQuery);
        case QUERY_DELETE:
            return executeDelete(args, getDeleteQuery(args).get());
        case OBJECT_METHOD:
            return method.invoke(this, args);
        default:
            return Void.class;
    }
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery)

Example 84 with DocumentDeleteQuery

use of org.jnosql.diana.api.document.DocumentDeleteQuery in project jnosql-artemis by eclipse.

the class AbstractDocumentRepositoryProxy method invoke.

@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
    String methodName = method.getName();
    DocumentRepositoryType type = DocumentRepositoryType.of(method, args);
    Class<?> typeClass = getClassRepresentation().getClassInstance();
    switch(type) {
        case DEFAULT:
            return method.invoke(getRepository(), args);
        case FIND_BY:
            DocumentQuery query = getQueryParser().parse(methodName, args, getClassRepresentation(), getConverters());
            return returnObject(query, getTemplate(), typeClass, method);
        case FIND_ALL:
            return returnObject(select().from(getClassRepresentation().getName()).build(), getTemplate(), typeClass, method);
        case DELETE_BY:
            getTemplate().delete(getDeleteParser().parse(methodName, args, getClassRepresentation(), getConverters()));
            return null;
        case QUERY:
            DocumentQuery documentQuery = getQuery(args).get();
            return returnObject(documentQuery, getTemplate(), typeClass, method);
        case QUERY_DELETE:
            DocumentDeleteQuery deleteQuery = getDeleteQuery(args).get();
            getTemplate().delete(deleteQuery);
            return Void.class;
        case OBJECT_METHOD:
            return method.invoke(this, args);
        default:
            return Void.class;
    }
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery)

Example 85 with DocumentDeleteQuery

use of org.jnosql.diana.api.document.DocumentDeleteQuery in project jnosql-artemis by eclipse.

the class DocumentRepositoryProxyTest method shouldDeleteQuery.

@Test
public void shouldDeleteQuery() {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    DocumentDeleteQuery query = delete().from("Person").where("name").eq("Ada").build();
    personRepository.deleteQuery(query);
    verify(template).delete(captor.capture());
    assertEquals(query, captor.getValue());
}
Also used : DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)86 Test (org.junit.jupiter.api.Test)74 Document (org.jnosql.diana.api.document.Document)35 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)31 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)31 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)20 List (java.util.List)15 Person (org.jnosql.artemis.model.Person)13 Duration (java.time.Duration)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 Optional (java.util.Optional)4 Consumer (java.util.function.Consumer)4 Collectors (java.util.stream.Collectors)4 DocumentQueryBuilder.delete (org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete)4 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)4 Arrays (java.util.Arrays)3