Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.data.annotation.QueryAnnotation;

/**
* Annotation to declare meta-information (execution time, cursor size, disk usage) for query methods.
* <p>
* Annotating a repository method with this annotation forces the method to be implemented as query method (i.e. using
* this annotation on an overridden method from a base interface or fragment interface), similar to using
* {@link Query @Query}.
*
* @author Christoph Strobl
* @author Mark Paluch
Expand All @@ -37,7 +31,6 @@
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Documented
@QueryAnnotation
public @interface Meta {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query
* @param lastname
* @return
*/
@Meta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here? Seems like it was intended to be part of a Meta related test, but the test didn't make it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an leftover from research on the actual behavior, it can be removed.

List<Person> findByLastname(String lastname);

List<Person> findByLastnameStartsWith(String prefix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.data.mongodb.core.convert.NoOpDbRefResolver;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.core.query.TextCriteria;
import org.springframework.data.mongodb.repository.Meta;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Person;
import org.springframework.data.mongodb.repository.Person.Sex;
Expand Down Expand Up @@ -127,6 +128,12 @@ void doesNotDeriveFieldSpecForNormalDomainType() {
assertThat(deriveQueryFromMethod("findPersonBy", new Object[0]).getFieldsObject()).isEmpty();
}

@Test // GH-4852
void appliesMetaToPartTreeQuery() {
assertThat(deriveQueryFromMethod("findPersonBy", new Object[0]).getMeta()
.getMaxTimeMsec()).isEqualTo(1234L);
}

@Test // DATAMONGO-1345
void restrictsQueryToFieldsRequiredForProjection() {

Expand Down Expand Up @@ -193,7 +200,10 @@ private org.springframework.data.mongodb.core.query.Query deriveQueryFromMethod(
PartTreeMongoQuery partTreeQuery = createQueryForMethod(method, types);

MongoParameterAccessor accessor = new MongoParametersParameterAccessor(partTreeQuery.getQueryMethod(), args);
return partTreeQuery.createQuery(new ConvertingParameterAccessor(mongoOperationsMock.getConverter(), accessor));

org.springframework.data.mongodb.core.query.Query query = partTreeQuery.createQuery(new ConvertingParameterAccessor(mongoOperationsMock.getConverter(), accessor));
partTreeQuery.applyQueryMetaAttributesWhenPresent(query);
return query;
}

private PartTreeMongoQuery createQueryForMethod(String methodName, Class<?>... paramTypes) {
Expand Down Expand Up @@ -230,6 +240,7 @@ interface Repo extends MongoRepository<Person, Long> {
@Query(fields = "{ 'firstname }")
Person findByAge(Integer age);

@Meta(maxExecutionTimeMs = 1234)
Person findPersonBy();

PersonProjection findPersonProjectedBy();
Expand Down