DATACOUCH-650 - Implements CrudRepository and ReactiveCrudRepository.deleteById(Iterable<ID> ids).
Original pull request: #279.
This commit is contained in:
committed by
mikereiche
parent
788f7d999b
commit
dfd2dd66b3
8
pom.xml
8
pom.xml
@@ -20,7 +20,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<couchbase>3.0.10</couchbase>
|
<couchbase>3.0.10</couchbase>
|
||||||
<couchbase.osgi>3.0.10</couchbase.osgi>
|
<couchbase.osgi>3.0.10</couchbase.osgi>
|
||||||
<springdata.commons>2.4.3-SNAPSHOT</springdata.commons>
|
<springdata.commons>2.4.0-DATACMNS-800-SNAPSHOT</springdata.commons>
|
||||||
<java-module-name>spring.data.couchbase</java-module-name>
|
<java-module-name>spring.data.couchbase</java-module-name>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
@@ -161,6 +161,12 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.projectreactor</groupId>
|
||||||
|
<artifactId>reactor-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Kotlin extension -->
|
<!-- Kotlin extension -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import com.couchbase.client.java.query.QueryScanConsistency;
|
|||||||
*
|
*
|
||||||
* @author Michael Nitschinger
|
* @author Michael Nitschinger
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Jens Schauder
|
||||||
*/
|
*/
|
||||||
public class SimpleCouchbaseRepository<T, ID> implements CouchbaseRepository<T, ID> {
|
public class SimpleCouchbaseRepository<T, ID> implements CouchbaseRepository<T, ID> {
|
||||||
|
|
||||||
@@ -130,6 +131,12 @@ public class SimpleCouchbaseRepository<T, ID> implements CouchbaseRepository<T,
|
|||||||
couchbaseOperations.removeById().all(Streamable.of(entities).map(entityInformation::getId).toList());
|
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
|
@Override
|
||||||
public long count() {
|
public long count() {
|
||||||
return couchbaseOperations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency())
|
return couchbaseOperations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency())
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import com.couchbase.client.java.query.QueryScanConsistency;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author David Kelly
|
* @author David Kelly
|
||||||
* @author Douglas Six
|
* @author Douglas Six
|
||||||
|
* @author Jens Schauder
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class SimpleReactiveCouchbaseRepository<T, ID> implements ReactiveCouchbaseRepository<T, ID> {
|
public class SimpleReactiveCouchbaseRepository<T, ID> implements ReactiveCouchbaseRepository<T, ID> {
|
||||||
@@ -185,6 +186,11 @@ public class SimpleReactiveCouchbaseRepository<T, ID> implements ReactiveCouchba
|
|||||||
return Flux.from(entityStream).flatMap(this::delete).single();
|
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")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Mono<Long> count() {
|
public Mono<Long> count() {
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.data.couchbase.repository;
|
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 static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -26,6 +28,7 @@ import java.util.concurrent.Callable;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -47,6 +50,7 @@ import org.springframework.data.couchbase.util.Capabilities;
|
|||||||
import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests;
|
import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests;
|
||||||
import org.springframework.data.couchbase.util.ClusterType;
|
import org.springframework.data.couchbase.util.ClusterType;
|
||||||
import org.springframework.data.couchbase.util.IgnoreWhen;
|
import org.springframework.data.couchbase.util.IgnoreWhen;
|
||||||
|
import org.springframework.data.util.StreamUtils;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||||
|
|
||||||
import com.couchbase.client.core.error.IndexExistsException;
|
import com.couchbase.client.core.error.IndexExistsException;
|
||||||
@@ -56,6 +60,7 @@ import com.couchbase.client.core.error.IndexExistsException;
|
|||||||
*
|
*
|
||||||
* @author Michael Nitschinger
|
* @author Michael Nitschinger
|
||||||
* @author Michael Reiche
|
* @author Michael Reiche
|
||||||
|
* @author Jens Schauder
|
||||||
*/
|
*/
|
||||||
@SpringJUnitConfig(CouchbaseRepositoryQueryIntegrationTests.Config.class)
|
@SpringJUnitConfig(CouchbaseRepositoryQueryIntegrationTests.Config.class)
|
||||||
@IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED)
|
@IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED)
|
||||||
@@ -170,7 +175,7 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
|
|||||||
airportRepository.save(airport);
|
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);
|
assertEquals(1, count);
|
||||||
|
|
||||||
long airportCount = airportRepository.count();
|
long airportCount = airportRepository.count();
|
||||||
@@ -277,6 +282,25 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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) {
|
private void sleep(int millis) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(millis); // so they are executed out-of-order
|
Thread.sleep(millis); // so they are executed out-of-order
|
||||||
|
|||||||
@@ -16,15 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.data.couchbase.repository;
|
package org.springframework.data.couchbase.repository;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
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 org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -43,8 +35,18 @@ import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests;
|
|||||||
import org.springframework.data.couchbase.util.ClusterType;
|
import org.springframework.data.couchbase.util.ClusterType;
|
||||||
import org.springframework.data.couchbase.util.IgnoreWhen;
|
import org.springframework.data.couchbase.util.IgnoreWhen;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
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
|
* template class for Reactive Couchbase operations
|
||||||
@@ -56,10 +58,13 @@ import com.couchbase.client.core.error.IndexExistsException;
|
|||||||
@IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED)
|
@IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED)
|
||||||
public class ReactiveCouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegrationTests {
|
public class ReactiveCouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegrationTests {
|
||||||
|
|
||||||
@Autowired CouchbaseClientFactory clientFactory;
|
@Autowired
|
||||||
|
CouchbaseClientFactory clientFactory;
|
||||||
|
|
||||||
@Autowired ReactiveAirportRepository airportRepository; // intellij flags "Could not Autowire", but it runs ok.
|
@Autowired
|
||||||
@Autowired ReactiveUserRepository userRepository; // intellij flags "Could not Autowire", but it runs ok.
|
ReactiveAirportRepository airportRepository; // intellij flags "Could not Autowire", but it runs ok.
|
||||||
|
@Autowired
|
||||||
|
ReactiveUserRepository userRepository; // intellij flags "Could not Autowire", but it runs ok.
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void beforeEach() {
|
void beforeEach() {
|
||||||
@@ -93,9 +98,9 @@ public class ReactiveCouchbaseRepositoryQueryIntegrationTests extends ClusterAwa
|
|||||||
vie = new Airport("airports::vie", "vie", "loww");
|
vie = new Airport("airports::vie", "vie", "loww");
|
||||||
airportRepository.save(vie).block();
|
airportRepository.save(vie).block();
|
||||||
List<Airport> airports1 = airportRepository.findAllByIata("vie").collectList().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();
|
List<Airport> airports2 = airportRepository.findAllByIata("vie").collectList().block();
|
||||||
assertEquals(1,airports2.size());
|
assertEquals(1, airports2.size());
|
||||||
} finally {
|
} finally {
|
||||||
airportRepository.delete(vie).block();
|
airportRepository.delete(vie).block();
|
||||||
}
|
}
|
||||||
@@ -114,7 +119,7 @@ public class ReactiveCouchbaseRepositoryQueryIntegrationTests extends ClusterAwa
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void count() {
|
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];
|
Future[] future = new Future[iatas.length];
|
||||||
ExecutorService executorService = Executors.newFixedThreadPool(iatas.length);
|
ExecutorService executorService = Executors.newFixedThreadPool(iatas.length);
|
||||||
try {
|
try {
|
||||||
@@ -148,6 +153,25 @@ public class ReactiveCouchbaseRepositoryQueryIntegrationTests extends ClusterAwa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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)).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
|
@Configuration
|
||||||
@EnableReactiveCouchbaseRepositories("org.springframework.data.couchbase")
|
@EnableReactiveCouchbaseRepositories("org.springframework.data.couchbase")
|
||||||
static class Config extends AbstractCouchbaseConfiguration {
|
static class Config extends AbstractCouchbaseConfiguration {
|
||||||
|
|||||||
Reference in New Issue
Block a user