Search in sources :

Example 76 with ColumnCondition

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

the class DefaultColumnConditionTest method shouldCreateOrCondition.

@Test
public void shouldCreateOrCondition() {
    Column age = Column.of("age", 26);
    Column name = Column.of("name", "Otavio");
    ColumnCondition condition1 = DefaultColumnCondition.of(name, Condition.EQUALS);
    ColumnCondition condition2 = DefaultColumnCondition.of(age, Condition.GREATER_THAN);
    ColumnCondition and = condition1.or(condition2);
    Column andColumn = and.getColumn();
    assertEquals(Condition.OR, and.getCondition());
    assertEquals(Condition.OR.getNameField(), andColumn.getName());
    assertThat(andColumn.getValue().get(new TypeReference<List<ColumnCondition>>() {
    }), Matchers.containsInAnyOrder(condition1, condition2));
}
Also used : Column(jakarta.nosql.column.Column) TypeReference(jakarta.nosql.TypeReference) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 77 with ColumnCondition

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

the class DefaultColumnConditionTest method shouldAffirmDoubleNegate.

@Test
public void shouldAffirmDoubleNegate() {
    ColumnCondition eq = ColumnCondition.eq(Column.of("name", "otavio"));
    ColumnCondition affirm = eq.negate().negate();
    assertEquals(eq.getCondition(), affirm.getCondition());
}
Also used : ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 78 with ColumnCondition

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

the class DefaultColumnConditionTest method shouldOr.

@Test
public void shouldOr() {
    ColumnCondition eq = ColumnCondition.eq(Column.of("name", "otavio"));
    ColumnCondition gt = ColumnCondition.gt(Column.of("age", 10));
    ColumnCondition lte = ColumnCondition.lte(Column.of("salary", 10_000.00));
    ColumnCondition or = eq.or(gt);
    List<ColumnCondition> conditions = or.getColumn().get(new TypeReference<List<ColumnCondition>>() {
    });
    assertEquals(Condition.OR, or.getCondition());
    assertThat(conditions, Matchers.containsInAnyOrder(eq, gt));
    ColumnCondition result = or.or(lte);
    assertEquals(Condition.OR, result.getCondition());
    assertThat(result.getColumn().get(new TypeReference<List<ColumnCondition>>() {
    }), Matchers.containsInAnyOrder(eq, gt, lte));
}
Also used : List(java.util.List) TypeReference(jakarta.nosql.TypeReference) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 79 with ColumnCondition

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

the class BaseQueryBuilder method appendCondition.

protected void appendCondition(ColumnCondition newCondition) {
    ColumnCondition columnCondition = getColumnCondition(newCondition);
    if (nonNull(condition)) {
        if (and) {
            this.condition = condition.and(columnCondition);
        } else {
            this.condition = condition.or(columnCondition);
        }
    } else {
        this.condition = columnCondition;
    }
    this.negate = false;
    this.name = null;
}
Also used : ColumnCondition(jakarta.nosql.column.ColumnCondition)

Example 80 with ColumnCondition

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

the class BaseQueryBuilder method gteImpl.

protected <T> void gteImpl(T value) {
    requireNonNull(value, "value is required");
    ColumnCondition newCondition = ColumnCondition.gte(Column.of(name, value));
    appendCondition(newCondition);
}
Also used : 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