DATAMONGO-1539 - Polishing.
Renamed @Count and @Delete to @CountQuery and @DeleteQuery. Minor polishing in test cases and test repository methods. JavaDoc, formatting. Original pull request: #416.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
* Copyright 2016 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.
|
||||
@@ -20,27 +20,26 @@ import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
* Annotation to declare finder count queries directly on repository methods. Both attributes allow using a placeholder
|
||||
* notation of {@code ?0}, {@code ?1} and so on.
|
||||
*
|
||||
* @see DATAMONGO-1539
|
||||
*
|
||||
* @author Fırat KÜÇÜK
|
||||
* @author Oliver Gierke
|
||||
* @since 1.10
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
|
||||
@Documented
|
||||
@Query(count = true)
|
||||
public @interface Count {
|
||||
public @interface CountQuery {
|
||||
|
||||
/**
|
||||
* Takes a MongoDB JSON string to define the actual query to be executed. This one will take precedence over the
|
||||
* method name then.
|
||||
*
|
||||
* Alias for {@link Query#value}.
|
||||
* method name then. Alias for {@link Query#value}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
* Copyright 2016 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.
|
||||
@@ -20,27 +20,26 @@ import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
* Annotation to declare finder delete queries directly on repository methods. Both attributes allow using a placeholder
|
||||
* notation of {@code ?0}, {@code ?1} and so on.
|
||||
*
|
||||
* @see DATAMONGO-1539
|
||||
*
|
||||
* @author Fırat KÜÇÜK
|
||||
* @author Oliver Gierke
|
||||
* @since 1.10
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
|
||||
@Documented
|
||||
@Query(delete = true)
|
||||
public @interface Delete {
|
||||
public @interface DeleteQuery {
|
||||
|
||||
/**
|
||||
* Takes a MongoDB JSON string to define the actual query to be executed. This one will take precedence over the
|
||||
* method name then.
|
||||
*
|
||||
* Alias for {@link Query#value}.
|
||||
* method name then. Alias for {@link Query#value}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@@ -1311,22 +1311,19 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
/**
|
||||
* @see DATAMONGO-1539
|
||||
*/
|
||||
@Test
|
||||
public void countsPersonsByFirstname() {
|
||||
|
||||
long result = repository.countByThePersonsFirstname("Dave");
|
||||
assertThat(result, is(1L));
|
||||
}
|
||||
@Test
|
||||
public void countsPersonsByFirstname() {
|
||||
assertThat(repository.countByThePersonsFirstname("Dave"), is(1L));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAMONGO-1539
|
||||
*/
|
||||
@Test
|
||||
public void deletesPersonsByFirstname() {
|
||||
public void deletesPersonsByFirstname() {
|
||||
|
||||
repository.deleteByThePersonsFirstname("Dave");
|
||||
repository.deleteByThePersonsFirstname("Dave");
|
||||
|
||||
long result = repository.countByThePersonsFirstname("Dave");
|
||||
assertThat(result, is(0L));
|
||||
}
|
||||
assertThat(repository.countByThePersonsFirstname("Dave"), is(0L));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,25 +370,23 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query
|
||||
List<Person> findWithSpelByFirstnameForSpELExpressionWithParameterVariableOnly(@Param("firstname") String firstname);
|
||||
|
||||
/**
|
||||
* Returns the count of {@link Person} with the given firstname. Uses {@link Count} annotation to define the query
|
||||
* to be executed.
|
||||
* Returns the count of {@link Person} with the given firstname. Uses {@link CountQuery} annotation to define the
|
||||
* query to be executed.
|
||||
*
|
||||
* @see DATAMONGO-1539
|
||||
*
|
||||
* @param firstname
|
||||
* @return
|
||||
*/
|
||||
@Count(value = "{ 'firstname' : ?0 }")
|
||||
@CountQuery("{ 'firstname' : ?0 }")
|
||||
long countByThePersonsFirstname(String firstname);
|
||||
|
||||
/**
|
||||
* Deletes {@link Person} entities with the given firstname. Uses {@link Delete} annotation to define the query
|
||||
* Deletes {@link Person} entities with the given firstname. Uses {@link DeleteQuery} annotation to define the query
|
||||
* to be executed.
|
||||
*
|
||||
* @see DATAMONGO-1539
|
||||
*
|
||||
* @param firstname
|
||||
*/
|
||||
@Delete(value = "{ 'firstname' : ?0 }")
|
||||
@DeleteQuery("{ 'firstname' : ?0 }")
|
||||
void deleteByThePersonsFirstname(String firstname);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user