Search in sources :

Example 11 with DocumentDeleteQuery

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

the class ArangoDBDocumentCollectionManagerTest method shouldRemoveEntity.

@Test
public void shouldRemoveEntity() {
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Document id = documentEntity.find("_key").get();
    DocumentQuery select = 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(select).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 12 with DocumentDeleteQuery

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

the class DefaultCouchbaseDocumentCollectionManager method delete.

@Override
public void delete(DocumentDeleteQuery query) {
    QueryConverter.QueryConverterResult delete = QueryConverter.delete(query, database);
    if (nonNull(delete.getStatement())) {
        ParameterizedN1qlQuery n1qlQuery = N1qlQuery.parameterized(delete.getStatement(), delete.getParams());
        bucket.query(n1qlQuery);
    }
    if (!delete.getKeys().isEmpty()) {
        delete.getKeys().stream().map(s -> getPrefix(query.getDocumentCollection(), s)).forEach(bucket::remove);
    }
}
Also used : Document(org.jnosql.diana.api.document.Document) EntityConverter.getPrefix(org.jnosql.diana.couchbase.document.EntityConverter.getPrefix) Statement(com.couchbase.client.java.query.Statement) ParameterizedN1qlQuery(com.couchbase.client.java.query.ParameterizedN1qlQuery) JsonObject(com.couchbase.client.java.document.json.JsonObject) ArrayList(java.util.ArrayList) JsonDocument(com.couchbase.client.java.document.JsonDocument) Duration(java.time.Duration) Objects.requireNonNull(java.util.Objects.requireNonNull) StreamSupport(java.util.stream.StreamSupport) Collectors.toSet(java.util.stream.Collectors.toSet) N1qlQueryResult(com.couchbase.client.java.query.N1qlQueryResult) KEY_FIELD(org.jnosql.diana.couchbase.document.EntityConverter.KEY_FIELD) Set(java.util.Set) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Bucket(com.couchbase.client.java.Bucket) SearchQueryRow(com.couchbase.client.java.search.result.SearchQueryRow) List(java.util.List) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) N1qlQuery(com.couchbase.client.java.query.N1qlQuery) SearchQuery(com.couchbase.client.java.search.SearchQuery) Objects.nonNull(java.util.Objects.nonNull) ID_FIELD(org.jnosql.diana.couchbase.document.EntityConverter.ID_FIELD) EntityConverter.convert(org.jnosql.diana.couchbase.document.EntityConverter.convert) SearchQueryResult(com.couchbase.client.java.search.result.SearchQueryResult) ParameterizedN1qlQuery(com.couchbase.client.java.query.ParameterizedN1qlQuery)

Example 13 with DocumentDeleteQuery

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

the class CouchbaseDocumentCollectionManagerAsyncTest method setUp.

@BeforeEach
public void setUp() {
    CouchbaseDocumentConfiguration configuration = new CouchbaseDocumentConfiguration();
    CouhbaseDocumentCollectionManagerFactory managerFactory = configuration.get();
    entityManagerAsync = managerFactory.getAsync(CouchbaseUtil.BUCKET_NAME);
    entityManager = managerFactory.get(CouchbaseUtil.BUCKET_NAME);
    DocumentEntity documentEntity = getEntity();
    Document id = documentEntity.find("name").get();
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    entityManagerAsync.delete(deleteQuery);
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with DocumentDeleteQuery

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

the class CouchbaseDocumentCollectionManagerAsyncTest method shouldRemoveEntityAsyncCallBack.

@Test
public void shouldRemoveEntityAsyncCallBack() {
    AtomicBoolean condition = new AtomicBoolean(false);
    AtomicReference<List<DocumentEntity>> references = new AtomicReference<>();
    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();
    entityManagerAsync.delete(deleteQuery, d -> {
        condition.set(true);
    });
    await().untilTrue(condition);
    entityManagerAsync.select(query, references::set);
    await().until(() -> references.get(), notNullValue());
    assertFalse(references.get().isEmpty());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Document(org.jnosql.diana.api.document.Document) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 15 with DocumentDeleteQuery

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

the class CouchbaseDocumentCollectionManagerTest method shouldRemoveEntityByName.

@Test
public void shouldRemoveEntityByName() {
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Document name = documentEntity.find("name").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
    DocumentDeleteQuery deleteQuery = DocumentQueryBuilder.delete().from(COLLECTION_NAME).where(name.getName()).eq(name.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)

Aggregations

DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)86 Test (org.junit.jupiter.api.Test)74 Document (org.jnosql.diana.api.document.Document)35 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)31 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)31 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)20 List (java.util.List)15 Person (org.jnosql.artemis.model.Person)13 Duration (java.time.Duration)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 Optional (java.util.Optional)4 Consumer (java.util.function.Consumer)4 Collectors (java.util.stream.Collectors)4 DocumentQueryBuilder.delete (org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete)4 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)4 Arrays (java.util.Arrays)3