Search in sources :

Example 6 with ColumnCondition

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);
}
Also used : ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 7 with ColumnCondition

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));
}
Also used : Column(jakarta.nosql.column.Column) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 8 with ColumnCondition

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));
}
Also used : List(java.util.List) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 9 with ColumnCondition

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);
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) DeleteQueryConverter(jakarta.nosql.column.DeleteQueryConverter) ColumnFamilyManager(jakarta.nosql.column.ColumnFamilyManager) ColumnCondition(jakarta.nosql.column.ColumnCondition) Collectors(java.util.stream.Collectors) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) DeleteQuery(jakarta.nosql.query.DeleteQuery) List(java.util.List) DeleteQueryProvider(jakarta.nosql.query.DeleteQuery.DeleteQueryProvider) Stream(java.util.stream.Stream) QueryException(jakarta.nosql.QueryException) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnDeleteQueryParams(jakarta.nosql.column.ColumnDeleteQueryParams) ColumnPreparedStatement(jakarta.nosql.column.ColumnPreparedStatement) ColumnObserverParser(jakarta.nosql.column.ColumnObserverParser) Params(jakarta.nosql.Params) ColumnCondition(jakarta.nosql.column.ColumnCondition)

Example 10 with ColumnCondition

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);
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) DeleteQueryConverter(jakarta.nosql.column.DeleteQueryConverter) ColumnFamilyManager(jakarta.nosql.column.ColumnFamilyManager) ColumnCondition(jakarta.nosql.column.ColumnCondition) Collectors(java.util.stream.Collectors) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) DeleteQuery(jakarta.nosql.query.DeleteQuery) List(java.util.List) DeleteQueryProvider(jakarta.nosql.query.DeleteQuery.DeleteQueryProvider) Stream(java.util.stream.Stream) QueryException(jakarta.nosql.QueryException) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnDeleteQueryParams(jakarta.nosql.column.ColumnDeleteQueryParams) ColumnPreparedStatement(jakarta.nosql.column.ColumnPreparedStatement) ColumnObserverParser(jakarta.nosql.column.ColumnObserverParser) Params(jakarta.nosql.Params) QueryException(jakarta.nosql.QueryException) ColumnDeleteQueryParams(jakarta.nosql.column.ColumnDeleteQueryParams) Params(jakarta.nosql.Params) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) DeleteQuery(jakarta.nosql.query.DeleteQuery) ColumnCondition(jakarta.nosql.column.ColumnCondition)

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