Skip to content

Commit 4c18cf9

Browse files
authored
Merge pull request #86 from zalando-stups/gh-69-enum-mapping-from-explicit-schema
Fix a bug with enum type mapping from explicit schema
2 parents b36942f + 87d8977 commit 4c18cf9

24 files changed

+361
-102
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
RESET role;
2+
3+
CREATE SCHEMA ztest_schema3
4+
AUTHORIZATION zalando_api_owner;
5+
6+
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA ztest_schema3 REVOKE EXECUTE ON FUNCTIONS FROM public;
7+
ALTER DEFAULT PRIVILEGES FOR ROLE zalando_api_owner IN SCHEMA ztest_schema3 REVOKE EXECUTE ON FUNCTIONS FROM public;
8+
ALTER DEFAULT PRIVILEGES IN SCHEMA ztest_schema3 REVOKE EXECUTE ON FUNCTIONS FROM public;
9+
10+
ALTER DEFAULT PRIVILEGES FOR ROLE zalando_api_owner IN SCHEMA ztest_schema3 GRANT EXECUTE ON FUNCTIONS TO zalando_api_executor;
11+
12+
GRANT USAGE ON SCHEMA ztest_schema3 TO zalando_api_usage;
13+
14+
SET ROLE TO zalando_api_owner;
15+
16+
SET search_path TO ztest_schema3, public;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TYPE color AS ENUM (
2+
'RED',
3+
'BLUE',
4+
'GREEN',
5+
'ORANGE'
6+
);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TYPE CAR AS
2+
(
3+
id BIGINT,
4+
brand TEXT,
5+
color ztest_schema3.COLOR
6+
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TYPE CUSTOMER_ADDRESS AS
2+
(
3+
street VARCHAR,
4+
house_number INT
5+
);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TYPE CUSTOMER AS
2+
(
3+
id BIGINT,
4+
name TEXT,
5+
address ztest_schema3.CUSTOMER_ADDRESS
6+
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CREATE OR REPLACE FUNCTION get_all_cars()
2+
RETURNS SETOF ztest_schema3.CAR AS
3+
$body$
4+
BEGIN
5+
RETURN QUERY SELECT t.id, t.brand,
6+
t.color
7+
FROM (VALUES (1::BIGINT, 'Toyota'::TEXT, 'RED'::ztest_schema3.COLOR),
8+
(2::BIGINT, 'Mercedes'::TEXT, 'BLUE'::ztest_schema3.COLOR))
9+
AS t (id, brand, color);
10+
END;
11+
$body$
12+
LANGUAGE plpgsql
13+
SECURITY DEFINER
14+
COST 100;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE OR REPLACE FUNCTION get_all_customers()
2+
RETURNS SETOF ztest_schema3.CUSTOMER AS
3+
$body$
4+
BEGIN
5+
RETURN QUERY SELECT t.id, t.name,
6+
t.address
7+
FROM (VALUES (1::BIGINT, 'John'::TEXT, ROW('First street', 15)::ztest_schema3.CUSTOMER_ADDRESS))
8+
AS t (id, name, address);
9+
END;
10+
$body$
11+
LANGUAGE plpgsql
12+
SECURITY DEFINER
13+
COST 100;

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
version: '3'
22
services:
33
db:
4-
image: 'postgres:9.6.10'
4+
image: 'postgres:13'
55
environment:
66
POSTGRES_PASSWORD: 'postgres'
77
ports:
8-
- '5432:5432'
8+
- '5432:5432'

pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959

6060
<properties>
6161
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
62-
<maven.compiler.source>1.8</maven.compiler.source>
63-
<maven.compiler.target>1.8</maven.compiler.target>
62+
<maven.compiler.source>11</maven.compiler.source>
63+
<maven.compiler.target>11</maven.compiler.target>
6464
<spring.version>5.2.12.RELEASE</spring.version>
6565
<postgresql.version>42.2.14</postgresql.version>
6666
</properties>
@@ -198,7 +198,7 @@
198198
<plugin>
199199
<groupId>org.owasp</groupId>
200200
<artifactId>dependency-check-maven</artifactId>
201-
<version>6.0.5</version>
201+
<version>6.1.6</version>
202202
<executions>
203203
<execution>
204204
<goals>
@@ -434,6 +434,7 @@
434434
CREATE EXTENSION hstore;
435435
DROP SCHEMA IF EXISTS ztest_schema1 CASCADE;
436436
DROP SCHEMA IF EXISTS ztest_schema2 CASCADE;
437+
DROP SCHEMA IF EXISTS ztest_schema3 CASCADE;
437438
</sqlCommand>
438439
<onError>continue</onError>
439440
</configuration>

src/main/java/org/zalando/typemapper/core/TypeMapper.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public ITEM mapRow(final ResultSet set, final int count) throws SQLException {
7171
}
7272

7373
private ResultTree extractResultTree(final ResultSet set) throws SQLException {
74-
LOG.trace("Extracting result tree");
7574

7675
// cast to obtain more information from the result set.
7776
final PgResultSet pgSet = set.unwrap(PgResultSet.class);
@@ -100,7 +99,7 @@ private ResultTree extractResultTree(final ResultSet set) throws SQLException {
10099
int j = 1;
101100
for (final String fieldValue : fieldValues) {
102101
final DbTypeField fieldDef = function.getFieldByPos(j);
103-
DbResultNode currentNode = null;
102+
DbResultNode currentNode;
104103
if (fieldDef.getType().equals("USER-DEFINED")) {
105104
currentNode = new ObjectResultNode(fieldValue, fieldDef.getName(), fieldDef.getTypeName(),
106105
fieldDef.getTypeId(), pgSet.getStatement().getConnection());
@@ -141,7 +140,7 @@ private ResultTree extractResultTree(final ResultSet set) throws SQLException {
141140
tree.addChild(node);
142141
}
143142

144-
LOG.trace("Extracted ResultTree: {}", tree);
143+
LOG.debug("Extracted ResultTree: {}", tree);
145144

146145
return tree;
147146
}

0 commit comments

Comments
 (0)