DATACOUCH-650 - Polishing.
Reorder methods. Remove superfluous final keyword. Reformat pom. Fix dependency to Spring Data Commons. Original pull request: #279.
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
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;
|
||||
@@ -26,7 +28,6 @@ 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;
|
||||
@@ -64,8 +65,8 @@ public class SimpleCouchbaseRepository<T, ID> implements CouchbaseRepository<T,
|
||||
* @param entityInformation the Metadata for the entity.
|
||||
* @param couchbaseOperations the reference to the template used.
|
||||
*/
|
||||
public SimpleCouchbaseRepository(final CouchbaseEntityInformation<T, String> entityInformation,
|
||||
final CouchbaseOperations couchbaseOperations) {
|
||||
public SimpleCouchbaseRepository(CouchbaseEntityInformation<T, String> entityInformation,
|
||||
CouchbaseOperations couchbaseOperations) {
|
||||
Assert.notNull(entityInformation, "CouchbaseEntityInformation must not be null!");
|
||||
Assert.notNull(couchbaseOperations, "CouchbaseOperations must not be null!");
|
||||
|
||||
@@ -75,7 +76,7 @@ public class SimpleCouchbaseRepository<T, ID> implements CouchbaseRepository<T,
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <S extends T> S save(final S entity) {
|
||||
public <S extends T> S save(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())) {
|
||||
@@ -86,21 +87,19 @@ public class SimpleCouchbaseRepository<T, ID> implements CouchbaseRepository<T,
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <S extends T> Iterable<S> saveAll(final Iterable<S> entities) {
|
||||
public <S extends T> Iterable<S> saveAll(Iterable<S> 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<T> findById(final ID id) {
|
||||
public Optional<T> findById(ID id) {
|
||||
Assert.notNull(id, "The given id must not be null!");
|
||||
return Optional.ofNullable(couchbaseOperations.findById(entityInformation.getJavaType()).one(id.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<T> findAllById(final Iterable<ID> ids) {
|
||||
public List<T> findAllById(Iterable<ID> ids) {
|
||||
Assert.notNull(ids, "The given Iterable of ids must not be null!");
|
||||
List<String> convertedIds = Streamable.of(ids).stream().map(Objects::toString).collect(Collectors.toList());
|
||||
Collection<? extends T> all = couchbaseOperations.findById(entityInformation.getJavaType()).all(convertedIds);
|
||||
@@ -108,35 +107,35 @@ public class SimpleCouchbaseRepository<T, ID> implements CouchbaseRepository<T,
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsById(final ID id) {
|
||||
public boolean existsById(ID id) {
|
||||
Assert.notNull(id, "The given id must not be null!");
|
||||
return couchbaseOperations.existsById().one(id.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(final ID id) {
|
||||
public void deleteById(ID id) {
|
||||
Assert.notNull(id, "The given id must not be null!");
|
||||
couchbaseOperations.removeById().one(id.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(final T entity) {
|
||||
public void delete(T entity) {
|
||||
Assert.notNull(entity, "Entity must not be null!");
|
||||
couchbaseOperations.removeById().one(entityInformation.getId(entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(final Iterable<? extends T> 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<? 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 void deleteAll(Iterable<? extends T> 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())
|
||||
@@ -155,17 +154,17 @@ public class SimpleCouchbaseRepository<T, ID> implements CouchbaseRepository<T,
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> findAll(final Sort sort) {
|
||||
public List<T> findAll(Sort sort) {
|
||||
return findAll(new Query().with(sort));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> findAll(final QueryScanConsistency queryScanConsistency) {
|
||||
public List<T> findAll(QueryScanConsistency queryScanConsistency) {
|
||||
return findAll(new Query().scanConsistency(queryScanConsistency));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<T> findAll(final Pageable pageable) {
|
||||
public Page<T> findAll(Pageable pageable) {
|
||||
List<T> results = findAll(new Query().with(pageable));
|
||||
return new PageImpl<>(results, pageable, count());
|
||||
}
|
||||
@@ -185,7 +184,7 @@ public class SimpleCouchbaseRepository<T, ID> implements CouchbaseRepository<T,
|
||||
* @param query the originating query.
|
||||
* @return the list of found entities, already executed.
|
||||
*/
|
||||
private List<T> findAll(final Query query) {
|
||||
private List<T> findAll(Query query) {
|
||||
return couchbaseOperations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency())
|
||||
.matching(query).all();
|
||||
}
|
||||
@@ -203,7 +202,7 @@ public class SimpleCouchbaseRepository<T, ID> implements CouchbaseRepository<T,
|
||||
*
|
||||
* @param crudMethodMetadata the injected repository metadata.
|
||||
*/
|
||||
void setRepositoryMethodMetadata(final CrudMethodMetadata crudMethodMetadata) {
|
||||
void setRepositoryMethodMetadata(CrudMethodMetadata crudMethodMetadata) {
|
||||
this.crudMethodMetadata = crudMethodMetadata;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.data.couchbase.repository.support;
|
||||
|
||||
import static org.springframework.data.couchbase.repository.support.Util.*;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -24,12 +26,12 @@ import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.data.couchbase.core.CouchbaseOperations;
|
||||
import org.springframework.data.couchbase.core.ReactiveCouchbaseOperations;
|
||||
import org.springframework.data.couchbase.core.query.Query;
|
||||
import org.springframework.data.couchbase.repository.ReactiveCouchbaseRepository;
|
||||
import org.springframework.data.couchbase.repository.query.CouchbaseEntityInformation;
|
||||
import static org.springframework.data.couchbase.repository.support.Util.hasNonZeroVersionProperty;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -67,8 +69,8 @@ public class SimpleReactiveCouchbaseRepository<T, ID> implements ReactiveCouchba
|
||||
* @param entityInformation the Metadata for the entity.
|
||||
* @param operations the reference to the reactive template used.
|
||||
*/
|
||||
public SimpleReactiveCouchbaseRepository(final CouchbaseEntityInformation<T, String> entityInformation,
|
||||
final ReactiveCouchbaseOperations operations) {
|
||||
public SimpleReactiveCouchbaseRepository(CouchbaseEntityInformation<T, String> entityInformation,
|
||||
ReactiveCouchbaseOperations operations) {
|
||||
Assert.notNull(operations, "ReactiveCouchbaseOperations must not be null!");
|
||||
Assert.notNull(entityInformation, "CouchbaseEntityInformation must not be null!");
|
||||
|
||||
@@ -78,7 +80,7 @@ public class SimpleReactiveCouchbaseRepository<T, ID> implements ReactiveCouchba
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <S extends T> Mono<S> save(final S entity) {
|
||||
public <S extends T> Mono<S> save(S entity) {
|
||||
Assert.notNull(entity, "Entity must not be null!");
|
||||
// if entity has non-null version property, then replace()
|
||||
if (hasNonZeroVersionProperty(entity, operations.getConverter())) {
|
||||
@@ -89,52 +91,45 @@ public class SimpleReactiveCouchbaseRepository<T, ID> implements ReactiveCouchba
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<T> findAll(final Sort sort) {
|
||||
public Flux<T> findAll(Sort sort) {
|
||||
return findAll(new Query().with(sort));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <S extends T> Flux<S> saveAll(final Iterable<S> entities) {
|
||||
public <S extends T> Flux<S> saveAll(Iterable<S> entities) {
|
||||
Assert.notNull(entities, "The given Iterable of entities must not be null!");
|
||||
return Flux.fromIterable(entities).flatMap(this::save);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <S extends T> Flux<S> saveAll(final Publisher<S> entityStream) {
|
||||
public <S extends T> Flux<S> saveAll(Publisher<S> 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<T> findById(final ID id) {
|
||||
public Mono<T> findById(ID id) {
|
||||
return operations.findById(entityInformation.getJavaType()).one(id.toString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Mono<T> findById(final Publisher<ID> publisher) {
|
||||
public Mono<T> findById(Publisher<ID> publisher) {
|
||||
Assert.notNull(publisher, "The given Publisher must not be null!");
|
||||
return Mono.from(publisher).flatMap(this::findById);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Mono<Boolean> existsById(final ID id) {
|
||||
public Mono<Boolean> existsById(ID id) {
|
||||
Assert.notNull(id, "The given id must not be null!");
|
||||
return operations.existsById().one(id.toString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Mono<Boolean> existsById(final Publisher<ID> publisher) {
|
||||
public Mono<Boolean> existsById(Publisher<ID> publisher) {
|
||||
Assert.notNull(publisher, "The given Publisher must not be null!");
|
||||
return Mono.from(publisher).flatMap(this::existsById);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Flux<T> findAll() {
|
||||
return findAll(new Query());
|
||||
@@ -142,62 +137,56 @@ public class SimpleReactiveCouchbaseRepository<T, ID> implements ReactiveCouchba
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Flux<T> findAllById(final Iterable<ID> ids) {
|
||||
public Flux<T> findAllById(Iterable<ID> ids) {
|
||||
Assert.notNull(ids, "The given Iterable of ids must not be null!");
|
||||
List<String> convertedIds = Streamable.of(ids).stream().map(Objects::toString).collect(Collectors.toList());
|
||||
return (Flux<T>) operations.findById(entityInformation.getJavaType()).all(convertedIds);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Flux<T> findAllById(final Publisher<ID> entityStream) {
|
||||
public Flux<T> findAllById(Publisher<ID> entityStream) {
|
||||
Assert.notNull(entityStream, "The given entityStream must not be null!");
|
||||
return Flux.from(entityStream).flatMap(this::findById);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Mono<Void> deleteById(final ID id) {
|
||||
public Mono<Void> deleteById(ID id) {
|
||||
return operations.removeById().one(id.toString()).then();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> deleteById(final Publisher<ID> publisher) {
|
||||
public Mono<Void> deleteById(Publisher<ID> publisher) {
|
||||
Assert.notNull(publisher, "The given id must not be null!");
|
||||
return Mono.from(publisher).flatMap(this::deleteById);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Mono<Void> delete(final T entity) {
|
||||
public Mono<Void> delete(T entity) {
|
||||
Assert.notNull(entity, "Entity must not be null!");
|
||||
return operations.removeById().one(entityInformation.getId(entity)).then();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Mono<Void> deleteAll(final Iterable<? extends T> entities) {
|
||||
public Mono<Void> deleteAllById(Iterable<? extends ID> ids) {
|
||||
return operations.removeById().all(Streamable.of(ids).map(Object::toString).toList()).then();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> deleteAll(Iterable<? extends T> entities) {
|
||||
return operations.removeById().all(Streamable.of(entities).map(entityInformation::getId).toList()).then();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> deleteAll(final Publisher<? extends T> entityStream) {
|
||||
public Mono<Void> deleteAll(Publisher<? extends T> entityStream) {
|
||||
Assert.notNull(entityStream, "The given publisher of entities must not be null!");
|
||||
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() {
|
||||
return operations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency()).count();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Mono<Void> deleteAll() {
|
||||
return operations.removeByQuery(entityInformation.getJavaType()).all().then();
|
||||
@@ -212,7 +201,7 @@ public class SimpleReactiveCouchbaseRepository<T, ID> implements ReactiveCouchba
|
||||
return entityInformation;
|
||||
}
|
||||
|
||||
private Flux<T> findAll(final Query query) {
|
||||
private Flux<T> findAll(Query query) {
|
||||
return operations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency())
|
||||
.matching(query).all();
|
||||
}
|
||||
@@ -230,7 +219,7 @@ public class SimpleReactiveCouchbaseRepository<T, ID> implements ReactiveCouchba
|
||||
*
|
||||
* @param crudMethodMetadata the injected repository metadata.
|
||||
*/
|
||||
void setRepositoryMethodMetadata(final CrudMethodMetadata crudMethodMetadata) {
|
||||
void setRepositoryMethodMetadata(CrudMethodMetadata crudMethodMetadata) {
|
||||
this.crudMethodMetadata = crudMethodMetadata;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user