#53 - Enable -parameters for compilation.

Removed obsolete @Param annotations from repository interfaces. Upgraded to Fowler snapshots for JPA 2.1 examples as we need a fix in derived stored procedure execution to work correctly.

Related issues: DATAJPA-681.
This commit is contained in:
Oliver Gierke
2015-02-27 19:26:37 +01:00
parent a50a3450cd
commit 797db3eece
7 changed files with 35 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2013-2014 the original author or authors. * Copyright 2013-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -55,6 +55,6 @@ public interface UserRepository extends CrudRepository<User, Long>, UserReposito
* @param firstname * @param firstname
* @return * @return
*/ */
@Query("select u from User u where u.firstname = ?1") @Query("select u from User u where u.firstname = :firstname")
List<User> findByFirstname(String firstname); List<User> findByFirstname(String firstname);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2013-2014 the original author or authors. * Copyright 2013-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@ import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import com.google.common.base.Optional; import com.google.common.base.Optional;
@@ -63,19 +62,18 @@ public interface SimpleUserRepository extends CrudRepository<User, Long> {
* @param firstname * @param firstname
* @return * @return
*/ */
@Query("select u from User u where u.firstname = ?") @Query("select u from User u where u.firstname = :firstname")
List<User> findByFirstname(String firstname); List<User> findByFirstname(String firstname);
/** /**
* Returns all users with the given name as first- or lastname. Makes use of the {@link Param} annotation to use named * Returns all users with the given name as first- or lastname. This makes the query to method relation much more
* parameters in queries. This makes the query to method relation much more refactoring safe as the order of the * refactoring safe as the order of the method parameters is completely irrelevant.
* method parameters is completely irrelevant.
* *
* @param name * @param name
* @return * @return
*/ */
@Query("select u from User u where u.firstname = :name or u.lastname = :name") @Query("select u from User u where u.firstname = :name or u.lastname = :name")
List<User> findByFirstnameOrLastname(@Param("name") String name); List<User> findByFirstnameOrLastname(String name);
/** /**
* Returns the total number of entries deleted as their lastnames match the given one. * Returns the total number of entries deleted as their lastnames match the given one.
@@ -126,5 +124,5 @@ public interface SimpleUserRepository extends CrudRepository<User, Long> {
* @return * @return
*/ */
@Query("select u from User u where u.firstname = :#{#user.firstname} or u.lastname = :#{#user.lastname}") @Query("select u from User u where u.firstname = :#{#user.firstname} or u.lastname = :#{#user.lastname}")
Iterable<User> findByFirstnameOrLastname(@Param("user") User user); Iterable<User> findByFirstnameOrLastname(User user);
} }

View File

@@ -11,4 +11,8 @@
<artifactId>spring-data-jpa-jpa21</artifactId> <artifactId>spring-data-jpa-jpa21</artifactId>
<name>Spring Data JPA - JPA 2.1 specific features</name> <name>Spring Data JPA - JPA 2.1 specific features</name>
<properties>
<spring-data-releasetrain.version>Fowler-BUILD-SNAPSHOT</spring-data-releasetrain.version>
</properties>
</project> </project>

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2013 the original author or authors. * Copyright 2013-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ import javax.persistence.EntityManager;
import org.springframework.data.jpa.repository.query.Procedure; import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
/** /**
* Simple repository interface for {@link User} instances. The interface is used to declare so called query methods, * Simple repository interface for {@link User} instances. The interface is used to declare so called query methods,
@@ -36,7 +35,7 @@ public interface UserRepository extends CrudRepository<User, Long> {
* @see User * @see User
*/ */
@Procedure(name = "User.plus1") @Procedure(name = "User.plus1")
Integer plus1BackedByOtherNamedStoredProcedure(@Param("arg") Integer arg); Integer plus1BackedByOtherNamedStoredProcedure(Integer arg);
/** /**
* Directly map the method to the stored procedure in the database (to avoid the annotation madness on your domain * Directly map the method to the stored procedure in the database (to avoid the annotation madness on your domain

16
pom.xml
View File

@@ -72,6 +72,22 @@
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
<repositories> <repositories>
<repository> <repository>
<id>spring-libs-snapshot</id> <id>spring-libs-snapshot</id>

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014 the original author or authors. * Copyright 2014-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,16 +16,14 @@
package example.stores; package example.stores;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
/** /**
* Spring configuration class main application bootstrap point. * Spring configuration class main application bootstrap point.
* *
* @author Oliver Gierke * @author Oliver Gierke
*/ */
@EnableAutoConfiguration @SpringBootApplication
@ComponentScan
public class StoreApp { public class StoreApp {
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014 the original author or authors. * Copyright 2014-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.geo.Distance; import org.springframework.data.geo.Distance;
import org.springframework.data.geo.Point; import org.springframework.data.geo.Point;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RestResource; import org.springframework.data.rest.core.annotation.RestResource;
/** /**
@@ -32,6 +31,5 @@ import org.springframework.data.rest.core.annotation.RestResource;
public interface StoreRepository extends PagingAndSortingRepository<Store, String> { public interface StoreRepository extends PagingAndSortingRepository<Store, String> {
@RestResource(rel = "by-location") @RestResource(rel = "by-location")
Page<Store> findByAddressLocationNear(// Page<Store> findByAddressLocationNear(Point location, Distance distance, Pageable pageable);
@Param("location") Point location, @Param("distance") Distance distance, Pageable pageable);
} }