Skip to content

Commit 5540a93

Browse files
committed
Added documentation
New sections: - Type Mapping - Prerequisites
1 parent 5fad7d7 commit 5540a93

File tree

2 files changed

+111
-2
lines changed

2 files changed

+111
-2
lines changed

README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,117 @@ Library to make PostgreSQL stored procedures(SProcs) available through simple Ja
55

66
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.
77

8+
Type Mapping
9+
------------
10+
11+
The SprocWrapper provides and efficient and easy-to-use mechanimism for translatiing 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).
12+
13+
Here are some examples.
14+
15+
Basic type:
16+
17+
```java
18+
@SProcCall
19+
String getNameForId(@SProcParam int id);
20+
```
21+
22+
```sql
23+
CREATE FUNCTION get_name_for_id(p_id int) RETURNS text AS
24+
$$
25+
SELECT name
26+
FROM customer
27+
WHERE id = p_id
28+
$$ LANGUAGE ‘sql’;
29+
```
30+
31+
Complex type:
32+
33+
```java
34+
@SProcCall
35+
List<Order> findOrders(@SProcParam String email);
36+
```
37+
38+
```sql
39+
CREATE FUNCTION find_orders(p_email text,
40+
OUT order_id int,
41+
OUT order_date timestamp,
42+
OUT shipping_address order_address) RETURNS SETOF RECORD AS
43+
$$
44+
SELECT o_id,
45+
o_date,
46+
ROW(oa_street, oa_city, oa_country)::order_address
47+
FROM z_data.order
48+
JOIN z_data.order_address
49+
ON oa_order_id = o_id
50+
JOIN z_data.customer
51+
ON c_id = o_customer_id
52+
WHERE c_email = p_email
53+
$$
54+
LANGUAGE 'sql' SECURITY DEFINER;
55+
```
56+
57+
Supported data types:
58+
59+
Numeric Types:
60+
61+
| Database | JAVA |
62+
| ---------------- | -------------------- |
63+
| smallint | int |
64+
| integer | int |
65+
| bigint | long |
66+
| decimal | java.math.BigDecimal |
67+
| numeric | java.math.BigDecimal |
68+
| real | float |
69+
| double precision | double |
70+
| serial | int |
71+
| bigserial | long |
72+
73+
Character Types:
74+
75+
| Database | JAVA |
76+
| ---------------- | -------------------- |
77+
| varchar | String |
78+
| char | char |
79+
| text | String |
80+
81+
Date/Time Types:
82+
83+
| Database | JAVA |
84+
| ---------------- | -------------------- |
85+
| timestamp | java.sql.Timestamp |
86+
| date | java.sql.Timestamp |
87+
| time | java.sql.Timestamp |
88+
89+
Boolean Type:
90+
91+
| Database | JAVA |
92+
| ---------------- | -------------------- |
93+
| boolean | boolean |
94+
95+
Enumerated Types:
96+
97+
| Database | JAVA |
98+
| ---------------- | -------------------- |
99+
| enum | java.lang.Enum |
100+
101+
Container types:
102+
103+
| Database | JAVA |
104+
| ---------------- | ----------------------------- |
105+
| array | java.util.List/java.util.Set |
106+
| hstore | java.util.Map<String, String> |
107+
108+
109+
Note: Sprocwrapper doesn't support functions returning arrays as a single output. If one wants to return a collection, please return a SETOF instead.
110+
111+
Please check unit/integration tests for more examples.
112+
113+
Prerequisites
114+
-------------
115+
116+
* Java 7
117+
* To compile, one should use [Maven](http://maven.apache.org/) 2.1.0 or above
118+
8119
Dependencies
9120
------------
10121

src/test/java/de/zalando/sprocwrapper/DateConversionIT.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.util.TimeZone;
66

77
import org.junit.Assert;
8-
import org.junit.Ignore;
98
import org.junit.Test;
109

1110
import org.junit.runner.RunWith;
@@ -100,7 +99,6 @@ public void testCheckDateWithoutTimeZoneTransformationOtherPostgresZone() {
10099
}
101100

102101
@Test
103-
@Ignore
104102
public void checkDateComplexDate() {
105103
final ComplexDate complexDate = new ComplexDate();
106104
final Date date = new Date();

0 commit comments

Comments
 (0)