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;
}
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);
}
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;
}
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());
}
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(""));
}
Aggregations