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