Skip to content

Commit

Permalink
Upgrade to Postgres 11 for integration testing.
Browse files Browse the repository at this point in the history
Postgres stored procedures requires some adjustments in order to upgrade to Postgres 11.

See #2903
  • Loading branch information
gregturn committed May 30, 2023
1 parent 8c7b469 commit 199317b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -68,6 +69,7 @@
* @author Greg Turnquist
* @author Yanming Zhou
*/
@DisabledOnHibernate61 // GH-2903
@Transactional
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = PostgresStoredProcedureIntegrationTests.Config.class)
Expand Down Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -62,6 +63,7 @@
*
* @author Greg Turnquist
*/
@DisabledOnHibernate61 // GH-2903
@Transactional
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = PostgresStoredProcedureNullHandlingIntegrationTests.Config.class)
Expand Down Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand All @@ -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$
Expand All @@ -35,7 +32,6 @@ BEGIN
INTO c
FROM test_model
WHERE test_model.local_date = this_local_date;
RETURN c;
END;
$BODY$
;;
Original file line number Diff line number Diff line change
Expand Up @@ -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$;;

0 comments on commit 199317b

Please sign in to comment.