use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldSQL2.
@Test
public void shouldSQL2() {
DocumentEntity entity = entityManager.insert(getEntity());
Optional<Document> id = entity.find("name");
List<DocumentEntity> entities = entityManager.sql("select * from person where name = :name", singletonMap("name", id.get().get())).collect(Collectors.toList());
assertFalse(entities.isEmpty());
assertThat(entities, contains(entity));
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldSaveSubDocument2.
@Test
public void shouldSaveSubDocument2() {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", Arrays.asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
DocumentEntity entitySaved = entityManager.insert(entity);
Document id = entitySaved.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentEntity entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
Document subDocument = entityFound.find("phones").get();
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
});
assertThat(documents, containsInAnyOrder(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class QueryOSQLConverter method definesCondition.
private static void definesCondition(DocumentCondition condition, StringBuilder query, List<Object> params, int counter, List<ORecordId> ids) {
Document document = condition.getDocument();
switch(condition.getCondition()) {
case IN:
appendCondition(query, params, document, IN, ids);
return;
case EQUALS:
appendCondition(query, params, document, EQUALS, ids);
return;
case GREATER_EQUALS_THAN:
appendCondition(query, params, document, GREATER_EQUALS_THAN, ids);
return;
case GREATER_THAN:
appendCondition(query, params, document, GREATER_THAN, ids);
return;
case LESSER_THAN:
appendCondition(query, params, document, LESSER_THAN, ids);
return;
case LESSER_EQUALS_THAN:
appendCondition(query, params, document, LESSER_EQUALS_THAN, ids);
return;
case LIKE:
appendCondition(query, params, document, LIKE, ids);
return;
case AND:
for (DocumentCondition dc : document.get(new TypeReference<List<DocumentCondition>>() {
})) {
if (isFirstCondition(query, counter)) {
query.append(AND);
}
definesCondition(dc, query, params, ++counter, ids);
}
return;
case OR:
for (DocumentCondition dc : document.get(new TypeReference<List<DocumentCondition>>() {
})) {
if (isFirstCondition(query, counter)) {
query.append(OR);
}
definesCondition(dc, query, params, ++counter, ids);
}
return;
case NOT:
DocumentCondition documentCondition = document.get(DocumentCondition.class);
query.append("NOT (");
definesCondition(documentCondition, query, params, ++counter, ids);
query.append(")");
return;
default:
throw new IllegalArgumentException("Orient DB has not support to the condition " + condition.getCondition());
}
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldUpdateWithRetry.
@Test
public void shouldUpdateWithRetry() {
DocumentEntity entity = entityManager.insert(getEntity());
entity.add(Document.of(OrientDBConverter.VERSION_FIELD, 0));
Document newField = Documents.of("newField", "99");
entity.add(newField);
entityManager.update(entity);
Document id = entity.find(OrientDBConverter.RID_FIELD).get();
DocumentQuery query = select().from(entity.getName()).where(id.getName()).eq(id.get()).build();
Optional<DocumentEntity> updated = entityManager.singleResult(query);
assertTrue(updated.isPresent());
assertEquals(newField, updated.get().find(newField.getName()).get());
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class DefaultSolrDocumentCollectionManagerTest method shouldFindDocument.
@Test
public void shouldFindDocument() {
DocumentEntity entity = entityManager.insert(getEntity());
Optional<Document> id = entity.find(ID);
DocumentQuery query = select().from(COLLECTION_NAME).where(ID).eq(id.get().get()).build();
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
assertFalse(entities.isEmpty());
final DocumentEntity result = entities.get(0);
assertEquals(entity.find("name").get(), result.find("name").get());
assertEquals(entity.find("city").get(), result.find("city").get());
}
Aggregations