Skip to content

DATACOUCH-650 - Implements deleteById(Iterable<ID> ids). #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-couchbase</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.2.0-DATACOUCH-650-SNAPSHOT</version>

<name>Spring Data Couchbase</name>
<description>Spring Data integration for Couchbase</description>
Expand All @@ -20,7 +20,7 @@
<properties>
<couchbase>3.0.9</couchbase>
<couchbase.osgi>3.0.9</couchbase.osgi>
<springdata.commons>2.5.0-SNAPSHOT</springdata.commons>
<springdata.commons>2.4.0-DATACMNS-800-SNAPSHOT</springdata.commons>
<java-module-name>spring.data.couchbase</java-module-name>
</properties>

Expand Down Expand Up @@ -161,6 +161,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>

<!-- Kotlin extension -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
*
* @author Michael Nitschinger
* @author Mark Paluch
* @author Jens Schauder
*/
public class SimpleCouchbaseRepository<T, ID> implements CouchbaseRepository<T, ID> {

Expand Down Expand Up @@ -130,6 +131,12 @@ public void deleteAll(final Iterable<? extends T> entities) {
couchbaseOperations.removeById().all(Streamable.of(entities).map(entityInformation::getId).toList());
}

@Override
public void deleteAllById(Iterable<? extends ID> ids) {
Assert.notNull(ids, "The given Iterable of ids must not be null!");
couchbaseOperations.removeById().all(Streamable.of(ids).map(Objects::toString).toList());
}

@Override
public long count() {
return couchbaseOperations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* @author Christoph Strobl
* @author David Kelly
* @author Douglas Six
* @author Jens Schauder
* @since 3.0
*/
public class SimpleReactiveCouchbaseRepository<T, ID> implements ReactiveCouchbaseRepository<T, ID> {
Expand Down Expand Up @@ -185,6 +186,11 @@ public Mono<Void> deleteAll(final Publisher<? extends T> entityStream) {
return Flux.from(entityStream).flatMap(this::delete).single();
}

@Override
public Mono<Void> deleteAllById(final Iterable<? extends ID> ids) {
return operations.removeById().all(Streamable.of(ids).map(Object::toString).toList()).then();
}

@SuppressWarnings("unchecked")
@Override
public Mono<Long> count() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.data.couchbase.repository;

import static java.util.Arrays.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*;

import java.util.ArrayList;
Expand All @@ -26,6 +28,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -47,6 +50,7 @@
import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests;
import org.springframework.data.couchbase.util.ClusterType;
import org.springframework.data.couchbase.util.IgnoreWhen;
import org.springframework.data.util.StreamUtils;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import com.couchbase.client.core.error.IndexExistsException;
Expand All @@ -56,6 +60,7 @@
*
* @author Michael Nitschinger
* @author Michael Reiche
* @author Jens Schauder
*/
@SpringJUnitConfig(CouchbaseRepositoryQueryIntegrationTests.Config.class)
@IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED)
Expand Down Expand Up @@ -170,7 +175,7 @@ void count() {
airportRepository.save(airport);
}

Long count = airportRepository.countFancyExpression(Arrays.asList("JFK"), Arrays.asList("jfk"), false);
Long count = airportRepository.countFancyExpression(asList("JFK"), asList("jfk"), false);
assertEquals(1, count);

long airportCount = airportRepository.count();
Expand Down Expand Up @@ -277,6 +282,25 @@ void threadSafeStringParametersTest() throws Exception {
}
}

@Test // DATACOUCH-650
void deleteAllById() {

Airport vienna = new Airport("airports::vie", "vie", "LOWW");
Airport frankfurt = new Airport("airports::fra", "fra", "EDDF");
Airport losAngeles = new Airport("airports::lax", "lax", "KLAX");

try {
airportRepository.saveAll(asList(vienna, frankfurt, losAngeles));

airportRepository.deleteAllById(asList(vienna.getId(), losAngeles.getId()));


assertThat(airportRepository.findAll()).containsExactly(frankfurt);
} finally {
airportRepository.deleteAll();
}
}

private void sleep(int millis) {
try {
Thread.sleep(millis); // so they are executed out-of-order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@

package org.springframework.data.couchbase.repository;

import static org.junit.jupiter.api.Assertions.*;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;

import com.couchbase.client.core.error.IndexExistsException;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should verify where import changes stem from. This file seemed to be formatted properly previously.

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -43,8 +35,18 @@
import org.springframework.data.couchbase.util.ClusterType;
import org.springframework.data.couchbase.util.IgnoreWhen;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import reactor.test.StepVerifier;

import com.couchbase.client.core.error.IndexExistsException;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;

import static java.util.Arrays.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*;

/**
* template class for Reactive Couchbase operations
Expand All @@ -56,10 +58,13 @@
@IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED)
public class ReactiveCouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegrationTests {

@Autowired CouchbaseClientFactory clientFactory;
@Autowired
CouchbaseClientFactory clientFactory;

@Autowired ReactiveAirportRepository airportRepository; // intellij flags "Could not Autowire", but it runs ok.
@Autowired ReactiveUserRepository userRepository; // intellij flags "Could not Autowire", but it runs ok.
@Autowired
ReactiveAirportRepository airportRepository; // intellij flags "Could not Autowire", but it runs ok.
@Autowired
ReactiveUserRepository userRepository; // intellij flags "Could not Autowire", but it runs ok.

@BeforeEach
void beforeEach() {
Expand Down Expand Up @@ -93,9 +98,9 @@ void findBySimpleProperty() {
vie = new Airport("airports::vie", "vie", "loww");
airportRepository.save(vie).block();
List<Airport> airports1 = airportRepository.findAllByIata("vie").collectList().block();
assertEquals(1,airports1.size());
assertEquals(1, airports1.size());
List<Airport> airports2 = airportRepository.findAllByIata("vie").collectList().block();
assertEquals(1,airports2.size());
assertEquals(1, airports2.size());
} finally {
airportRepository.delete(vie).block();
}
Expand All @@ -114,7 +119,7 @@ public void testCas() {

@Test
void count() {
String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" };
String[] iatas = {"JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX"};
Future[] future = new Future[iatas.length];
ExecutorService executorService = Executors.newFixedThreadPool(iatas.length);
try {
Expand Down Expand Up @@ -148,6 +153,25 @@ void count() {
}
}

@Test
// DATACOUCH-650
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Formatting

void deleteAllById() {

Airport vienna = new Airport("airports::vie", "vie", "LOWW");
Airport frankfurt = new Airport("airports::fra", "fra", "EDDF");
Airport losAngeles = new Airport("airports::lax", "lax", "KLAX");

try {
airportRepository.saveAll(asList(vienna, frankfurt, losAngeles)).as(StepVerifier::create).verifyComplete();

airportRepository.deleteAllById(asList(vienna.getId(), losAngeles.getId())).as(StepVerifier::create).verifyComplete();

airportRepository.findAll().as(StepVerifier::create).expectNext(frankfurt).verifyComplete();
} finally {
airportRepository.deleteAll();
}
}

@Configuration
@EnableReactiveCouchbaseRepositories("org.springframework.data.couchbase")
static class Config extends AbstractCouchbaseConfiguration {
Expand Down