From 089ea83b01e044659843420af2e3679c586827c6 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 28 Apr 2014 12:49:17 +0200 Subject: [PATCH] Adapted JPA 2.1 example to latest changes in Spring Data JPA. Changed method to derive the stored procedure metadata to be named after the stored procedure so that the name doesn't have to be customized on the annotation. Switched to Spring Data JPA master branch artifact as the stored procedure support has been merged recently. --- jpa/jpa21/README.md | 6 +++--- jpa/jpa21/pom.xml | 2 +- .../springdata/jpa/storedprocedures/UserRepository.java | 4 ++-- .../storedprocedures/UserRepositoryIntegrationTests.java | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/jpa/jpa21/README.md b/jpa/jpa21/README.md index b99fb4d7..5b7ea2db 100644 --- a/jpa/jpa21/README.md +++ b/jpa/jpa21/README.md @@ -44,11 +44,11 @@ public interface UserRepository extends CrudRepository { Integer plus1BackedByOtherNamedStoredProcedure(@Param("arg") Integer arg); // Directly map the method to the stored procedure in the database (to avoid the annotation madness on your domain classes). - @Procedure("plus1inout") - Integer derivedStoredProcedureDeclaration(Integer arg); + @Procedure + Integer plus1inout(Integer arg); } ``` Calling `UserRepository.plus1BackedByOtherNamedStoredProcedure(…)` will execute the stored procedure `plus1inout` using the meta-data declared on the `User` domain class. -`UserRepository.derivedStoredProcedureDeclaration(…)` will use the stored procedure name declared in the annotation and default to positional parameter binding and expect a single output parameter of the backing stored procedure. \ No newline at end of file +`UserRepository.plus1inout(…)` will derive stored procedure metadata from the repository and default to positional parameter binding and expect a single output parameter of the backing stored procedure. \ No newline at end of file diff --git a/jpa/jpa21/pom.xml b/jpa/jpa21/pom.xml index 67a63ec4..b7081de3 100644 --- a/jpa/jpa21/pom.xml +++ b/jpa/jpa21/pom.xml @@ -12,7 +12,7 @@ Spring Data JPA - JPA 2.1 specific features - 1.6.0.DATAJPA-455-SNAPSHOT + 1.6.0.BUILD-SNAPSHOT \ No newline at end of file diff --git a/jpa/jpa21/src/main/java/example/springdata/jpa/storedprocedures/UserRepository.java b/jpa/jpa21/src/main/java/example/springdata/jpa/storedprocedures/UserRepository.java index 32922037..3f721e7a 100644 --- a/jpa/jpa21/src/main/java/example/springdata/jpa/storedprocedures/UserRepository.java +++ b/jpa/jpa21/src/main/java/example/springdata/jpa/storedprocedures/UserRepository.java @@ -42,6 +42,6 @@ public interface UserRepository extends CrudRepository { * Directly map the method to the stored procedure in the database (to avoid the annotation madness on your domain * classes). */ - @Procedure("plus1inout") - Integer derivedStoredProcedureDeclaration(Integer arg); + @Procedure + Integer plus1inout(Integer arg); } diff --git a/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java b/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java index 80b6c554..8f671a75 100644 --- a/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java +++ b/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java @@ -55,7 +55,7 @@ public class UserRepositoryIntegrationTests { */ @Test public void invokeDerivedStoredProcedure() { - assertThat(repository.derivedStoredProcedureDeclaration(1), is(2)); + assertThat(repository.plus1inout(1), is(2)); } // This is what it would look like implemented manually.