Search in sources :

Example 46 with Column

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

the class CassandraConverter method getColumns.

private static Iterable<Iterable<Column>> getColumns(ColumnDefinition definition, Object result) {
    List<Iterable<Column>> columns = new ArrayList<>();
    for (Object value : Iterable.class.cast(result)) {
        final UdtValue udtValue = UdtValue.class.cast(value);
        final UDT udt = getUDT(definition, udtValue);
        columns.add((Iterable<Column>) udt.get());
    }
    return columns;
}
Also used : UdtValue(com.datastax.oss.driver.api.core.data.UdtValue) Column(jakarta.nosql.column.Column) ArrayList(java.util.ArrayList)

Example 47 with Column

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

the class CassandraConverter method toDocumentEntity.

public static ColumnEntity toDocumentEntity(Row row) {
    List<Column> columns = new ArrayList<>();
    String columnFamily = "";
    for (ColumnDefinition definition : row.getColumnDefinitions()) {
        columnFamily = definition.getTable().asInternal();
        Object result = CassandraConverter.get(definition, row);
        if (Objects.nonNull(result)) {
            columns.add(getColumn(definition, result));
        }
    }
    return ColumnEntity.of(columnFamily, columns);
}
Also used : Column(jakarta.nosql.column.Column) ArrayList(java.util.ArrayList) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition)

Example 48 with Column

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

the class QueryUtils method getUdtValue.

private static Object getUdtValue(UserDefinedType userType, Iterable elements, DataType type) {
    Collection<Object> udtValues = getCollectionUdt(type);
    UdtValue udtValue = userType.newValue();
    final List<String> udtNames = userType.getFieldNames().stream().map(CqlIdentifier::asInternal).collect(Collectors.toList());
    for (Object object : elements) {
        if (Column.class.isInstance(object)) {
            Column column = Column.class.cast(object);
            Object convert = ValueUtil.convert(column.getValue());
            final int index = udtNames.indexOf(column.getName());
            if (index < 0) {
                throw new CommunicationException("This field has not been found: " + column.getName() + " the fields available are " + udtNames + " in the UDT type " + userType.getName().asCql(true) + " at the keyspace " + userType.getKeyspace());
            }
            DataType fieldType = userType.getFieldTypes().get(index);
            TypeCodec<Object> objectTypeCodec = CodecRegistry.DEFAULT.codecFor(fieldType);
            if (fieldType instanceof SetType) {
                udtValue.set(getName(column), new HashSet<Object>((Collection<?>) convert), objectTypeCodec);
            } else {
                udtValue.set(getName(column), convert, objectTypeCodec);
            }
        } else if (Iterable.class.isInstance(object)) {
            udtValues.add(getUdtValue(userType, Iterable.class.cast(Iterable.class.cast(object)), type));
        }
    }
    if (udtValues.isEmpty()) {
        return udtValue;
    }
    return udtValues;
}
Also used : UdtValue(com.datastax.oss.driver.api.core.data.UdtValue) CommunicationException(jakarta.nosql.CommunicationException) Column(jakarta.nosql.column.Column) SetType(com.datastax.oss.driver.api.core.type.SetType) DataType(com.datastax.oss.driver.api.core.type.DataType) Collection(java.util.Collection)

Example 49 with Column

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

the class ColumnEntityTest method shouldNotFindColumn.

@Test
public void shouldNotFindColumn() {
    ColumnEntity entity = new DefaultColumnEntity("name");
    Optional<Column> column = entity.find("name");
    assertFalse(column.isPresent());
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) Test(org.junit.jupiter.api.Test)

Example 50 with Column

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

the class ColumnEntityTest method shouldFindValue.

@Test
public void shouldFindValue() {
    Column column = Column.of("name", "name");
    ColumnEntity entity = ColumnEntity.of("entity", singletonList(column));
    Optional<String> name = entity.find("name", String.class);
    Assertions.assertNotNull(name);
    Assertions.assertTrue(name.isPresent());
    Assertions.assertEquals("name", name.orElse(""));
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) Test(org.junit.jupiter.api.Test)

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