Skip to content

Commit faab7a2

Browse files
committed
Update README and test postgres version
1 parent 5f48783 commit faab7a2

File tree

2 files changed

+86
-47
lines changed

2 files changed

+86
-47
lines changed

README.md

Lines changed: 85 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ SProcWrapper
66
[![Maven Central](https://img.shields.io/maven-central/v/org.zalando/zalando-sprocwrapper.svg)](https://maven-badges.herokuapp.com/maven-central/org.zalando/zalando-sprocwrapper)
77
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/zalando/problem-spring-web/master/LICENSE)
88

9+
Library to make PostgreSQL stored procedures(SProcs) available through simple Java "SProcService" interfaces including
10+
automatic object serialization and deserialization (using typemapper and convention-over-configuration).
911

10-
11-
Library to make PostgreSQL stored procedures(SProcs) available through simple Java "SProcService" interfaces including automatic object serialization and deserialization (using typemapper and convention-over-configuration).
12-
13-
Supports horizontal database sharding (partition/access logic lies within application), easy use of `pg_advisory_lock` through annotations to ensure single Java node execution, configurable statement timeouts per stored procedure, and PostgreSQL types including enums and hstore.
12+
Supports horizontal database sharding (partition/access logic lies within application), easy use of `pg_advisory_lock`
13+
through annotations to ensure single Java node execution, configurable statement timeouts per stored procedure, and
14+
PostgreSQL types including enums and hstore.
1415

1516
Usage
1617
------------
1718
To use SProcWrapper, add the following lines to your pom.xml:
1819

1920
```xml
21+
2022
<dependency>
2123
<groupId>org.zalando</groupId>
2224
<artifactId>zalando-sprocwrapper</artifactId>
@@ -27,59 +29,64 @@ To use SProcWrapper, add the following lines to your pom.xml:
2729
Type Mapping
2830
------------
2931

30-
SProcWrapper provides an efficient and easy-to-use mechanism for translating values from database to Java objects and vice-versa. It allows us to map not only primitive types, but also complex types (Java domain objects).
32+
SProcWrapper provides an efficient and easy-to-use mechanism for translating values from database to Java objects and
33+
vice-versa. It allows us to map not only primitive types, but also complex types (Java domain objects).
3134

3235
Here are some examples!
3336

3437
Using basic types:
3538

3639
```java
40+
3741
@SProcService
3842
public interface CustomerSProcService {
39-
@SProcCall
40-
int registerCustomer(@SProcParam String name, @SProcParam String email);
43+
@SProcCall
44+
int registerCustomer(@SProcParam String name, @SProcParam String email);
4145
}
4246
```
4347

4448
```sql
45-
CREATE FUNCTION register_customer(p_name text, p_email text)
46-
RETURNS int AS
49+
CREATE FUNCTION register_customer(p_name TEXT, p_email TEXT)
50+
RETURNS INT AS
4751
$$
48-
INSERT INTO z_data.customer(c_name, c_email)
49-
VALUES (p_name, p_email)
50-
RETURNING c_id
52+
INSERT INTO z_data.customer(c_name, c_email)
53+
VALUES (p_name, p_email)
54+
RETURNING c_id
5155
$$
52-
LANGUAGE 'sql' SECURITY DEFINER;
56+
LANGUAGE 'sql'
57+
SECURITY DEFINER;
5358
```
5459

5560
And a complex type:
5661

5762
```java
63+
5864
@SProcService
5965
public interface OrderSProcService {
60-
@SProcCall
61-
List<Order> findOrders(@SProcParam String email);
66+
@SProcCall
67+
List<Order> findOrders(@SProcParam String email);
6268
}
6369
```
6470

6571
```sql
66-
CREATE FUNCTION find_orders(p_email text,
67-
OUT order_id int,
68-
OUT order_date timestamp,
69-
OUT shipping_address order_address)
70-
RETURNS SETOF RECORD AS
72+
CREATE FUNCTION find_orders(p_email TEXT,
73+
OUT order_id INT,
74+
OUT order_date TIMESTAMP,
75+
OUT shipping_address ORDER_ADDRESS)
76+
RETURNS SETOF RECORD AS
7177
$$
72-
SELECT o_id,
73-
o_date,
74-
ROW(oa_street, oa_city, oa_country)::order_address
75-
FROM z_data.order
76-
JOIN z_data.order_address
77-
ON oa_order_id = o_id
78-
JOIN z_data.customer
79-
ON c_id = o_customer_id
80-
WHERE c_email = p_email
78+
SELECT o_id,
79+
o_date,
80+
ROW (oa_street, oa_city, oa_country)::ORDER_ADDRESS
81+
FROM z_data.order
82+
JOIN z_data.order_address
83+
ON oa_order_id = o_id
84+
JOIN z_data.customer
85+
ON c_id = o_customer_id
86+
WHERE c_email = p_email
8187
$$
82-
LANGUAGE 'sql' SECURITY DEFINER;
88+
LANGUAGE 'sql'
89+
SECURITY DEFINER;
8390
```
8491

8592
Please check [unit/integration tests](src/test/java/de/zalando/sprocwrapper) for more examples.
@@ -110,40 +117,72 @@ The following table shows the mapping between a database type and a Java type:
110117
| array | java.util.List / java.util.Set |
111118
| hstore | java.util.Map<java.lang.String, java.lang.String> |
112119

113-
Note: SProcwrapper doesn't support functions returning arrays as a single output. If one wants to return a collection, please return a SETOF instead.
120+
Note: SProcwrapper doesn't support functions returning arrays as a single output. If one wants to return a collection,
121+
please return a SETOF instead.
122+
123+
### Configure global value transformer loader
124+
125+
Global value transformer loader loads global value transformers from the classpath. By default, it searches value
126+
transformers in `org.zalando` package. You can change this behaviour using
127+
the `global.value.transformer.search.namespace` environment variable:
128+
129+
```shell
130+
EXPORT global.value.transformer.search.namespace="my.package"
131+
```
132+
133+
or by calling a method:
134+
135+
```java
136+
GlobalValueTransformerLoader.changeNamespaceToScan("my.package");
137+
```
138+
139+
It is also possible to provide multiple scan packages using `;` separator:
140+
141+
```shell
142+
EXPORT global.value.transformer.search.namespace="my.package;another.package;third.package"
143+
```
114144

115145
Prerequisites
116146
-------------
117147

118-
* Java 8
119-
* To compile, one should use [Maven](http://maven.apache.org/) 2.1.0 or above
148+
* Java 11
149+
* To compile, one should use [Maven](http://maven.apache.org/) 3.0.0 or above
120150

121151
Dependencies
122152
------------
123153

124-
* Spring Framework
125-
* PostgreSQL JDBC driver ;)
126-
* Google Guava
127-
* and more see [pom.xml](pom.xml) for details
154+
* Spring Framework 5.x
155+
* PostgreSQL JDBC driver ;)
156+
* Google Guava
157+
158+
See [pom.xml](pom.xml) for the full list of dependencies.
128159

129160
How to run integration tests
130161
----------------------------
131162

132163
The provided helper script will start a PostgreSQL instance with Docker on port 5432 and run integration tests:
133-
134-
./test.sh
135-
136-
You can use the provided Vagrant box to run the script in.
164+
```shell
165+
./test.sh
166+
```
137167

138168
Known issues
139169
------------
140170

141-
* PostgreSQL JDBC driver does not honor identical type names in different schemas, this may lead to issues if typemapper is used where types are present with equal name in more than one schema (this problem is solved now with the commit [3ca94e64d6322fa91c477200bfb3719deaeac153](https://github.com/pgjdbc/pgjdbc/commit/3ca94e64d6322fa91c477200bfb3719deaeac153) to [pgjdbc](https://github.com/pgjdbc/pgjdbc/) driver);
171+
* PostgreSQL JDBC driver does not honor identical type names in different schemas, this may lead to issues if typemapper
172+
is used where types are present with equal name in more than one schema (this problem is solved now with the
173+
commit [3ca94e64d6322fa91c477200bfb3719deaeac153](https://github.com/pgjdbc/pgjdbc/commit/3ca94e64d6322fa91c477200bfb3719deaeac153)
174+
to [pgjdbc](https://github.com/pgjdbc/pgjdbc/) driver);
142175
* PostgreSQL domains are not supported as for now;
143-
* PostgreSQL `hstore` type is mapped from and to `Map<String,String>`, there is no way to use `Map` of different types for now;
144-
* Two different datasources with the same JDBC URL and different search paths might not work properly when we have types with the identical name;
145-
* SProcWrapper relies on the search path to resolve conflicting types with the same name (right now, we are not checking the schema). If one specifies the schema of the stored procedure's return type, SProcWrapper might end up using the wrong one, because it will use the `search_path` to resolve the conflict. For more info check test: `SimpleIT.testTypeLookupBugWithSchema`;
146-
* For integration with Spring's transaction management use the `TransactionAwareDataSourceProxy` as the data source injected into the data source provider.
176+
* PostgreSQL `hstore` type is mapped from and to `Map<String,String>`, there is no way to use `Map` of different types
177+
for now;
178+
* Two different datasources with the same JDBC URL and different search paths might not work properly when we have types
179+
with the identical name;
180+
* SProcWrapper relies on the search path to resolve conflicting types with the same name (right now, we are not checking
181+
the schema). If one specifies the schema of the stored procedure's return type, SProcWrapper might end up using the
182+
wrong one, because it will use the `search_path` to resolve the conflict. For more info check
183+
test: `SimpleIT.testTypeLookupBugWithSchema`;
184+
* For integration with Spring's transaction management use the `TransactionAwareDataSourceProxy` as the data source
185+
injected into the data source provider.
147186

148187
Documentation
149188
-------------

test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if nc -w 5 -z localhost 5432; then
1616
exit 1
1717
fi
1818

19-
PGVERSION=9.6.10
19+
PGVERSION=13
2020

2121
container=$(docker ps | grep postgres:$PGVERSION)
2222
if [ -z "$container" ]; then

0 commit comments

Comments
 (0)