Search in sources :

Example 66 with ColumnDeleteQuery

use of jakarta.nosql.column.ColumnDeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryParserTest method shouldReturnParserQuery25.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete  from God where name = \"Ada\" and age = 20 or" + " siblings = {\"apollo\": \"Brother\", \"Zeus\": \"Father\"}" })
public void shouldReturnParserQuery25(String query) {
    ArgumentCaptor<ColumnDeleteQuery> captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).delete(captor.capture());
    ColumnDeleteQuery columnQuery = captor.getValue();
    checkBaseQuery(columnQuery);
    assertTrue(columnQuery.getCondition().isPresent());
    ColumnCondition condition = columnQuery.getCondition().get();
    Column column = condition.getColumn();
    assertEquals(Condition.AND, condition.getCondition());
    List<ColumnCondition> conditions = column.get(new TypeReference<List<ColumnCondition>>() {
    });
    assertEquals(Condition.EQUALS, conditions.get(0).getCondition());
    assertEquals(Condition.EQUALS, conditions.get(1).getCondition());
    assertEquals(Condition.OR, conditions.get(2).getCondition());
}
Also used : Column(jakarta.nosql.column.Column) List(java.util.List) ColumnCondition(jakarta.nosql.column.ColumnCondition) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 67 with ColumnDeleteQuery

use of jakarta.nosql.column.ColumnDeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryParserTest method shouldReturnParserQuery21.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where name like \"Ada\"" })
public void shouldReturnParserQuery21(String query) {
    ArgumentCaptor<ColumnDeleteQuery> captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).delete(captor.capture());
    ColumnDeleteQuery columnQuery = captor.getValue();
    checkBaseQuery(columnQuery);
    assertTrue(columnQuery.getCondition().isPresent());
    ColumnCondition condition = columnQuery.getCondition().get();
    Column column = condition.getColumn();
    assertEquals(Condition.LIKE, condition.getCondition());
    assertEquals("name", column.getName());
    assertEquals("Ada", column.get());
}
Also used : Column(jakarta.nosql.column.Column) ColumnCondition(jakarta.nosql.column.ColumnCondition) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 68 with ColumnDeleteQuery

use of jakarta.nosql.column.ColumnDeleteQuery in project jnosql-diana by eclipse.

the class DeleteQueryParserTest method shouldReturnParserQuery23.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete  from God where name = \"Ada\" and age = 20" })
public void shouldReturnParserQuery23(String query) {
    ArgumentCaptor<ColumnDeleteQuery> captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).delete(captor.capture());
    ColumnDeleteQuery columnQuery = captor.getValue();
    checkBaseQuery(columnQuery);
    assertTrue(columnQuery.getCondition().isPresent());
    ColumnCondition condition = columnQuery.getCondition().get();
    Column column = condition.getColumn();
    assertEquals(Condition.AND, condition.getCondition());
    List<ColumnCondition> conditions = column.get(new TypeReference<List<ColumnCondition>>() {
    });
    assertThat(conditions, contains(eq(Column.of("name", "Ada")), eq(Column.of("age", 20L))));
}
Also used : Column(jakarta.nosql.column.Column) List(java.util.List) ColumnCondition(jakarta.nosql.column.ColumnCondition) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 69 with ColumnDeleteQuery

use of jakarta.nosql.column.ColumnDeleteQuery in project jnosql-diana by eclipse.

the class DefaultColumnTemplateTest method shouldDelete.

@Test
public void shouldDelete() {
    ColumnDeleteQuery query = delete().from("delete").build();
    subject.delete(query);
    verify(managerMock).delete(query);
}
Also used : ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 70 with ColumnDeleteQuery

use of jakarta.nosql.column.ColumnDeleteQuery in project jnosql-diana by eclipse.

the class AbstractColumnRepositoryProxy method invoke.

@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
    RepositoryType type = RepositoryType.of(method);
    Class<?> typeClass = getClassMapping().getClassInstance();
    switch(type) {
        case DEFAULT:
            return method.invoke(getRepository(), args);
        case FIND_BY:
            ColumnQuery query = getQuery(method, args);
            return executeQuery(method, args, typeClass, query);
        case FIND_ALL:
            ColumnQuery queryFindAll = ColumnQuery.select().from(getClassMapping().getName()).build();
            return executeQuery(method, args, typeClass, getQuerySorts(args, queryFindAll));
        case DELETE_BY:
            ColumnDeleteQuery deleteQuery = getDeleteQuery(method, args);
            getTemplate().delete(deleteQuery);
            return Void.class;
        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;
    }
}
Also used : DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) Repository(jakarta.nosql.mapping.Repository) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) Converters(jakarta.nosql.mapping.Converters) ColumnQuery(jakarta.nosql.column.ColumnQuery) DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) InvocationHandler(java.lang.reflect.InvocationHandler) Method(java.lang.reflect.Method) ColumnQuery(jakarta.nosql.column.ColumnQuery) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery)

Aggregations

ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)70 Test (org.junit.jupiter.api.Test)41 ColumnCondition (jakarta.nosql.column.ColumnCondition)33 Column (jakarta.nosql.column.Column)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 ValueSource (org.junit.jupiter.params.provider.ValueSource)20 Person (jakarta.nosql.tck.entities.Person)12 List (java.util.List)12 ColumnEntity (jakarta.nosql.column.ColumnEntity)6 Params (jakarta.nosql.Params)5 ColumnDeleteQueryParams (jakarta.nosql.column.ColumnDeleteQueryParams)5 ColumnQuery (jakarta.nosql.column.ColumnQuery)5 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)4 ColumnFamilyManager (jakarta.nosql.column.ColumnFamilyManager)3 DeleteQuery (jakarta.nosql.query.DeleteQuery)3 Optional (java.util.Optional)3 QueryException (jakarta.nosql.QueryException)2 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)2 ColumnObserverParser (jakarta.nosql.column.ColumnObserverParser)2 DeleteQueryConverter (jakarta.nosql.column.DeleteQueryConverter)2