Search in sources :

Example 81 with ColumnQuery

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

the class QueryUtils method select.

public static Select select(ColumnQuery query, String keyspace) {
    String columnFamily = query.getColumnFamily();
    final List<String> columns = query.getColumns();
    Select select = null;
    if (columns.isEmpty()) {
        select = QueryBuilder.selectFrom(keyspace, columnFamily).all();
    } else {
        select = QueryBuilder.selectFrom(keyspace, columnFamily).columns(columns);
    }
    select = select.where(Relations.createClause(query.getCondition().orElse(null)));
    final Map<String, ClusteringOrder> sort = query.getSorts().stream().collect(Collectors.toMap(s -> s.getName(), mapSort()));
    select = select.orderBy(sort);
    return select;
}
Also used : QueryBuilder(com.datastax.oss.driver.api.querybuilder.QueryBuilder) SortType(jakarta.nosql.SortType) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) Insert(com.datastax.oss.driver.api.querybuilder.insert.Insert) HashMap(java.util.HashMap) Function(java.util.function.Function) ValueUtil(org.eclipse.jnosql.communication.driver.ValueUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Duration(java.time.Duration) Map(java.util.Map) InsertInto(com.datastax.oss.driver.api.querybuilder.insert.InsertInto) Select(com.datastax.oss.driver.api.querybuilder.select.Select) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) ColumnEntity(jakarta.nosql.column.ColumnEntity) CodecRegistry(com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry) Collection(java.util.Collection) DataType(com.datastax.oss.driver.api.core.type.DataType) Collectors(java.util.stream.Collectors) UdtValue(com.datastax.oss.driver.api.core.data.UdtValue) ColumnMetadata(com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata) ProtocolConstants(com.datastax.oss.protocol.internal.ProtocolConstants) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) Value(jakarta.nosql.Value) List(java.util.List) Column(jakarta.nosql.column.Column) CodecNotFoundException(com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException) TypeCodec(com.datastax.oss.driver.api.core.type.codec.TypeCodec) Optional(java.util.Optional) SetType(com.datastax.oss.driver.api.core.type.SetType) Term(com.datastax.oss.driver.api.querybuilder.term.Term) ColumnQuery(jakarta.nosql.column.ColumnQuery) Sort(jakarta.nosql.Sort) CommunicationException(jakarta.nosql.CommunicationException) Select(com.datastax.oss.driver.api.querybuilder.select.Select) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)

Example 82 with ColumnQuery

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

the class HBaseColumnFamilyManagerTest method shouldFindInBatch.

@Test
public void shouldFindInBatch() {
    columnFamilyManager.insert(createEntity());
    columnFamilyManager.insert(createEntity2());
    ColumnQuery query = select().from(FAMILY).where(ID_FIELD).eq("otaviojava").or(ID_FIELD).eq("poliana").build();
    List<ColumnEntity> entities = columnFamilyManager.select(query).collect(Collectors.toList());
    assertEquals(Integer.valueOf(2), Integer.valueOf(entities.size()));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Example 83 with ColumnQuery

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

the class HBaseColumnFamilyManagerTest method shouldFind.

@Test
public void shouldFind() {
    columnFamilyManager.insert(createEntity());
    ColumnQuery query = select().from(FAMILY).where(ID_FIELD).eq("otaviojava").build();
    List<ColumnEntity> columnFamilyEntities = columnFamilyManager.select(query).collect(Collectors.toList());
    assertNotNull(columnFamilyEntities);
    assertFalse(columnFamilyEntities.isEmpty());
    ColumnEntity entity = columnFamilyEntities.get(0);
    assertEquals(FAMILY, entity.getName());
    assertThat(entity.getColumns(), containsInAnyOrder(Column.of(ID_FIELD, "otaviojava"), Column.of("age", "26"), Column.of("country", "Brazil")));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Example 84 with ColumnQuery

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

the class HBaseColumnFamilyManagerTest method shouldDeleteEntities.

@Test
public void shouldDeleteEntities() {
    columnFamilyManager.insert(createEntity());
    columnFamilyManager.insert(createEntity2());
    ColumnQuery query = select().from(FAMILY).where(ID_FIELD).eq("otaviojava").or(ID_FIELD).eq("poliana").build();
    ColumnDeleteQuery deleteQuery = delete().from(FAMILY).where(ID_FIELD).eq("otaviojava").or(ID_FIELD).eq("poliana").build();
    columnFamilyManager.delete(deleteQuery);
    List<ColumnEntity> entities = columnFamilyManager.select(query).collect(Collectors.toList());
    assertTrue(entities.isEmpty());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 85 with ColumnQuery

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

the class HBaseColumnFamilyManagerTest method shouldDeleteEntity.

@Test
public void shouldDeleteEntity() {
    columnFamilyManager.insert(createEntity());
    ColumnQuery query = select().from(FAMILY).where(ID_FIELD).eq("otaviojava").build();
    ColumnDeleteQuery deleteQuery = delete().from(FAMILY).where(ID_FIELD).eq("otaviojava").build();
    columnFamilyManager.delete(deleteQuery);
    List<ColumnEntity> entities = columnFamilyManager.select(query).collect(Collectors.toList());
    assertTrue(entities.isEmpty());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnQuery (jakarta.nosql.column.ColumnQuery)160 Test (org.junit.jupiter.api.Test)120 ColumnCondition (jakarta.nosql.column.ColumnCondition)64 Person (jakarta.nosql.tck.entities.Person)50 Column (jakarta.nosql.column.Column)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)30 ValueSource (org.junit.jupiter.params.provider.ValueSource)30 Pagination (jakarta.nosql.mapping.Pagination)27 ColumnEntity (jakarta.nosql.column.ColumnEntity)26 List (java.util.List)26 Collections.singletonList (java.util.Collections.singletonList)10 Value (jakarta.nosql.Value)8 ColumnQueryPagination (jakarta.nosql.mapping.column.ColumnQueryPagination)8 Arrays.asList (java.util.Arrays.asList)8 Params (jakarta.nosql.Params)7 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)7 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)7 ColumnQueryParams (jakarta.nosql.column.ColumnQueryParams)7 ColumnTemplate (jakarta.nosql.mapping.column.ColumnTemplate)6 SelectQuery (jakarta.nosql.query.SelectQuery)6