use of jakarta.nosql.document.Document in project jnosql-diana by eclipse.
the class DefaultDocumentEntityConverterTest method shouldConvertSubEntity.
@Test
public void shouldConvertSubEntity() {
ZipCode zipcode = new ZipCode();
zipcode.setZip("12321");
zipcode.setPlusFour("1234");
Address address = new Address();
address.setCity("Salvador");
address.setState("Bahia");
address.setStreet("Rua Engenheiro Jose Anasoh");
address.setZipCode(zipcode);
DocumentEntity documentEntity = converter.toDocument(address);
List<Document> documents = documentEntity.getDocuments();
assertEquals("Address", documentEntity.getName());
assertEquals(4, documents.size());
List<Document> zip = documentEntity.find("zipCode").map(d -> d.get(new TypeReference<List<Document>>() {
})).orElse(Collections.emptyList());
assertEquals("Rua Engenheiro Jose Anasoh", getValue(documentEntity.find("street")));
assertEquals("Salvador", getValue(documentEntity.find("city")));
assertEquals("Bahia", getValue(documentEntity.find("state")));
assertEquals("12321", getValue(zip.stream().filter(d -> d.getName().equals("zip")).findFirst()));
assertEquals("1234", getValue(zip.stream().filter(d -> d.getName().equals("plusFour")).findFirst()));
}
use of jakarta.nosql.document.Document in project jnosql-diana by eclipse.
the class ParamsBinderTest method shouldConvert2.
@Test
public void shouldConvert2() {
Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals("findByAgeAndName")).findFirst().get();
ClassMapping classMapping = mappings.get(Person.class);
RepositoryDocumentObserverParser parser = new RepositoryDocumentObserverParser(classMapping);
paramsBinder = new ParamsBinder(classMapping, converters);
SelectMethodProvider selectMethodFactory = SelectMethodProvider.get();
SelectQuery selectQuery = selectMethodFactory.apply(method, classMapping.getName());
SelectQueryConverter converter = ServiceLoaderProvider.get(SelectQueryConverter.class);
DocumentQueryParams queryParams = converter.apply(selectQuery, parser);
Params params = queryParams.getParams();
paramsBinder.bind(params, new Object[] { 10L, "Ada" }, method);
DocumentQuery query = queryParams.getQuery();
DocumentCondition columnCondition = query.getCondition().get();
List<DocumentCondition> conditions = columnCondition.getDocument().get(new TypeReference<List<DocumentCondition>>() {
});
List<Object> values = conditions.stream().map(DocumentCondition::getDocument).map(Document::getValue).map(Value::get).collect(Collectors.toList());
assertEquals(10, values.get(0));
assertEquals("Ada", values.get(1));
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class QueryAQLConverter method definesCondition.
private static void definesCondition(DocumentCondition condition, StringBuilder aql, Map<String, Object> params, char entity, int counter) {
Document document = condition.getDocument();
switch(condition.getCondition()) {
case IN:
appendCondition(aql, params, entity, document, IN);
return;
case EQUALS:
appendCondition(aql, params, entity, document, EQUALS);
return;
case GREATER_EQUALS_THAN:
appendCondition(aql, params, entity, document, GREATER_EQUALS_THAN);
return;
case GREATER_THAN:
appendCondition(aql, params, entity, document, GREATER_THAN);
return;
case LESSER_THAN:
appendCondition(aql, params, entity, document, LESSER_THAN);
return;
case LESSER_EQUALS_THAN:
appendCondition(aql, params, entity, document, LESSER_EQUALS_THAN);
return;
case LIKE:
appendCondition(aql, params, entity, document, LIKE);
return;
case AND:
for (DocumentCondition dc : document.get(new TypeReference<List<DocumentCondition>>() {
})) {
if (isFirstCondition(aql, counter)) {
aql.append(AND);
}
definesCondition(dc, aql, params, entity, ++counter);
}
return;
case OR:
for (DocumentCondition dc : document.get(new TypeReference<List<DocumentCondition>>() {
})) {
if (isFirstCondition(aql, counter)) {
aql.append(OR);
}
definesCondition(dc, aql, params, entity, ++counter);
}
return;
case NOT:
DocumentCondition documentCondition = document.get(DocumentCondition.class);
aql.append(NOT);
definesCondition(documentCondition, aql, params, entity, ++counter);
return;
default:
throw new IllegalArgumentException("The condition does not support in AQL: " + condition.getCondition());
}
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method shouldFindDocument.
@Test
public void shouldFindDocument() {
DocumentEntity entity = entityManager.insert(getEntity());
Document id = entity.find(KEY_NAME).get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
assertFalse(entities.isEmpty());
DocumentEntity documentEntity = entities.get(0);
assertEquals(entity.find(KEY_NAME).get().getValue().get(String.class), documentEntity.find(KEY_NAME).get().getValue().get(String.class));
assertEquals(entity.find("name").get(), documentEntity.find("name").get());
assertEquals(entity.find("city").get(), documentEntity.find("city").get());
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method shouldRetrieveListSubdocumentList.
@Test
public void shouldRetrieveListSubdocumentList() {
DocumentEntity entity = entityManager.insert(createSubdocumentList());
Document key = entity.find(KEY_NAME).get();
DocumentQuery query = select().from("AppointmentBook").where(key.getName()).eq(key.get()).build();
DocumentEntity documentEntity = entityManager.singleResult(query).get();
assertNotNull(documentEntity);
List<List<Document>> contacts = (List<List<Document>>) documentEntity.find("contacts").get().get();
assertEquals(3, contacts.size());
assertTrue(contacts.stream().allMatch(d -> d.size() == 3));
}
Aggregations