Search in sources :

Example 96 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana-driver by eclipse.

the class MongoDBDocumentCollectionManagerTest method shouldRemoveEntity.

@Test
public void shouldRemoveEntity() {
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Optional<Document> id = documentEntity.find("_id");
    DocumentQuery query = select().from(COLLECTION_NAME).where("_id").eq(id.get().get()).build();
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where("_id").eq(id.get().get()).build();
    entityManager.delete(deleteQuery);
    assertTrue(entityManager.select(query).collect(Collectors.toList()).isEmpty());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 97 with DocumentDeleteQuery

use of jakarta.nosql.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 : Statement(com.couchbase.client.java.query.Statement) ParameterizedN1qlQuery(com.couchbase.client.java.query.ParameterizedN1qlQuery) ID_FIELD(org.eclipse.jnosql.communication.couchbase.document.EntityConverter.ID_FIELD) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) JsonObject(com.couchbase.client.java.document.json.JsonObject) JsonDocument(com.couchbase.client.java.document.JsonDocument) DocumentQuery(jakarta.nosql.document.DocumentQuery) Duration(java.time.Duration) Objects.requireNonNull(java.util.Objects.requireNonNull) StreamSupport(java.util.stream.StreamSupport) EntityConverter.convert(org.eclipse.jnosql.communication.couchbase.document.EntityConverter.convert) N1qlQueryResult(com.couchbase.client.java.query.N1qlQueryResult) KEY_FIELD(org.eclipse.jnosql.communication.couchbase.document.EntityConverter.KEY_FIELD) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Bucket(com.couchbase.client.java.Bucket) SearchQueryRow(com.couchbase.client.java.search.result.SearchQueryRow) Stream(java.util.stream.Stream) EntityConverter.getPrefix(org.eclipse.jnosql.communication.couchbase.document.EntityConverter.getPrefix) N1qlQuery(com.couchbase.client.java.query.N1qlQuery) SearchQuery(com.couchbase.client.java.search.SearchQuery) Objects.nonNull(java.util.Objects.nonNull) SearchQueryResult(com.couchbase.client.java.search.result.SearchQueryResult) ParameterizedN1qlQuery(com.couchbase.client.java.query.ParameterizedN1qlQuery)

Example 98 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana-driver by eclipse.

the class ElasticsearchDocumentCollectionManagerTest method setUp.

@BeforeEach
public void setUp() {
    ElasticsearchDocumentCollectionManagerFactory managerFactory = ElasticsearchDocumentCollectionManagerFactorySupplier.INSTANCE.get();
    entityManager = managerFactory.get(DocumentEntityGerator.INDEX);
    DocumentDeleteQuery deleteQuery = DocumentDeleteQuery.delete().from("person").build();
    entityManager.delete(deleteQuery);
}
Also used : DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 99 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana-driver by eclipse.

the class DefaultSolrDocumentCollectionManagerTest method shouldExecuteNativeQueryParamsReplaceAll.

@Test
public void shouldExecuteNativeQueryParamsReplaceAll() {
    entityManager.insert(getEntitiesWithValues());
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).build();
    entityManager.delete(deleteQuery);
    entityManager.insert(getEntitiesWithValues());
    Map<String, Object> params = new HashMap<>();
    params.put("age", 22);
    List<DocumentEntity> entitiesFound = entityManager.solr("age:@age AND age:@age", params);
    assertEquals(1, entitiesFound.size());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) HashMap(java.util.HashMap) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 100 with DocumentDeleteQuery

use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana-driver by eclipse.

the class DefaultSolrDocumentCollectionManagerTest method shouldFindDocumentStart.

@Test
public void shouldFindDocumentStart() {
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).build();
    entityManager.delete(deleteQuery);
    Iterable<DocumentEntity> entitiesSaved = entityManager.insert(getEntitiesWithValues());
    List<DocumentEntity> entities = StreamSupport.stream(entitiesSaved.spliterator(), false).collect(Collectors.toList());
    DocumentQuery query = select().from(COLLECTION_NAME).where("age").gt(22).and("type").eq("V").skip(1L).build();
    List<DocumentEntity> entitiesFound = entityManager.select(query).collect(Collectors.toList());
    assertEquals(2, entitiesFound.size());
    assertThat(entitiesFound, not(contains(entities.get(0))));
    query = select().from(COLLECTION_NAME).where("age").gt(22).and("type").eq("V").skip(3L).build();
    entitiesFound = entityManager.select(query).collect(Collectors.toList());
    assertTrue(entitiesFound.isEmpty());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)114 Test (org.junit.jupiter.api.Test)79 DocumentEntity (jakarta.nosql.document.DocumentEntity)45 DocumentQuery (jakarta.nosql.document.DocumentQuery)43 Document (jakarta.nosql.document.Document)37 DocumentCondition (jakarta.nosql.document.DocumentCondition)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 ValueSource (org.junit.jupiter.params.provider.ValueSource)20 List (java.util.List)15 Person (jakarta.nosql.tck.entities.Person)12 Collectors (java.util.stream.Collectors)7 Params (jakarta.nosql.Params)5 DocumentDeleteQueryParams (jakarta.nosql.document.DocumentDeleteQueryParams)5 Duration (java.time.Duration)5 HashMap (java.util.HashMap)5 Optional (java.util.Optional)5 StreamSupport (java.util.stream.StreamSupport)5 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)4 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)4 Map (java.util.Map)4