Search in sources :

Example 71 with ColumnCondition

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

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameLt.

@Test
public void shouldSelectWhereNameLt() {
    String columnFamily = "columnFamily";
    Number value = 10;
    ColumnQuery query = select().from(columnFamily).where("name").lt(value).build();
    ColumnCondition condition = query.getCondition().get();
    Column column = condition.getColumn();
    assertTrue(query.getColumns().isEmpty());
    assertEquals(columnFamily, query.getColumnFamily());
    assertEquals(Condition.LESSER_THAN, condition.getCondition());
    assertEquals("name", column.getName());
    assertEquals(value, column.get());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Column(jakarta.nosql.column.Column) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 72 with ColumnCondition

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

the class DefaultColumnConditionTest method shouldAnd.

@Test
public void shouldAnd() {
    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 and = eq.and(gt);
    List<ColumnCondition> conditions = and.getColumn().get(new TypeReference<List<ColumnCondition>>() {
    });
    assertEquals(Condition.AND, and.getCondition());
    assertThat(conditions, Matchers.containsInAnyOrder(eq, gt));
    ColumnCondition result = and.and(lte);
    assertEquals(Condition.AND, 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 73 with ColumnCondition

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

the class DefaultColumnConditionTest method shouldCreateAnInstance.

@Test
public void shouldCreateAnInstance() {
    Column name = Column.of("name", "Otavio");
    ColumnCondition condition = DefaultColumnCondition.of(name, Condition.EQUALS);
    assertNotNull(condition);
    assertEquals(name, condition.getColumn());
    assertEquals(Condition.EQUALS, condition.getCondition());
}
Also used : Column(jakarta.nosql.column.Column) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 74 with ColumnCondition

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

the class DefaultColumnConditionTest method shouldCreateAndCondition.

@Test
public void shouldCreateAndCondition() {
    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.and(condition2);
    Column andColumn = and.getColumn();
    assertEquals(Condition.AND, and.getCondition());
    assertEquals(Condition.AND.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 75 with ColumnCondition

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

the class DefaultColumnConditionTest method shouldCreateNegationCondition.

@Test
public void shouldCreateNegationCondition() {
    Column age = Column.of("age", 26);
    ColumnCondition condition = DefaultColumnCondition.of(age, Condition.GREATER_THAN);
    ColumnCondition negate = condition.negate();
    Column negateColumn = negate.getColumn();
    assertEquals(Condition.NOT, negate.getCondition());
    assertEquals(Condition.NOT.getNameField(), negateColumn.getName());
    assertEquals(DefaultColumnCondition.of(age, Condition.GREATER_THAN), negateColumn.getValue().get());
}
Also used : Column(jakarta.nosql.column.Column) 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