Search in sources :

Example 81 with Column

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

the class CassandraConverter method getUDT.

private static UDT getUDT(ColumnDefinition definition, UdtValue udtValue) {
    String name = definition.getName().asInternal();
    final UserDefinedType type = udtValue.getType();
    List<Column> columns = new ArrayList<>();
    List<String> names = type.getFieldNames().stream().map(CqlIdentifier::asInternal).collect(toList());
    for (CqlIdentifier fieldName : type.getFieldNames()) {
        final int index = names.indexOf(fieldName.asInternal());
        DataType fieldType = type.getFieldTypes().get(index);
        Object elementValue = udtValue.get(fieldName, CodecRegistry.DEFAULT.codecFor(fieldType));
        if (elementValue != null) {
            columns.add(Column.of(fieldName.asInternal(), elementValue));
        }
    }
    return UDT.builder(type.getName().asInternal()).withName(name).addUDT(columns).build();
}
Also used : Column(jakarta.nosql.column.Column) ArrayList(java.util.ArrayList) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) DataType(com.datastax.oss.driver.api.core.type.DataType) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier)

Example 82 with Column

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

the class CassandraColumnFamilyManagerTest method shouldFindByIdWithConsistenceLevel.

@Test
public void shouldFindByIdWithConsistenceLevel() {
    entityManager.insert(getColumnFamily());
    ColumnQuery query = select().from(Constants.COLUMN_FAMILY).where("id").eq(10L).build();
    List<ColumnEntity> columnEntity = entityManager.select(query, CONSISTENCY_LEVEL).collect(toList());
    assertFalse(columnEntity.isEmpty());
    List<Column> columns = columnEntity.get(0).getColumns();
    assertThat(columns.stream().map(Column::getName).collect(toList()), containsInAnyOrder("name", "version", "options", "id"));
    assertThat(columns.stream().map(Column::getValue).map(Value::get).collect(toList()), containsInAnyOrder("Cassandra", 3.2, asList(1, 2, 3), 10L));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) Value(jakarta.nosql.Value) Test(org.junit.jupiter.api.Test)

Example 83 with Column

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

the class CassandraColumnFamilyManagerTest method shouldInsertJustKey.

@Test
public void shouldInsertJustKey() {
    Column key = Columns.of("id", 10L);
    ColumnEntity columnEntity = ColumnEntity.of(Constants.COLUMN_FAMILY);
    columnEntity.add(key);
    entityManager.insert(columnEntity);
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) Test(org.junit.jupiter.api.Test)

Example 84 with Column

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

the class CassandraColumnFamilyManagerTest method shouldSupportAnUDTElement.

@Test
public void shouldSupportAnUDTElement() {
    ColumnEntity entity = ColumnEntity.of("users");
    entity.add(Column.of("nickname", "Ioda"));
    List<Column> columns = new ArrayList<>();
    columns.add(Column.of("firstname", "Ioda"));
    UDT udt = UDT.builder("fullname").withName("name").addUDT(columns).build();
    entity.add(udt);
    entityManager.insert(entity);
    ColumnQuery query = select().from("users").where("nickname").eq("Ioda").build();
    ColumnEntity columnEntity = entityManager.singleResult(query).get();
    Column column = columnEntity.find("name").get();
    udt = UDT.class.cast(column);
    List<Column> udtColumns = (List<Column>) udt.get();
    assertEquals("name", udt.getName());
    assertEquals("fullname", udt.getUserType());
    assertThat(udtColumns, Matchers.containsInAnyOrder(Column.of("firstname", "Ioda")));
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) ArrayList(java.util.ArrayList) 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 85 with Column

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

the class Relations method load.

private static void load(ColumnCondition columnCondition, List<Relation> relations) {
    Column column = columnCondition.getColumn();
    Condition condition = columnCondition.getCondition();
    switch(condition) {
        case EQUALS:
            relations.add(Relation.column(QueryUtils.getName(column)).isEqualTo(getTerm(column)));
            return;
        case GREATER_THAN:
            relations.add(Relation.column(QueryUtils.getName(column)).isGreaterThan(getTerm(column)));
            return;
        case GREATER_EQUALS_THAN:
            relations.add(Relation.column(QueryUtils.getName(column)).isGreaterThanOrEqualTo(getTerm(column)));
            return;
        case LESSER_THAN:
            relations.add(Relation.column(QueryUtils.getName(column)).isLessThan(getTerm(column)));
            return;
        case LESSER_EQUALS_THAN:
            relations.add(Relation.column(QueryUtils.getName(column)).isLessThanOrEqualTo(getTerm(column)));
            return;
        case IN:
            relations.add(Relation.column(QueryUtils.getName(column)).in(getIinValue(column.getValue())));
            return;
        case LIKE:
            relations.add(Relation.column(QueryUtils.getName(column)).like(getTerm(column)));
            return;
        case AND:
            column.get(new TypeReference<List<ColumnCondition>>() {
            }).forEach(cc -> load(cc, relations));
            return;
        case OR:
        default:
            throw new UnsupportedOperationException("The columnCondition " + condition + " is not supported in cassandra column driver");
    }
}
Also used : ColumnCondition(jakarta.nosql.column.ColumnCondition) Condition(jakarta.nosql.Condition) Column(jakarta.nosql.column.Column) TypeReference(jakarta.nosql.TypeReference) ColumnCondition(jakarta.nosql.column.ColumnCondition)

Aggregations

Column (jakarta.nosql.column.Column)113 Test (org.junit.jupiter.api.Test)72 ColumnCondition (jakarta.nosql.column.ColumnCondition)57 ColumnEntity (jakarta.nosql.column.ColumnEntity)39 ColumnQuery (jakarta.nosql.column.ColumnQuery)35 List (java.util.List)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 ValueSource (org.junit.jupiter.params.provider.ValueSource)26 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)24 ArrayList (java.util.ArrayList)13 Value (jakarta.nosql.Value)10 TypeReference (jakarta.nosql.TypeReference)9 Arrays.asList (java.util.Arrays.asList)9 Collections.singletonList (java.util.Collections.singletonList)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)6 Optional (java.util.Optional)4 CqlSession (com.datastax.oss.driver.api.core.CqlSession)3 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)3