Search in sources :

Example 86 with Document

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));
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 87 with Document

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")));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 88 with Document

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());
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition)

Example 89 with Document

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());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 90 with Document

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());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Aggregations

Document (jakarta.nosql.document.Document)196 Test (org.junit.jupiter.api.Test)140 DocumentEntity (jakarta.nosql.document.DocumentEntity)115 DocumentQuery (jakarta.nosql.document.DocumentQuery)93 DocumentCondition (jakarta.nosql.document.DocumentCondition)60 List (java.util.List)60 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)44 Arrays.asList (java.util.Arrays.asList)33 ArrayList (java.util.ArrayList)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 ValueSource (org.junit.jupiter.params.provider.ValueSource)26 TypeReference (jakarta.nosql.TypeReference)21 HashMap (java.util.HashMap)20 Map (java.util.Map)17 Collectors (java.util.stream.Collectors)16 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)14 Matchers.contains (org.hamcrest.Matchers.contains)14 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14