Search in sources :

Example 71 with Document

use of org.jnosql.diana.api.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()));
    assertFalse(entities.isEmpty());
    assertThat(entities, contains(entity));
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 72 with Document

use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.

the class OrientDBDocumentCollectionManagerTest method shouldRemoveEntity.

@Test
public void shouldRemoveEntity() {
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Document id = documentEntity.find("name").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    entityManager.delete(deleteQuery);
    assertTrue(entityManager.select(query).isEmpty());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 73 with Document

use of org.jnosql.diana.api.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) {
    Document document = condition.getDocument();
    switch(condition.getCondition()) {
        case IN:
            appendCondition(query, params, document, IN);
            return;
        case EQUALS:
            appendCondition(query, params, document, EQUALS);
            return;
        case GREATER_EQUALS_THAN:
            appendCondition(query, params, document, GREATER_EQUALS_THAN);
            return;
        case GREATER_THAN:
            appendCondition(query, params, document, GREATER_THAN);
            return;
        case LESSER_THAN:
            appendCondition(query, params, document, LESSER_THAN);
            return;
        case LESSER_EQUALS_THAN:
            appendCondition(query, params, document, LESSER_EQUALS_THAN);
            return;
        case LIKE:
            appendCondition(query, params, document, LIKE);
            return;
        case AND:
            for (DocumentCondition dc : document.get(new TypeReference<List<DocumentCondition>>() {
            })) {
                if (isFirstCondition(query, counter)) {
                    query.append(AND);
                }
                definesCondition(dc, query, params, ++counter);
            }
            return;
        case OR:
            for (DocumentCondition dc : document.get(new TypeReference<List<DocumentCondition>>() {
            })) {
                if (isFirstCondition(query, counter)) {
                    query.append(OR);
                }
                definesCondition(dc, query, params, ++counter);
            }
            return;
        case NOT:
            DocumentCondition documentCondition = document.get(DocumentCondition.class);
            query.append("NOT (");
            definesCondition(documentCondition, query, params, ++counter);
            query.append(")");
            return;
        default:
            throw new IllegalArgumentException("Orient DB has not support to the condition " + condition.getCondition());
    }
}
Also used : List(java.util.List) Document(org.jnosql.diana.api.document.Document) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition)

Example 74 with Document

use of org.jnosql.diana.api.document.Document in project jnosql-diana by eclipse.

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameOr.

@Test
public void shouldSelectWhereNameOr() {
    String documentCollection = "documentCollection";
    String name = "Ada Lovelace";
    DocumentDeleteQuery query = delete().from(documentCollection).where("name").eq(name).or("age").gt(10).build();
    DocumentCondition condition = query.getCondition().get();
    Document document = condition.getDocument();
    List<DocumentCondition> conditions = document.get(new TypeReference<List<DocumentCondition>>() {
    });
    assertEquals(Condition.OR, condition.getCondition());
    assertThat(conditions, Matchers.containsInAnyOrder(eq(Document.of("name", name)), DocumentCondition.gt(Document.of("age", 10))));
}
Also used : List(java.util.List) Document(org.jnosql.diana.api.document.Document) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 75 with Document

use of org.jnosql.diana.api.document.Document in project jnosql-diana by eclipse.

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameEq.

@Test
public void shouldSelectWhereNameEq() {
    String documentCollection = "documentCollection";
    String name = "Ada Lovelace";
    DocumentDeleteQuery query = delete().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());
}
Also used : Document(org.jnosql.diana.api.document.Document) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Aggregations

Document (org.jnosql.diana.api.document.Document)126 Test (org.junit.jupiter.api.Test)102 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)94 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)71 List (java.util.List)41 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)37 ArrayList (java.util.ArrayList)25 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)25 Arrays.asList (java.util.Arrays.asList)23 HashMap (java.util.HashMap)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 Map (java.util.Map)11 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)11 TypeReference (org.jnosql.diana.api.TypeReference)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 Matchers.contains (org.hamcrest.Matchers.contains)10 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)10 Arrays (java.util.Arrays)8 Optional (java.util.Optional)8 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)8