@Override 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(entity -> delete(entity)).single(); }
@SuppressWarnings("unchecked") @Override public <S extends T> Flux<S> saveAll(Iterable<S> entities) { Assert.notNull(entities, "The given Iterable of entities must not be null!"); return mapFlux(operations.save(entities)); }
@SuppressWarnings("unchecked") @Override public Mono<Boolean> existsById(ID id) { Assert.notNull(id, "The given id must not be null!"); return mapMono(operations.exists(id.toString()).toSingle()); }
@SuppressWarnings("unchecked") @Override public Flux<T> findAll() { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(false); query.stale(operations.getDefaultConsistency().viewConsistency()); return mapFlux(operations.findByView(query, entityInformation.getJavaType())); }
@SuppressWarnings("unchecked") @Override public Mono<Long> count() { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(true); query.stale(operations.getDefaultConsistency().viewConsistency()); return mapMono(operations .queryView(query) .flatMap(AsyncViewResult::rows) .map(asyncViewRow -> Long.valueOf(asyncViewRow.value().toString())).toSingle()); }
@SuppressWarnings("unchecked") @Override 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(object -> save(object)); }
/** * Returns a new Repository based on the metadata. Two categories of repositories can be instantiated: * {@link SimpleReactiveCouchbaseRepository} and {@link ReactiveN1qlCouchbaseRepository}. * * This method performs feature checks to decide which of the two categories can be instantiated (eg. is N1QL available?). * Instantiation is done via reflection, see {@link #getRepositoryBaseClass(RepositoryMetadata)}. * * @param metadata the repository metadata. * * @return a new created repository. */ @Override protected final Object getTargetRepository(final RepositoryInformation metadata) { RxJavaCouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(metadata.getRepositoryInterface(), metadata.getDomainType()); boolean isN1qlAvailable = couchbaseOperations.getCouchbaseClusterInfo().checkAvailable(CouchbaseFeature.N1QL); ViewIndexed viewIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), ViewIndexed.class); N1qlPrimaryIndexed n1qlPrimaryIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), N1qlPrimaryIndexed.class); N1qlSecondaryIndexed n1qlSecondaryIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), N1qlSecondaryIndexed.class); checkFeatures(metadata, isN1qlAvailable, n1qlPrimaryIndexed, n1qlSecondaryIndexed); indexManager.buildIndexes(metadata, viewIndexed, n1qlPrimaryIndexed, n1qlSecondaryIndexed, couchbaseOperations); CouchbaseEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType()); SimpleReactiveCouchbaseRepository repo = getTargetRepositoryViaReflection(metadata, entityInformation, couchbaseOperations); repo.setViewMetadataProvider(viewPostProcessor.getViewMetadataProvider()); return repo; }
@SuppressWarnings("unchecked") @Override public Flux<T> findAll() { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(false); query.stale(operations.getDefaultConsistency().viewConsistency()); return mapFlux(operations.findByView(query, entityInformation.getJavaType())); }
@SuppressWarnings("unchecked") @Override public Mono<Long> count() { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(true); query.stale(operations.getDefaultConsistency().viewConsistency()); return mapMono(operations .queryView(query) .flatMap(AsyncViewResult::rows) .map(asyncViewRow -> Long.valueOf(asyncViewRow.value().toString())).toSingle()); }
@SuppressWarnings("unchecked") @Override 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(object -> save(object)); }
/** * Returns a new Repository based on the metadata. Two categories of repositories can be instantiated: * {@link SimpleReactiveCouchbaseRepository} and {@link ReactiveN1qlCouchbaseRepository}. * * This method performs feature checks to decide which of the two categories can be instantiated (eg. is N1QL available?). * Instantiation is done via reflection, see {@link #getRepositoryBaseClass(RepositoryMetadata)}. * * @param metadata the repository metadata. * * @return a new created repository. */ @Override protected final Object getTargetRepository(final RepositoryInformation metadata) { RxJavaCouchbaseOperations couchbaseOperations = couchbaseOperationsMapping.resolve(metadata.getRepositoryInterface(), metadata.getDomainType()); boolean isN1qlAvailable = couchbaseOperations.getCouchbaseClusterInfo().checkAvailable(CouchbaseFeature.N1QL); ViewIndexed viewIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), ViewIndexed.class); N1qlPrimaryIndexed n1qlPrimaryIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), N1qlPrimaryIndexed.class); N1qlSecondaryIndexed n1qlSecondaryIndexed = AnnotationUtils.findAnnotation(metadata.getRepositoryInterface(), N1qlSecondaryIndexed.class); checkFeatures(metadata, isN1qlAvailable, n1qlPrimaryIndexed, n1qlSecondaryIndexed); indexManager.buildIndexes(metadata, viewIndexed, n1qlPrimaryIndexed, n1qlSecondaryIndexed, couchbaseOperations); CouchbaseEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType()); SimpleReactiveCouchbaseRepository repo = getTargetRepositoryViaReflection(metadata, entityInformation, couchbaseOperations); repo.setViewMetadataProvider(viewPostProcessor.getViewMetadataProvider()); return repo; }
@SuppressWarnings("unchecked") @Override public Flux<T> findAllById(final Iterable<ID> ids) { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(false); query.stale(operations.getDefaultConsistency().viewConsistency()); JsonArray keys = JsonArray.create(); for (ID id : ids) { keys.add(id); } query.keys(keys); return mapFlux(operations.findByView(query, entityInformation.getJavaType())); }
@SuppressWarnings("unchecked") @Override public Mono<Void> deleteAll() { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(false); query.stale(operations.getDefaultConsistency().viewConsistency()); return mapMono(operations.queryView(query) .map(AsyncViewResult::rows) .flatMap(row -> { AsyncViewRow asyncViewRow = (AsyncViewRow) row; return operations.remove(asyncViewRow.id()) .onErrorResumeNext(throwable -> { if (throwable instanceof DocumentDoesNotExistException) { return Observable.empty(); } return Observable.error(throwable); }); }) .toList() .map(list -> Observable.<Void>empty()) .toSingle()); }
@SuppressWarnings("unchecked") @Override public Mono<Boolean> existsById(ID id) { Assert.notNull(id, "The given id must not be null!"); return mapMono(operations.exists(id.toString()).toSingle()); }
@SuppressWarnings("unchecked") @Override public <S extends T> Flux<S> saveAll(Iterable<S> entities) { Assert.notNull(entities, "The given Iterable of entities must not be null!"); return mapFlux(operations.save(entities)); }
@Override 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(entity -> delete(entity)).single(); }
@SuppressWarnings("unchecked") @Override public Flux<T> findAllById(final Iterable<ID> ids) { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(false); query.stale(operations.getDefaultConsistency().viewConsistency()); JsonArray keys = JsonArray.create(); for (ID id : ids) { keys.add(id); } query.keys(keys); return mapFlux(operations.findByView(query, entityInformation.getJavaType())); }
@SuppressWarnings("unchecked") @Override public Mono<Void> deleteAll() { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(false); query.stale(operations.getDefaultConsistency().viewConsistency()); return mapMono(operations.queryView(query) .map(AsyncViewResult::rows) .flatMap(row -> { AsyncViewRow asyncViewRow = (AsyncViewRow) row; return operations.remove(asyncViewRow.id()) .onErrorResumeNext(throwable -> { if (throwable instanceof DocumentDoesNotExistException) { return Observable.empty(); } return Observable.error(throwable); }); }) .toList() .map(list -> Observable.<Void>empty()) .toSingle()); }
@SuppressWarnings("unchecked") public <S extends T> Mono<S> save(S entity) { Assert.notNull(entity, "Entity must not be null!"); return mapMono(operations.save(entity).toSingle()); }
@SuppressWarnings("unchecked") public <S extends T> Mono<S> save(S entity) { Assert.notNull(entity, "Entity must not be null!"); return mapMono(operations.save(entity).toSingle()); }