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));
}
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());
}
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());
}
}
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))));
}
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());
}
Aggregations