use of org.jnosql.diana.api.document.Document in project jnosql-diana by eclipse.
the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameEq.
@Test
public void shouldSelectWhereNameEq() {
String documentCollection = "documentCollection";
String name = "Ada Lovelace";
DocumentQuery query = select().from(documentCollection).where("name").eq(name).build();
DocumentCondition condition = query.getCondition().get();
Document document = condition.getDocument();
assertTrue(query.getDocuments().isEmpty());
assertEquals(documentCollection, query.getDocumentCollection());
assertEquals(Condition.EQUALS, condition.getCondition());
assertEquals("name", document.getName());
assertEquals(name, document.get());
}
use of org.jnosql.diana.api.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 org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerAsyncTest method shouldSelect.
@Test
public void shouldSelect() {
DocumentEntity entity = getEntity();
AtomicReference<DocumentEntity> reference = new AtomicReference<>();
AtomicBoolean condition = new AtomicBoolean(false);
entityManagerAsync.insert(entity, d -> {
condition.set(true);
reference.set(d);
});
await().untilTrue(condition);
DocumentEntity entity1 = reference.get();
Document key = entity1.find("_key").get();
condition.set(false);
AtomicReference<List<DocumentEntity>> references = new AtomicReference<>();
entityManagerAsync.select(select().from(entity1.getName()).where("_key").eq(key.get()).build(), l -> {
condition.set(true);
references.set(l);
});
await().untilTrue(condition);
List<DocumentEntity> entities = references.get();
assertFalse(entities.isEmpty());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerAsyncTest method getEntity.
private DocumentEntity getEntity() {
DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
Map<String, Object> map = new HashMap<>();
map.put("name", "Poliana");
map.put("city", "Salvador");
entity.add(Document.of(KEY_NAME, random.nextLong()));
List<Document> documents = Documents.of(map);
documents.forEach(entity::add);
return entity;
}
use of org.jnosql.diana.api.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);
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());
}
Aggregations