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());
}
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());
}
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))));
}
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);
}
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;
}
}
Aggregations