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