Search in sources :

Example 76 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerTest method shouldReturnListUDT.

@Test
public void shouldReturnListUDT() {
    ColumnEntity entity = createEntityWithIterable();
    entityManager.insert(entity);
    ColumnQuery query = select().from("contacts").where("user").eq("otaviojava").build();
    ColumnEntity columnEntity = entityManager.singleResult(query).get();
    List<List<Column>> names = (List<List<Column>>) columnEntity.find("names").get().get();
    assertEquals(3, names.size());
    assertTrue(names.stream().allMatch(n -> n.size() == 2));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) EmbeddedCassandraServerHelper(org.cassandraunit.utils.EmbeddedCassandraServerHelper) TTransportException(org.apache.thrift.transport.TTransportException) Date(java.util.Date) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery) HashMap(java.util.HashMap) ColumnQueryBuilder.delete(org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete) ConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) Calendar(java.util.Calendar) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) Session(com.datastax.driver.core.Session) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Duration(java.time.Duration) Map(java.util.Map) Columns(org.jnosql.diana.api.column.Columns) Thread.sleep(java.lang.Thread.sleep) Collections.singletonMap(java.util.Collections.singletonMap) NonUniqueResultException(org.jnosql.diana.api.NonUniqueResultException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) KEY_SPACE(org.jnosql.diana.cassandra.column.Constants.KEY_SPACE) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Month(java.time.Month) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) COLUMN_FAMILY(org.jnosql.diana.cassandra.column.Constants.COLUMN_FAMILY) ZoneId(java.time.ZoneId) Column(org.jnosql.diana.api.column.Column) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) LocalDate(com.datastax.driver.core.LocalDate) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ColumnQueryBuilder.select(org.jnosql.diana.api.column.query.ColumnQueryBuilder.select) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Value(org.jnosql.diana.api.Value) Optional(java.util.Optional) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Column(org.jnosql.diana.api.column.Column) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Test(org.junit.jupiter.api.Test)

Example 77 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class QueryUtilsTest method shouldRunEqualsQuerySort.

@Test
public void shouldRunEqualsQuerySort() {
    ColumnQuery query = select().from("collection").where("name").eq("value").orderBy("name").asc().build();
    BuiltStatement select = QueryUtils.select(query, "keyspace");
    String cql = select.toString();
    assertEquals("value", select.getObject(0));
    assertEquals("SELECT * FROM keyspace.collection WHERE name='value' ORDER BY name ASC;", cql);
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) BuiltStatement(com.datastax.driver.core.querybuilder.BuiltStatement) Test(org.junit.jupiter.api.Test)

Example 78 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class QueryUtilsTest method shouldRunEqualsQueryLimit.

@Test
public void shouldRunEqualsQueryLimit() {
    ColumnQuery query = select().from("collection").where("name").eq("value").limit(5).build();
    BuiltStatement select = QueryUtils.select(query, "keyspace");
    String cql = select.toString();
    assertEquals("value", select.getObject(0));
    assertEquals("SELECT * FROM keyspace.collection WHERE name='value' LIMIT 5;", cql);
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) BuiltStatement(com.datastax.driver.core.querybuilder.BuiltStatement) Test(org.junit.jupiter.api.Test)

Example 79 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class QueryUtilsTest method shouldReturnErrorWhenUseNotOperator.

@Test
public void shouldReturnErrorWhenUseNotOperator() {
    ColumnQuery query = select().from("collection").where("name").not().eq("value").build();
    assertThrows(UnsupportedOperationException.class, () -> {
        QueryUtils.select(query, "keyspace");
    });
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Test(org.junit.jupiter.api.Test)

Example 80 with ColumnQuery

use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.

the class QueryUtilsTest method shouldReturnErrorWhenUseOr.

@Test
public void shouldReturnErrorWhenUseOr() {
    ColumnQuery query = select().from("collection").where("name").eq("value").or("age").lte(10).build();
    assertThrows(UnsupportedOperationException.class, () -> {
        QueryUtils.select(query, "keyspace");
    });
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)117 Test (org.junit.jupiter.api.Test)113 Person (org.jnosql.artemis.model.Person)37 ColumnCondition (org.jnosql.diana.api.column.ColumnCondition)35 Column (org.jnosql.diana.api.column.Column)29 List (java.util.List)26 ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)26 Collections.singletonList (java.util.Collections.singletonList)20 ColumnDeleteQuery (org.jnosql.diana.api.column.ColumnDeleteQuery)19 Arrays.asList (java.util.Arrays.asList)15 Duration (java.time.Duration)14 ColumnQueryBuilder.delete (org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete)14 ColumnQueryBuilder.select (org.jnosql.diana.api.column.query.ColumnQueryBuilder.select)14 BeforeEach (org.junit.jupiter.api.BeforeEach)14 Optional (java.util.Optional)13 Consumer (java.util.function.Consumer)13 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)13 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)13 Inject (javax.inject.Inject)12 CDIExtension (org.jnosql.artemis.CDIExtension)12