Search in sources :

Example 1 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.

the class AbstractColumnRepositoryAsyncProxy method invoke.

@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
    String methodName = method.getName();
    ColumnRepositoryType type = ColumnRepositoryType.of(method, args);
    switch(type) {
        case DEFAULT:
            return method.invoke(getRepository(), args);
        case FIND_BY:
            ColumnQuery 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:
            ColumnDeleteQuery deleteQuery = getDeleteParser().parse(methodName, args, getClassRepresentation(), getConverters());
            return executeDelete(getCallBack(args), deleteQuery);
        case QUERY:
            ColumnQuery columnQuery = ColumnRepositoryType.getQuery(args).get();
            return executeQuery(getCallBack(args), columnQuery);
        case QUERY_DELETE:
            return executeDelete(args, ColumnRepositoryType.getDeleteQuery(args).get());
        case OBJECT_METHOD:
            return method.invoke(this, args);
        default:
            return Void.class;
    }
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery)

Example 2 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.

the class AbstractColumnRepositoryProxy method invoke.

@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
    String methodName = method.getName();
    ColumnRepositoryType type = ColumnRepositoryType.of(method, args);
    Class<?> typeClass = getClassRepresentation().getClassInstance();
    switch(type) {
        case DEFAULT:
            return method.invoke(getRepository(), args);
        case FIND_BY:
            ColumnQuery 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:
            ColumnDeleteQuery deleteQuery = getDeleteParser().parse(methodName, args, getClassRepresentation(), getConverters());
            getTemplate().delete(deleteQuery);
            return Void.class;
        case QUERY:
            ColumnQuery columnQuery = getQuery(args).get();
            return returnObject(columnQuery, getTemplate(), typeClass, method);
        case QUERY_DELETE:
            ColumnDeleteQuery columnDeleteQuery = getDeleteQuery(args).get();
            getTemplate().delete(columnDeleteQuery);
            return Void.class;
        case OBJECT_METHOD:
            return method.invoke(this, args);
        default:
            return Void.class;
    }
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery)

Example 3 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.

the class AbstractColumnTemplate method find.

@Override
public <T, ID> Optional<T> find(Class<T> entityClass, ID id) {
    requireNonNull(entityClass, "entityClass is required");
    requireNonNull(id, "id is required");
    ClassRepresentation classRepresentation = getClassRepresentations().get(entityClass);
    FieldRepresentation idField = classRepresentation.getId().orElseThrow(() -> IdNotFoundException.newInstance(entityClass));
    Object value = ConverterUtil.getValue(id, classRepresentation, idField.getFieldName(), getConverters());
    ColumnQuery query = ColumnQueryBuilder.select().from(classRepresentation.getName()).where(idField.getName()).eq(value).build();
    return singleResult(query);
}
Also used : FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Example 4 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.

the class DefaultColumnTemplateAsyncTest method shouldReturnErrorFindByIdReturnMoreThanOne.

@Test
public void shouldReturnErrorFindByIdReturnMoreThanOne() {
    assertThrows(NonUniqueResultException.class, () -> {
        ArgumentCaptor<Consumer<List<ColumnEntity>>> dianaCallbackCaptor = ArgumentCaptor.forClass(Consumer.class);
        ArgumentCaptor<ColumnQuery> queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class);
        AtomicBoolean condition = new AtomicBoolean(false);
        AtomicReference<Person> atomicReference = new AtomicReference<>();
        Consumer<Optional<Person>> callback = p -> {
            condition.set(true);
            p.ifPresent(atomicReference::set);
        };
        subject.find(Person.class, 10L, callback);
        verify(managerMock).select(queryCaptor.capture(), dianaCallbackCaptor.capture());
        Consumer<List<ColumnEntity>> dianaCallBack = dianaCallbackCaptor.getValue();
        dianaCallBack.accept(asList(ColumnEntity.of("Person", asList(columns)), ColumnEntity.of("Person", asList(columns))));
    });
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Arrays(java.util.Arrays) Converters(org.jnosql.artemis.Converters) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery) ColumnFamilyManagerAsync(org.jnosql.diana.api.column.ColumnFamilyManagerAsync) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ColumnQueryBuilder.delete(org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collections.singletonList(java.util.Collections.singletonList) Person(org.jnosql.artemis.model.Person) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Arrays.asList(java.util.Arrays.asList) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Duration(java.time.Duration) NonUniqueResultException(org.jnosql.diana.api.NonUniqueResultException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Instance(javax.enterprise.inject.Instance) ColumnQueryBuilder(org.jnosql.diana.api.column.query.ColumnQueryBuilder) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Awaitility.await(org.awaitility.Awaitility.await) Collections.emptyList(java.util.Collections.emptyList) Collectors(java.util.stream.Collectors) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) Column(org.jnosql.diana.api.column.Column) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) ColumnQueryBuilder.select(org.jnosql.diana.api.column.query.ColumnQueryBuilder.select) Optional(java.util.Optional) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Optional(java.util.Optional) AtomicReference(java.util.concurrent.atomic.AtomicReference) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Consumer(java.util.function.Consumer) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 5 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.

the class DefaultColumnTemplateAsyncTest method shouldReturnEmptySingleResult.

@Test
public void shouldReturnEmptySingleResult() {
    ArgumentCaptor<Consumer<List<ColumnEntity>>> dianaCallbackCaptor = ArgumentCaptor.forClass(Consumer.class);
    ColumnQuery query = ColumnQueryBuilder.select().from("Person").build();
    AtomicBoolean condition = new AtomicBoolean(false);
    AtomicReference<Person> atomicReference = new AtomicReference<>();
    Consumer<Optional<Person>> callback = p -> {
        condition.set(true);
        p.ifPresent(atomicReference::set);
    };
    subject.singleResult(query, callback);
    verify(managerMock).select(Mockito.any(ColumnQuery.class), dianaCallbackCaptor.capture());
    Consumer<List<ColumnEntity>> dianaCallBack = dianaCallbackCaptor.getValue();
    dianaCallBack.accept(emptyList());
    verify(managerMock).select(Mockito.eq(query), Mockito.any());
    await().untilTrue(condition);
    assertNull(atomicReference.get());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition) Arrays(java.util.Arrays) Converters(org.jnosql.artemis.Converters) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery) ColumnFamilyManagerAsync(org.jnosql.diana.api.column.ColumnFamilyManagerAsync) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ColumnQueryBuilder.delete(org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collections.singletonList(java.util.Collections.singletonList) Person(org.jnosql.artemis.model.Person) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Arrays.asList(java.util.Arrays.asList) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Duration(java.time.Duration) NonUniqueResultException(org.jnosql.diana.api.NonUniqueResultException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Instance(javax.enterprise.inject.Instance) ColumnQueryBuilder(org.jnosql.diana.api.column.query.ColumnQueryBuilder) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Awaitility.await(org.awaitility.Awaitility.await) Collections.emptyList(java.util.Collections.emptyList) Collectors(java.util.stream.Collectors) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) Column(org.jnosql.diana.api.column.Column) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) ColumnQueryBuilder.select(org.jnosql.diana.api.column.query.ColumnQueryBuilder.select) Optional(java.util.Optional) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Optional(java.util.Optional) AtomicReference(java.util.concurrent.atomic.AtomicReference) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Consumer(java.util.function.Consumer) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)117 Test (org.junit.jupiter.api.Test)113 Person (org.jnosql.artemis.model.Person)37 ColumnCondition (org.jnosql.diana.api.column.ColumnCondition)35 Column (org.jnosql.diana.api.column.Column)29 List (java.util.List)26 ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)26 Collections.singletonList (java.util.Collections.singletonList)20 ColumnDeleteQuery (org.jnosql.diana.api.column.ColumnDeleteQuery)19 Arrays.asList (java.util.Arrays.asList)15 Duration (java.time.Duration)14 ColumnQueryBuilder.delete (org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete)14 ColumnQueryBuilder.select (org.jnosql.diana.api.column.query.ColumnQueryBuilder.select)14 BeforeEach (org.junit.jupiter.api.BeforeEach)14 Optional (java.util.Optional)13 Consumer (java.util.function.Consumer)13 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)13 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)13 Inject (javax.inject.Inject)12 CDIExtension (org.jnosql.artemis.CDIExtension)12