use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-artemis by eclipse.
the class ColumnQueryDeleteParser method parse.
public ColumnDeleteQuery parse(String methodName, Object[] args, ClassRepresentation representation, Converters converters) {
ColumnCondition condition = null;
String[] tokens = methodName.replace(PREFIX, ColumnQueryParserUtil.EMPTY).split(TOKENIZER);
int index = 0;
for (String token : tokens) {
if (token.startsWith(ColumnQueryParserUtil.AND)) {
ConditionResult result = and(args, index, token, methodName, representation, condition, converters);
condition = result.getCondition();
index = result.getIndex();
} else if (token.startsWith(ColumnQueryParserUtil.OR)) {
ConditionResult result = or(args, index, token, methodName, representation, condition, converters);
condition = result.getCondition();
index = result.getIndex();
} else {
condition = toCondition(token, index, args, methodName, representation, converters);
index++;
}
}
return new ArtemisColumnDeleteQuery(representation.getName(), condition);
}
use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-artemis by eclipse.
the class ColumnQueryDeleteParserTest method shouldDeleteByNameAndAge.
@Test
public void shouldDeleteByNameAndAge() {
ColumnDeleteQuery query = parser.parse("deleteByNameAndAge", new Object[] { "name", 10 }, classRepresentation, converters);
ColumnCondition condition = query.getCondition().get();
assertEquals("Person", query.getColumnFamily());
assertEquals(Condition.AND, condition.getCondition());
List<ColumnCondition> conditions = condition.getColumn().get(new TypeReference<List<ColumnCondition>>() {
});
ColumnCondition condition1 = conditions.get(0);
assertEquals(Condition.EQUALS, condition1.getCondition());
assertEquals(Column.of("name", "name"), condition1.getColumn());
ColumnCondition condition2 = conditions.get(1);
assertEquals(Condition.EQUALS, condition2.getCondition());
assertEquals(Column.of("age", 10), condition2.getColumn());
}
use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-artemis by eclipse.
the class ColumnQueryDeleteParserTest method shouldDeleteByNameOrAge.
@Test
public void shouldDeleteByNameOrAge() {
ColumnDeleteQuery query = parser.parse("deleteByNameOrAge", new Object[] { "name", 10 }, classRepresentation, converters);
ColumnCondition condition = query.getCondition().get();
assertEquals("Person", query.getColumnFamily());
assertEquals(Condition.OR, condition.getCondition());
List<ColumnCondition> conditions = condition.getColumn().get(new TypeReference<List<ColumnCondition>>() {
});
ColumnCondition condition1 = conditions.get(0);
assertEquals(Condition.EQUALS, condition1.getCondition());
assertEquals(Column.of("name", "name"), condition1.getColumn());
ColumnCondition condition2 = conditions.get(1);
assertEquals(Condition.EQUALS, condition2.getCondition());
assertEquals(Column.of("age", 10), condition2.getColumn());
}
use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-artemis by eclipse.
the class ColumnRepositoryAsyncProxyTest method shoudFindByNameSortPagination.
@Test
public void shoudFindByNameSortPagination() {
Consumer<List<Person>> callback = v -> {
};
Sort sort = Sort.of("age", Sort.SortType.ASC);
Pagination pagination = Pagination.of(10, 20);
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
personRepository.findByName("name", sort, pagination, callback);
verify(template).select(captor.capture(), consumerCaptor.capture());
ColumnQuery query = captor.getValue();
ColumnCondition condition = query.getCondition().get();
assertEquals("Person", query.getColumnFamily());
assertEquals(Condition.EQUALS, condition.getCondition());
assertEquals(Column.of("name", "name"), condition.getColumn());
assertEquals(callback, consumerCaptor.getValue());
assertEquals(sort, query.getSorts().get(0));
assertEquals(pagination.getFirstResult(), query.getFirstResult());
assertEquals(pagination.getMaxResults(), query.getMaxResults());
}
use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-artemis by eclipse.
the class ColumnRepositoryAsyncProxyTest method shouldDeleteByName.
@Test
public void shouldDeleteByName() {
ArgumentCaptor<ColumnDeleteQuery> captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class);
personRepository.deleteByName("name");
verify(template).delete(captor.capture());
ColumnDeleteQuery query = captor.getValue();
ColumnCondition condition = query.getCondition().get();
assertEquals("Person", query.getColumnFamily());
assertEquals(Condition.EQUALS, condition.getCondition());
assertEquals(Column.of("name", "name"), condition.getColumn());
}
Aggregations