diff --git a/pom.xml b/pom.xml index eea61f492c..82c2f235da 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-mongodb-parent - 2.0.0.BUILD-SNAPSHOT + 2.0.0.DATAMONGO-1667-SNAPSHOT pom Spring Data MongoDB diff --git a/spring-data-mongodb-cross-store/pom.xml b/spring-data-mongodb-cross-store/pom.xml index 4a49168713..bdcc36643e 100644 --- a/spring-data-mongodb-cross-store/pom.xml +++ b/spring-data-mongodb-cross-store/pom.xml @@ -6,7 +6,7 @@ org.springframework.data spring-data-mongodb-parent - 2.0.0.BUILD-SNAPSHOT + 2.0.0.DATAMONGO-1667-SNAPSHOT ../pom.xml @@ -48,7 +48,7 @@ org.springframework.data spring-data-mongodb - 2.0.0.BUILD-SNAPSHOT + 2.0.0.DATAMONGO-1667-SNAPSHOT diff --git a/spring-data-mongodb-distribution/pom.xml b/spring-data-mongodb-distribution/pom.xml index 750ed23aa8..713189fce2 100644 --- a/spring-data-mongodb-distribution/pom.xml +++ b/spring-data-mongodb-distribution/pom.xml @@ -13,7 +13,7 @@ org.springframework.data spring-data-mongodb-parent - 2.0.0.BUILD-SNAPSHOT + 2.0.0.DATAMONGO-1667-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb-log4j/pom.xml b/spring-data-mongodb-log4j/pom.xml index 50d0a6454a..8e19e6417f 100644 --- a/spring-data-mongodb-log4j/pom.xml +++ b/spring-data-mongodb-log4j/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-mongodb-parent - 2.0.0.BUILD-SNAPSHOT + 2.0.0.DATAMONGO-1667-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml index 886bcca7b6..210b7132ac 100644 --- a/spring-data-mongodb/pom.xml +++ b/spring-data-mongodb/pom.xml @@ -11,7 +11,7 @@ org.springframework.data spring-data-mongodb-parent - 2.0.0.BUILD-SNAPSHOT + 2.0.0.DATAMONGO-1667-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/InfiniteStream.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/Tailable.java similarity index 77% rename from spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/InfiniteStream.java rename to spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/Tailable.java index ceda104373..f497580cea 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/InfiniteStream.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/Tailable.java @@ -24,10 +24,10 @@ import org.springframework.data.annotation.QueryAnnotation; /** - * Annotation to declare an infinite stream using repository query methods. An infinite stream uses MongoDB's - * {@link com.mongodb.CursorType#TailableAwait tailable} cursors to retrieve data from a capped collection and stream - * data as it is inserted into the collection. An infinite stream can only be used with streams that emit more than one - * element, such as {@link reactor.core.publisher.Flux} or {@link rx.Observable}. + * Annotation to declare an infinite stream using MongoDB's {@link com.mongodb.CursorType#TailableAwait tailable} + * cursors. An infinite stream can only be used with capped collections. Objects are emitted through the stream as data + * is inserted into the collection. An infinite stream can only be used with streams that emit more than one element, + * such as {@link reactor.core.publisher.Flux}. *

* The stream may become dead, or invalid, if either the query returns no match or the cursor returns the document at * the "end" of the collection and then the application deletes that document. @@ -37,11 +37,12 @@ * * @author Mark Paluch * @see Tailable Cursors + * @since 2.0 */ @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) @Documented @QueryAnnotation -public @interface InfiniteStream { +public @interface Tailable { } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractReactiveMongoQuery.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractReactiveMongoQuery.java index 0a2b8e97a3..563cdd0ecf 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractReactiveMongoQuery.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractReactiveMongoQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -130,7 +130,7 @@ private ReactiveMongoQueryExecution getExecutionToWrap(MongoParameterAccessor ac return new DeleteExecution(operations, method); } else if (method.isGeoNearQuery()) { return new GeoNearExecution(operations, accessor, method.getReturnType()); - } else if (isInfiniteStream(method)) { + } else if (isTailable(method)) { return new TailExecution(operations, accessor.getPageable()); } else if (method.isCollectionQuery()) { return new CollectionExecution(operations, accessor.getPageable()); @@ -139,8 +139,8 @@ private ReactiveMongoQueryExecution getExecutionToWrap(MongoParameterAccessor ac } } - private boolean isInfiniteStream(MongoQueryMethod method) { - return method.getInfiniteStreamAnnotation() != null; + private boolean isTailable(MongoQueryMethod method) { + return method.getTailableAnnotation() != null; } Query applyQueryMetaAttributesWhenPresent(Query query) { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java index 55e4b4affd..8bdb42d40d 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2016 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,9 @@ import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity; import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty; -import org.springframework.data.mongodb.repository.InfiniteStream; import org.springframework.data.mongodb.repository.Meta; import org.springframework.data.mongodb.repository.Query; +import org.springframework.data.mongodb.repository.Tailable; import org.springframework.data.projection.ProjectionFactory; import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.query.QueryMethod; @@ -44,7 +44,7 @@ /** * Mongo specific implementation of {@link QueryMethod}. - * + * * @author Oliver Gierke * @author Christoph Strobl * @author Mark Paluch @@ -61,7 +61,7 @@ public class MongoQueryMethod extends QueryMethod { /** * Creates a new {@link MongoQueryMethod} from the given {@link Method}. - * + * * @param method must not be {@literal null}. * @param metadata must not be {@literal null}. * @param projectionFactory must not be {@literal null}. @@ -89,7 +89,7 @@ protected MongoParameters createParameters(Method method) { /** * Returns whether the method has an annotated query. - * + * * @return */ public boolean hasAnnotatedQuery() { @@ -99,7 +99,7 @@ public boolean hasAnnotatedQuery() { /** * Returns the query string declared in a {@link Query} annotation or {@literal null} if neither the annotation found * nor the attribute was specified. - * + * * @return */ String getAnnotatedQuery() { @@ -110,7 +110,7 @@ String getAnnotatedQuery() { /** * Returns the field specification to be used for the query. - * + * * @return */ String getFieldSpecification() { @@ -119,7 +119,7 @@ String getFieldSpecification() { return StringUtils.hasText(value) ? value : null; } - /* + /* * (non-Javadoc) * @see org.springframework.data.repository.query.QueryMethod#getEntityInformation() */ @@ -165,7 +165,7 @@ public MongoParameters getParameters() { /** * Returns whether the query is a geo near query. - * + * * @return */ public boolean isGeoNearQuery() { @@ -192,7 +192,7 @@ private boolean isGeoNearQuery(Method method) { /** * Returns the {@link Query} annotation that is applied to the method or {@code null} if none available. - * + * * @return */ Query getQueryAnnotation() { @@ -213,7 +213,7 @@ public boolean hasQueryMetaAttributes() { /** * Returns the {@link Meta} annotation that is applied to the method or {@code null} if not available. - * + * * @return * @since 1.6 */ @@ -222,18 +222,18 @@ Meta getMetaAnnotation() { } /** - * Returns the {@link InfiniteStream} annotation that is applied to the method or {@code null} if not available. + * Returns the {@link Tailable} annotation that is applied to the method or {@code null} if not available. * * @return * @since 2.0 */ - InfiniteStream getInfiniteStreamAnnotation() { - return AnnotatedElementUtils.findMergedAnnotation(method, InfiniteStream.class); + Tailable getTailableAnnotation() { + return AnnotatedElementUtils.findMergedAnnotation(method, Tailable.class); } /** * Returns the {@link org.springframework.data.mongodb.core.query.Meta} attributes to be applied. - * + * * @return never {@literal null}. * @since 1.6 */ diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ReactiveMongoRepositoryTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ReactiveMongoRepositoryTests.java index 602b1c2fe1..0a1833b61f 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ReactiveMongoRepositoryTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ReactiveMongoRepositoryTests.java @@ -170,7 +170,7 @@ public void shouldFindByLastNameAndSort() { } @Test // DATAMONGO-1444 - public void shouldUseInfiniteStream() throws Exception { + public void shouldUseTailableCursor() throws Exception { StepVerifier .create(template.dropCollection(Capped.class) // @@ -195,7 +195,7 @@ public void shouldUseInfiniteStream() throws Exception { } @Test // DATAMONGO-1444 - public void shouldUseInfiniteStreamWithProjection() throws Exception { + public void shouldUseTailableCursorWithProjection() throws Exception { StepVerifier .create(template.dropCollection(Capped.class) // @@ -329,10 +329,10 @@ interface ReactivePersonRepository extends ReactiveMongoRepository { - @InfiniteStream + @Tailable Flux findByKey(String key); - @InfiniteStream + @Tailable Flux findProjectionByKey(String key); } diff --git a/src/main/asciidoc/reference/reactive-mongo-repositories.adoc b/src/main/asciidoc/reference/reactive-mongo-repositories.adoc index 3295a4e0c4..01dbf58581 100644 --- a/src/main/asciidoc/reference/reactive-mongo-repositories.adoc +++ b/src/main/asciidoc/reference/reactive-mongo-repositories.adoc @@ -188,18 +188,18 @@ public interface PersonRepository extends ReactiveMongoRepository { - @InfiniteStream + @Tailable Flux findByFirstname(String firstname); } @@ -208,6 +208,7 @@ Flux stream = repository.findByFirstname("Joe"); Disposable subscription = stream.doOnNext(person -> System.out.println(person)).subscribe(); + // … // Later: Dispose the stream