From 199317bf70777d1da1f956a013a34ac8febc4b28 Mon Sep 17 00:00:00 2001 From: "Greg L. Turnquist" Date: Tue, 30 May 2023 10:48:42 -0500 Subject: [PATCH] Upgrade to Postgres 11 for integration testing. Postgres stored procedures requires some adjustments in order to upgrade to Postgres 11. See #2903 --- ...PostgresStoredProcedureIntegrationTests.java | 4 +++- ...edProcedureNullHandlingIntegrationTests.java | 4 +++- .../postgres-nullable-stored-procedures.sql | 8 ++------ .../scripts/postgres-stored-procedures.sql | 17 ++++------------- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureIntegrationTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureIntegrationTests.java index 10c07c1a78..96c0f5e710 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureIntegrationTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureIntegrationTests.java @@ -47,6 +47,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.query.Procedure; +import org.springframework.data.jpa.util.DisabledOnHibernate61; import org.springframework.data.jpa.util.DisabledOnHibernate62; import org.springframework.jdbc.datasource.init.DataSourceInitializer; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; @@ -68,6 +69,7 @@ * @author Greg Turnquist * @author Yanming Zhou */ +@DisabledOnHibernate61 // GH-2903 @Transactional @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = PostgresStoredProcedureIntegrationTests.Config.class) @@ -203,7 +205,7 @@ static class Config { @Bean(initMethod = "start", destroyMethod = "stop") public PostgreSQLContainer container() { - return new PostgreSQLContainer<>("postgres:10.21") // + return new PostgreSQLContainer<>("postgres:15.3") // .withUsername("postgres"); } diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureNullHandlingIntegrationTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureNullHandlingIntegrationTests.java index 10aa204f37..bf87de2be4 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureNullHandlingIntegrationTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureNullHandlingIntegrationTests.java @@ -44,6 +44,7 @@ import org.springframework.data.jpa.repository.Temporal; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.query.Procedure; +import org.springframework.data.jpa.util.DisabledOnHibernate61; import org.springframework.jdbc.datasource.init.DataSourceInitializer; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; @@ -62,6 +63,7 @@ * * @author Greg Turnquist */ +@DisabledOnHibernate61 // GH-2903 @Transactional @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = PostgresStoredProcedureNullHandlingIntegrationTests.Config.class) @@ -109,7 +111,7 @@ static class Config { @Bean(initMethod = "start", destroyMethod = "stop") public PostgreSQLContainer container() { - return new PostgreSQLContainer<>("postgres:10.21") // + return new PostgreSQLContainer<>("postgres:15.3") // .withUsername("postgres"); } diff --git a/spring-data-jpa/src/test/resources/scripts/postgres-nullable-stored-procedures.sql b/spring-data-jpa/src/test/resources/scripts/postgres-nullable-stored-procedures.sql index 03a619176e..82ee419ab6 100644 --- a/spring-data-jpa/src/test/resources/scripts/postgres-nullable-stored-procedures.sql +++ b/spring-data-jpa/src/test/resources/scripts/postgres-nullable-stored-procedures.sql @@ -6,8 +6,7 @@ CREATE TABLE test_model CONSTRAINT test_model_pk PRIMARY KEY (ID) );; -CREATE OR REPLACE FUNCTION countByUuid(this_uuid uuid) - RETURNS int +CREATE OR REPLACE PROCEDURE countByUuid(IN this_uuid uuid) LANGUAGE 'plpgsql' AS $BODY$ @@ -18,13 +17,11 @@ BEGIN INTO c FROM test_model WHERE test_model.uuid = this_uuid; - RETURN c; END; $BODY$ ;; -CREATE OR REPLACE FUNCTION countByLocalDate(this_local_date DATE) - RETURNS int +CREATE OR REPLACE PROCEDURE countByLocalDate(IN this_local_date DATE) LANGUAGE 'plpgsql' AS $BODY$ @@ -35,7 +32,6 @@ BEGIN INTO c FROM test_model WHERE test_model.local_date = this_local_date; - RETURN c; END; $BODY$ ;; diff --git a/spring-data-jpa/src/test/resources/scripts/postgres-stored-procedures.sql b/spring-data-jpa/src/test/resources/scripts/postgres-stored-procedures.sql index 9d8226ee75..59097c8515 100644 --- a/spring-data-jpa/src/test/resources/scripts/postgres-stored-procedures.sql +++ b/spring-data-jpa/src/test/resources/scripts/postgres-stored-procedures.sql @@ -8,38 +8,29 @@ CREATE TABLE employee INSERT INTO employee (ID, NAME) VALUES (3, 'Fanny');; INSERT INTO employee (ID, NAME) VALUES (4, 'Gabriel');; -CREATE OR REPLACE FUNCTION get_employees() - RETURNS refcursor +CREATE OR REPLACE PROCEDURE get_employees(OUT ref refcursor) LANGUAGE 'plpgsql' AS $BODY$ -DECLARE - ref refcursor; BEGIN OPEN ref FOR SELECT * FROM employee; - RETURN ref; END; $BODY$;; -CREATE OR REPLACE FUNCTION get_employees_count() - RETURNS integer +CREATE OR REPLACE PROCEDURE get_employees_count(OUT results integer) LANGUAGE 'plpgsql' AS $BODY$ BEGIN - RETURN (SELECT COUNT(*) FROM employee); + results = (SELECT COUNT(*) FROM employee); END; $BODY$;; -CREATE OR REPLACE FUNCTION get_single_employee() - RETURNS refcursor +CREATE OR REPLACE PROCEDURE get_single_employee(OUT ref refcursor) LANGUAGE 'plpgsql' AS $BODY$ -DECLARE - ref refcursor; BEGIN OPEN ref FOR SELECT * FROM employee WHERE employee.ID = 3; - RETURN ref; END; $BODY$;;