use of jakarta.nosql.CommunicationException 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.CommunicationException in project jnosql-diana-driver by eclipse.
the class DefaultElasticsearchDocumentCollectionManager method count.
@Override
public long count(String documentCollection) {
Objects.requireNonNull(documentCollection, "query is required");
SearchRequest searchRequest = new SearchRequest(index);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.size(0);
try {
SearchResponse search = client.search(searchRequest, RequestOptions.DEFAULT);
return search.getHits().getTotalHits().value;
} catch (IOException e) {
throw new CommunicationException("Error on ES when try to execute count to document collection:" + documentCollection, e);
}
}
Aggregations