use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-diana-driver by eclipse.
the class QueryUtils method createClause.
private static void createClause(Optional<ColumnCondition> columnConditionOptional, List<Clause> clauses) {
if (!columnConditionOptional.isPresent()) {
return;
}
ColumnCondition columnCondition = columnConditionOptional.get();
Column column = columnCondition.getColumn();
Condition condition = columnCondition.getCondition();
Object value = column.getValue().get();
switch(condition) {
case EQUALS:
clauses.add(QueryBuilder.eq(getName(column), value));
return;
case GREATER_THAN:
clauses.add(QueryBuilder.gt(getName(column), value));
return;
case GREATER_EQUALS_THAN:
clauses.add(QueryBuilder.gte(getName(column), value));
return;
case LESSER_THAN:
clauses.add(QueryBuilder.lt(getName(column), value));
return;
case LESSER_EQUALS_THAN:
clauses.add(QueryBuilder.lte(getName(column), value));
return;
case IN:
clauses.add(QueryBuilder.in(getName(column), getIinValue(value)));
return;
case LIKE:
clauses.add(QueryBuilder.like(getName(column), value));
return;
case AND:
for (ColumnCondition cc : column.get(new TypeReference<List<ColumnCondition>>() {
})) {
createClause(Optional.of(cc), clauses);
}
return;
case OR:
default:
throw new UnsupportedOperationException("The columnCondition " + condition + " is not supported in cassandra column driver");
}
}
use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-diana-driver by eclipse.
the class HBaseColumnFamilyManager method delete.
@Override
public void delete(ColumnDeleteQuery query) {
Objects.requireNonNull(query, "query is required");
ColumnCondition condition = query.getCondition().orElseThrow(() -> new IllegalArgumentException("Condition is required"));
checkedCondition(condition);
List<String> values = new ArrayList<>();
convert(condition, values);
List<Delete> deletes = values.stream().map(String::getBytes).map(Delete::new).collect(toList());
try {
table.delete(deletes);
} catch (IOException e) {
throw new DianaHBaseException("An error when try to delete columns", e);
}
}
use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-diana by eclipse.
the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameGt.
@Test
public void shouldSelectWhereNameGt() {
String columnFamily = "columnFamily";
Number value = 10;
ColumnDeleteQuery query = delete().from(columnFamily).where("name").gt(value).build();
ColumnCondition condition = query.getCondition().get();
Column column = condition.getColumn();
assertTrue(query.getColumns().isEmpty());
assertEquals(columnFamily, query.getColumnFamily());
assertEquals(Condition.GREATER_THAN, condition.getCondition());
assertEquals("name", column.getName());
assertEquals(value, column.get());
}
use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-diana by eclipse.
the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameEq.
@Test
public void shouldSelectWhereNameEq() {
String columnFamily = "columnFamily";
String name = "Ada Lovelace";
ColumnDeleteQuery query = delete().from(columnFamily).where("name").eq(name).build();
ColumnCondition condition = query.getCondition().get();
Column column = condition.getColumn();
assertTrue(query.getColumns().isEmpty());
assertEquals(columnFamily, query.getColumnFamily());
assertEquals(Condition.EQUALS, condition.getCondition());
assertEquals("name", column.getName());
assertEquals(name, column.get());
}
use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-diana by eclipse.
the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameLte.
@Test
public void shouldSelectWhereNameLte() {
String columnFamily = "columnFamily";
Number value = 10;
ColumnDeleteQuery query = delete().from(columnFamily).where("name").lte(value).build();
ColumnCondition columnCondition = query.getCondition().get();
Column column = columnCondition.getColumn();
assertTrue(query.getColumns().isEmpty());
assertEquals(columnFamily, query.getColumnFamily());
assertEquals(Condition.LESSER_EQUALS_THAN, columnCondition.getCondition());
assertEquals("name", column.getName());
assertEquals(value, column.get());
}
Aggregations