From d99f33681b6a928d14714f43c7d3486381c708a8 Mon Sep 17 00:00:00 2001 From: Michael Nitschinger Date: Wed, 17 Feb 2021 09:36:56 +0100 Subject: [PATCH] Revert "DATACOUCH-650 - Polishing." This reverts commit eee83f71725f9a9ded519c4be038c61f412e7077. --- pom.xml | 6 +- .../support/SimpleCouchbaseRepository.java | 45 ++++++------- .../SimpleReactiveCouchbaseRepository.java | 65 +++++++++++-------- 3 files changed, 62 insertions(+), 54 deletions(-) diff --git a/pom.xml b/pom.xml index 32f44d32..db533050 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ 3.0.10 3.0.10 - 2.5.0-SNAPSHOT + 2.4.0-DATACMNS-800-SNAPSHOT spring.data.couchbase @@ -41,12 +41,10 @@ org.springframework spring-context-support - org.springframework spring-web - org.springframework spring-tx @@ -176,14 +174,12 @@ ${kotlin} true - org.jetbrains.kotlin kotlin-reflect ${kotlin} true - org.jetbrains.kotlin kotlin-test diff --git a/src/main/java/org/springframework/data/couchbase/repository/support/SimpleCouchbaseRepository.java b/src/main/java/org/springframework/data/couchbase/repository/support/SimpleCouchbaseRepository.java index bfead97d..5e8d569f 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/support/SimpleCouchbaseRepository.java +++ b/src/main/java/org/springframework/data/couchbase/repository/support/SimpleCouchbaseRepository.java @@ -16,8 +16,6 @@ package org.springframework.data.couchbase.repository.support; -import static org.springframework.data.couchbase.repository.support.Util.*; - import java.util.Collection; import java.util.List; import java.util.Objects; @@ -28,6 +26,7 @@ import org.springframework.data.couchbase.core.CouchbaseOperations; import org.springframework.data.couchbase.core.query.Query; import org.springframework.data.couchbase.repository.CouchbaseRepository; import org.springframework.data.couchbase.repository.query.CouchbaseEntityInformation; +import static org.springframework.data.couchbase.repository.support.Util.hasNonZeroVersionProperty; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; @@ -65,8 +64,8 @@ public class SimpleCouchbaseRepository implements CouchbaseRepository entityInformation, - CouchbaseOperations couchbaseOperations) { + public SimpleCouchbaseRepository(final CouchbaseEntityInformation entityInformation, + final CouchbaseOperations couchbaseOperations) { Assert.notNull(entityInformation, "CouchbaseEntityInformation must not be null!"); Assert.notNull(couchbaseOperations, "CouchbaseOperations must not be null!"); @@ -76,7 +75,7 @@ public class SimpleCouchbaseRepository implements CouchbaseRepository S save(S entity) { + public S save(final S entity) { Assert.notNull(entity, "Entity must not be null!"); // if entity has non-null, non-zero version property, then replace() if (hasNonZeroVersionProperty(entity, couchbaseOperations.getConverter())) { @@ -87,19 +86,21 @@ public class SimpleCouchbaseRepository implements CouchbaseRepository Iterable saveAll(Iterable entities) { + @SuppressWarnings("unchecked") + public Iterable saveAll(final Iterable entities) { Assert.notNull(entities, "The given Iterable of entities must not be null!"); return Streamable.of(entities).stream().map((e) -> save(e)).collect(StreamUtils.toUnmodifiableList()); } @Override - public Optional findById(ID id) { + public Optional findById(final ID id) { Assert.notNull(id, "The given id must not be null!"); return Optional.ofNullable(couchbaseOperations.findById(entityInformation.getJavaType()).one(id.toString())); } @Override - public List findAllById(Iterable ids) { + @SuppressWarnings("unchecked") + public List findAllById(final Iterable ids) { Assert.notNull(ids, "The given Iterable of ids must not be null!"); List convertedIds = Streamable.of(ids).stream().map(Objects::toString).collect(Collectors.toList()); Collection all = couchbaseOperations.findById(entityInformation.getJavaType()).all(convertedIds); @@ -107,35 +108,35 @@ public class SimpleCouchbaseRepository implements CouchbaseRepository entities) { + Assert.notNull(entities, "The given Iterable of entities must not be null!"); + couchbaseOperations.removeById().all(Streamable.of(entities).map(entityInformation::getId).toList()); + } + @Override public void deleteAllById(Iterable 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 void deleteAll(Iterable entities) { - Assert.notNull(entities, "The given Iterable of entities must not be null!"); - couchbaseOperations.removeById().all(Streamable.of(entities).map(entityInformation::getId).toList()); - } - @Override public long count() { return couchbaseOperations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency()) @@ -154,17 +155,17 @@ public class SimpleCouchbaseRepository implements CouchbaseRepository findAll(Sort sort) { + public List findAll(final Sort sort) { return findAll(new Query().with(sort)); } @Override - public List findAll(QueryScanConsistency queryScanConsistency) { + public List findAll(final QueryScanConsistency queryScanConsistency) { return findAll(new Query().scanConsistency(queryScanConsistency)); } @Override - public Page findAll(Pageable pageable) { + public Page findAll(final Pageable pageable) { List results = findAll(new Query().with(pageable)); return new PageImpl<>(results, pageable, count()); } @@ -184,7 +185,7 @@ public class SimpleCouchbaseRepository implements CouchbaseRepository findAll(Query query) { + private List findAll(final Query query) { return couchbaseOperations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency()) .matching(query).all(); } @@ -202,7 +203,7 @@ public class SimpleCouchbaseRepository implements CouchbaseRepository implements ReactiveCouchba * @param entityInformation the Metadata for the entity. * @param operations the reference to the reactive template used. */ - public SimpleReactiveCouchbaseRepository(CouchbaseEntityInformation entityInformation, - ReactiveCouchbaseOperations operations) { + public SimpleReactiveCouchbaseRepository(final CouchbaseEntityInformation entityInformation, + final ReactiveCouchbaseOperations operations) { Assert.notNull(operations, "ReactiveCouchbaseOperations must not be null!"); Assert.notNull(entityInformation, "CouchbaseEntityInformation must not be null!"); @@ -80,7 +78,7 @@ public class SimpleReactiveCouchbaseRepository implements ReactiveCouchba @SuppressWarnings("unchecked") @Override - public Mono save(S entity) { + public Mono save(final S entity) { Assert.notNull(entity, "Entity must not be null!"); // if entity has non-null version property, then replace() if (hasNonZeroVersionProperty(entity, operations.getConverter())) { @@ -91,45 +89,52 @@ public class SimpleReactiveCouchbaseRepository implements ReactiveCouchba } @Override - public Flux findAll(Sort sort) { + public Flux findAll(final Sort sort) { return findAll(new Query().with(sort)); } + @SuppressWarnings("unchecked") @Override - public Flux saveAll(Iterable entities) { + public Flux saveAll(final Iterable entities) { Assert.notNull(entities, "The given Iterable of entities must not be null!"); return Flux.fromIterable(entities).flatMap(this::save); } + @SuppressWarnings("unchecked") @Override - public Flux saveAll(Publisher entityStream) { + public Flux saveAll(final Publisher entityStream) { Assert.notNull(entityStream, "The given Iterable of entities must not be null!"); return Flux.from(entityStream).flatMap(this::save); } + @SuppressWarnings("unchecked") @Override - public Mono findById(ID id) { + public Mono findById(final ID id) { return operations.findById(entityInformation.getJavaType()).one(id.toString()); } + @SuppressWarnings("unchecked") @Override - public Mono findById(Publisher publisher) { + public Mono findById(final Publisher publisher) { Assert.notNull(publisher, "The given Publisher must not be null!"); return Mono.from(publisher).flatMap(this::findById); } + @SuppressWarnings("unchecked") @Override - public Mono existsById(ID id) { + public Mono existsById(final ID id) { Assert.notNull(id, "The given id must not be null!"); return operations.existsById().one(id.toString()); } + @SuppressWarnings("unchecked") @Override - public Mono existsById(Publisher publisher) { + public Mono existsById(final Publisher publisher) { Assert.notNull(publisher, "The given Publisher must not be null!"); return Mono.from(publisher).flatMap(this::existsById); } + @SuppressWarnings("unchecked") @Override public Flux findAll() { return findAll(new Query()); @@ -137,56 +142,62 @@ public class SimpleReactiveCouchbaseRepository implements ReactiveCouchba @SuppressWarnings("unchecked") @Override - public Flux findAllById(Iterable ids) { + public Flux findAllById(final Iterable ids) { Assert.notNull(ids, "The given Iterable of ids must not be null!"); List convertedIds = Streamable.of(ids).stream().map(Objects::toString).collect(Collectors.toList()); return (Flux) operations.findById(entityInformation.getJavaType()).all(convertedIds); } + @SuppressWarnings("unchecked") @Override - public Flux findAllById(Publisher entityStream) { + public Flux findAllById(final Publisher entityStream) { Assert.notNull(entityStream, "The given entityStream must not be null!"); return Flux.from(entityStream).flatMap(this::findById); } + @SuppressWarnings("unchecked") @Override - public Mono deleteById(ID id) { + public Mono deleteById(final ID id) { return operations.removeById().one(id.toString()).then(); } @Override - public Mono deleteById(Publisher publisher) { + public Mono deleteById(final Publisher publisher) { Assert.notNull(publisher, "The given id must not be null!"); return Mono.from(publisher).flatMap(this::deleteById); } + @SuppressWarnings("unchecked") @Override - public Mono delete(T entity) { + public Mono delete(final T entity) { Assert.notNull(entity, "Entity must not be null!"); return operations.removeById().one(entityInformation.getId(entity)).then(); } + @SuppressWarnings("unchecked") @Override - public Mono deleteAllById(Iterable ids) { - return operations.removeById().all(Streamable.of(ids).map(Object::toString).toList()).then(); - } - - @Override - public Mono deleteAll(Iterable entities) { + public Mono deleteAll(final Iterable entities) { return operations.removeById().all(Streamable.of(entities).map(entityInformation::getId).toList()).then(); } @Override - public Mono deleteAll(Publisher entityStream) { + public Mono deleteAll(final Publisher entityStream) { Assert.notNull(entityStream, "The given publisher of entities must not be null!"); return Flux.from(entityStream).flatMap(this::delete).single(); } + @Override + public Mono deleteAllById(final Iterable ids) { + return operations.removeById().all(Streamable.of(ids).map(Object::toString).toList()).then(); + } + + @SuppressWarnings("unchecked") @Override public Mono count() { return operations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency()).count(); } + @SuppressWarnings("unchecked") @Override public Mono deleteAll() { return operations.removeByQuery(entityInformation.getJavaType()).all().then(); @@ -201,7 +212,7 @@ public class SimpleReactiveCouchbaseRepository implements ReactiveCouchba return entityInformation; } - private Flux findAll(Query query) { + private Flux findAll(final Query query) { return operations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency()) .matching(query).all(); } @@ -219,7 +230,7 @@ public class SimpleReactiveCouchbaseRepository implements ReactiveCouchba * * @param crudMethodMetadata the injected repository metadata. */ - void setRepositoryMethodMetadata(CrudMethodMetadata crudMethodMetadata) { + void setRepositoryMethodMetadata(final CrudMethodMetadata crudMethodMetadata) { this.crudMethodMetadata = crudMethodMetadata; }