Search in sources :

Example 81 with ColumnCondition

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

the class BaseQueryBuilder method inImpl.

protected <T> void inImpl(Iterable<T> values) {
    requireNonNull(values, "values is required");
    ColumnCondition newCondition = ColumnCondition.in(Column.of(name, values));
    appendCondition(newCondition);
}
Also used : ColumnCondition(jakarta.nosql.column.ColumnCondition)

Example 82 with ColumnCondition

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

the class BaseQueryBuilder method betweenImpl.

protected <T> void betweenImpl(T valueA, T valueB) {
    requireNonNull(valueA, "valueA is required");
    requireNonNull(valueB, "valueB is required");
    ColumnCondition newCondition = ColumnCondition.between(Column.of(name, asList(valueA, valueB)));
    appendCondition(newCondition);
}
Also used : ColumnCondition(jakarta.nosql.column.ColumnCondition)

Example 83 with ColumnCondition

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

the class Relations method load.

private static void load(ColumnCondition columnCondition, List<Relation> relations) {
    Column column = columnCondition.getColumn();
    Condition condition = columnCondition.getCondition();
    switch(condition) {
        case EQUALS:
            relations.add(Relation.column(QueryUtils.getName(column)).isEqualTo(getTerm(column)));
            return;
        case GREATER_THAN:
            relations.add(Relation.column(QueryUtils.getName(column)).isGreaterThan(getTerm(column)));
            return;
        case GREATER_EQUALS_THAN:
            relations.add(Relation.column(QueryUtils.getName(column)).isGreaterThanOrEqualTo(getTerm(column)));
            return;
        case LESSER_THAN:
            relations.add(Relation.column(QueryUtils.getName(column)).isLessThan(getTerm(column)));
            return;
        case LESSER_EQUALS_THAN:
            relations.add(Relation.column(QueryUtils.getName(column)).isLessThanOrEqualTo(getTerm(column)));
            return;
        case IN:
            relations.add(Relation.column(QueryUtils.getName(column)).in(getIinValue(column.getValue())));
            return;
        case LIKE:
            relations.add(Relation.column(QueryUtils.getName(column)).like(getTerm(column)));
            return;
        case AND:
            column.get(new TypeReference<List<ColumnCondition>>() {
            }).forEach(cc -> load(cc, relations));
            return;
        case OR:
        default:
            throw new UnsupportedOperationException("The columnCondition " + condition + " is not supported in cassandra column driver");
    }
}
Also used : ColumnCondition(jakarta.nosql.column.ColumnCondition) Condition(jakarta.nosql.Condition) Column(jakarta.nosql.column.Column) TypeReference(jakarta.nosql.TypeReference) ColumnCondition(jakarta.nosql.column.ColumnCondition)

Example 84 with ColumnCondition

use of jakarta.nosql.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 HBaseException("An error when try to delete columns", e);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ColumnCondition(jakarta.nosql.column.ColumnCondition)

Example 85 with ColumnCondition

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

the class ColumnRepositoryProxyPaginationTest method shouldFindByAgeLessThanEqual.

@Test
public void shouldFindByAgeLessThanEqual() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    personRepository.findByAgeLessThanEqual(33, pagination);
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    ColumnQuery query = captor.getValue();
    ColumnCondition condition = query.getCondition().get();
    assertEquals("Person", query.getColumnFamily());
    assertEquals(LESSER_EQUALS_THAN, condition.getCondition());
    assertEquals(Column.of("age", 33), condition.getColumn());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Pagination(jakarta.nosql.mapping.Pagination) Person(jakarta.nosql.tck.entities.Person) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnCondition (jakarta.nosql.column.ColumnCondition)130 Test (org.junit.jupiter.api.Test)68 ColumnQuery (jakarta.nosql.column.ColumnQuery)64 Column (jakarta.nosql.column.Column)57 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 ValueSource (org.junit.jupiter.params.provider.ValueSource)37 List (java.util.List)34 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)33 Person (jakarta.nosql.tck.entities.Person)17 Pagination (jakarta.nosql.mapping.Pagination)13 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)10 TypeReference (jakarta.nosql.TypeReference)7 Params (jakarta.nosql.Params)6 ColumnEntity (jakarta.nosql.column.ColumnEntity)6 Collections.singletonList (java.util.Collections.singletonList)5 QueryException (jakarta.nosql.QueryException)4 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)4 ColumnFamilyManager (jakarta.nosql.column.ColumnFamilyManager)4 ColumnObserverParser (jakarta.nosql.column.ColumnObserverParser)4 ColumnQueryParams (jakarta.nosql.column.ColumnQueryParams)4