use of jakarta.nosql.column.ColumnCondition in project jnosql-diana by eclipse.
the class DefaultColumnConditionTest method shouldNegate.
@Test
public void shouldNegate() {
ColumnCondition eq = ColumnCondition.eq(Column.of("name", "otavio"));
ColumnCondition negate = eq.negate();
assertEquals(Condition.NOT, negate.getCondition());
ColumnCondition condition = negate.getColumn().get(ColumnCondition.class);
assertEquals(eq, condition);
}
use of jakarta.nosql.column.ColumnCondition in project jnosql-diana by eclipse.
the class DefaultColumnConditionTest method shouldReturnInClause.
@Test
public void shouldReturnInClause() {
Column column = Column.of("age", Arrays.asList(12, 13));
ColumnCondition in = ColumnCondition.in(column);
assertEquals(Condition.IN, in.getCondition());
Iterable<Integer> integers = in.getColumn().get(new TypeReference<Iterable<Integer>>() {
});
assertThat(integers, contains(12, 13));
}
use of jakarta.nosql.column.ColumnCondition in project jnosql-diana by eclipse.
the class DefaultColumnConditionTest method shouldAppendOr.
@Test
public void shouldAppendOr() {
ColumnCondition eq = ColumnCondition.eq(Column.of("name", "otavio"));
ColumnCondition gt = ColumnCondition.gt(Column.of("age", 10));
ColumnCondition and = ColumnCondition.or(eq, gt);
assertEquals(Condition.OR, and.getCondition());
List<ColumnCondition> conditions = and.getColumn().get(new TypeReference<List<ColumnCondition>>() {
});
assertThat(conditions, Matchers.containsInAnyOrder(eq, gt));
}
use of jakarta.nosql.column.ColumnCondition in project jnosql-diana by eclipse.
the class DeleteQueryParser method getQuery.
private ColumnDeleteQuery getQuery(Params params, ColumnObserverParser observer, DeleteQuery deleteQuery) {
String columnFamily = observer.fireEntity(deleteQuery.getEntity());
List<String> columns = deleteQuery.getFields().stream().map(f -> observer.fireField(columnFamily, f)).collect(Collectors.toList());
ColumnCondition condition = null;
if (deleteQuery.getWhere().isPresent()) {
condition = deleteQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, columnFamily)).get();
}
return new DefaultColumnDeleteQuery(columnFamily, condition, columns);
}
use of jakarta.nosql.column.ColumnCondition in project jnosql-diana by eclipse.
the class DeleteQueryParser method getQuery.
private ColumnDeleteQuery getQuery(String query, ColumnObserverParser observer) {
DeleteQuery deleteQuery = deleteQueryProvider.apply(query);
String columnFamily = observer.fireEntity(deleteQuery.getEntity());
List<String> columns = deleteQuery.getFields().stream().map(f -> observer.fireField(columnFamily, f)).collect(Collectors.toList());
ColumnCondition condition = null;
Params params = Params.newParams();
if (deleteQuery.getWhere().isPresent()) {
condition = deleteQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, columnFamily)).get();
}
if (params.isNotEmpty()) {
throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
}
return new DefaultColumnDeleteQuery(columnFamily, condition, columns);
}
Aggregations