diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/annotation/Query.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/annotation/Query.java index aade74435..3c0327b48 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/annotation/Query.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/annotation/Query.java @@ -1,5 +1,5 @@ /** - * Copyright 2011 the original author or authors. + * Copyright 2011-2013 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. @@ -21,6 +21,8 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.springframework.data.annotation.QueryAnnotation; + /** * Field that provides access to an iterator which is created by applying the provided query starting at the current * entity-node. The result elements are automatically converted to appropriate element @@ -30,10 +32,12 @@ import java.lang.annotation.Target; * Iterable<Person> friends; * * @author Michael Hunger + * @author Thomas Darimont * @since 15.09.2010 */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD,ElementType.METHOD}) +@QueryAnnotation public @interface Query { /** * @return Query to be executed {self} will be provided by the node-id of the current entity other parameters (e.g. {name}) by the given named params diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/RedeclaringRepositoryMethodsRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/RedeclaringRepositoryMethodsRepository.java new file mode 100644 index 000000000..ba11a0142 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/RedeclaringRepositoryMethodsRepository.java @@ -0,0 +1,44 @@ +/** + * Copyright 2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.neo4j.repository; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.neo4j.annotation.Query; +import org.springframework.data.neo4j.conversion.EndResult; +import org.springframework.data.neo4j.model.Person; + +/** + * @author Thomas Darimont + */ +public interface RedeclaringRepositoryMethodsRepository extends GraphRepository { + + /** + * Should not find any persons at all. + */ + @Query("START n=node(*) where HAS(n.name) AND n.name='Bubu' return n") + EndResult findAll(); + + /** + * Should only find persons with the name 'Oliver'. + * + * @param page + * @return + */ + @Query("START n=node(*) where HAS(n.name) AND n.name='Oliver' return n") + Page findAll(Pageable page); +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/RedeclaringRepositoryMethodsTests.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/RedeclaringRepositoryMethodsTests.java new file mode 100644 index 000000000..ee16d7467 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/RedeclaringRepositoryMethodsTests.java @@ -0,0 +1,66 @@ +/** + * Copyright 2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.neo4j.repository; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.neo4j.conversion.EndResult; +import org.springframework.data.neo4j.model.Person; +import org.springframework.transaction.annotation.Transactional; + +/** + * @author Thomas Darimont + */ +@Transactional +public class RedeclaringRepositoryMethodsTests extends AbstractEntityBasedGraphRepositoryTests { + + @Autowired RedeclaringRepositoryMethodsRepository repository; + + /** + * @see DATAGRAPH-392 + */ + @Test + public void adjustedWellKnownPagedFindAllMethodShouldReturnOnlyTheUserWithFirstnameOliver() { + + Person ollie = repository.save(new Person("Oliver", 30)); + repository.save(new Person("Thomas", 30)); + + Page page = repository.findAll(new PageRequest(0, 2)); + + assertThat(page.getNumberOfElements(), is(1)); + assertThat(page.getContent().get(0).getName(), is(ollie.getName())); + } + + /** + * @see DATAGRAPH-392 + */ + @Test + public void adjustedWllKnownFindAllMethodShouldReturnAnEmptyList() { + + repository.save(new Person("Oliver", 30)); + repository.save(new Person("Thomas", 30)); + + EndResult result = repository.findAll(); + + assertThat(result.iterator().hasNext(), is(false)); + } +}