From 519d02fef64f5d1dd9aa4c9a522579f3ff8e6a57 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 22 Oct 2024 08:50:15 +0200 Subject: [PATCH] Add test for stored procedures accepting array types. Closes #3081 --- .../PostgresStoredProcedureIntegrationTests.java | 16 ++++++++++++++++ .../scripts/postgres-stored-procedures.sql | 10 ++++++++++ 2 files changed, 26 insertions(+) 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 d10a3b83d..eaf489fdc 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 @@ -159,6 +159,14 @@ class PostgresStoredProcedureIntegrationTests { assertThat(results).containsKey("some_cursor"); } + @Test // GH-3081 + void supportsArrayTypes() { + + String result = repository.accept_array(new String[] { "one", "two" }); + + assertThat(result).isEqualTo("[1:2]"); + } + @Entity @NamedStoredProcedureQuery( // name = "get_employees_postgres", // @@ -177,6 +185,11 @@ class PostgresStoredProcedureIntegrationTests { @StoredProcedureParameter(mode = ParameterMode.REF_CURSOR, name = "some_cursor", type = void.class), @StoredProcedureParameter(mode = ParameterMode.OUT, name = "result1", type = Integer.class), @StoredProcedureParameter(mode = ParameterMode.OUT, name = "result2", type = Integer.class) }) + @NamedStoredProcedureQuery( // + name = "Employee.accept_array", // + procedureName = "accept_array", // + parameters = { @StoredProcedureParameter(mode = ParameterMode.IN, name = "some_chars", type = String[].class), + @StoredProcedureParameter(mode = ParameterMode.OUT, name = "dims", type = String.class) }) @NamedStoredProcedureQuery( // name = "positional_inout", // procedureName = "positional_inout_parameter_issue3460", // @@ -260,6 +273,9 @@ class PostgresStoredProcedureIntegrationTests { @Procedure(value = "get_employees_count") Integer noResultSet(); + @Procedure(value = "accept_array") + String accept_array(String[] some_chars); + @Procedure(value = "multiple_out") Map multiple_out(int someNumber); 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 cb08f096c..2f5d9a7fe 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 @@ -65,3 +65,13 @@ BEGIN OPEN some_cursor FOR SELECT COUNT(*) FROM employee; END; $BODY$;; + +CREATE OR REPLACE PROCEDURE accept_array(IN some_chars VARCHAR(255)[], + OUT dims VARCHAR(255)) + LANGUAGE 'plpgsql' +AS +$BODY$ +BEGIN + dims = array_dims(some_chars); +END; +$BODY$;;