@@ -8,102 +8,84 @@ Supports horizontal database sharding (partition/access logic lies within applic
8
8
Type Mapping
9
9
------------
10
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).
11
+ The SprocWrapper provides and efficient and easy-to-use mechanimism 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).
12
12
13
- Here are some examples.
13
+ Here are some examples!
14
14
15
- Basic type :
15
+ Using a basic types :
16
16
17
17
``` java
18
- @SProcCall
19
- String getNameForId(@SProcParam int id);
18
+ @SProcService
19
+ public interface CustomerSProcService {
20
+ @SProcCall
21
+ int registerCustomer (@SProcParam String name , @SProcParam String email );
22
+ }
20
23
```
21
24
22
25
``` sql
23
- CREATE FUNCTION get_name_for_id (p_id int ) RETURNS text AS
26
+ CREATE FUNCTION register_customer (p_name text , p_email text )
27
+ RETURNS int AS
24
28
$$
25
- SELECT name
26
- FROM customer
27
- WHERE id = p_id
28
- $$ LANGUAGE ‘sql’;
29
+ INSERT INTO z_data .customer (c_email, c_gender)
30
+ VALUES (p_email, p_gender)
31
+ RETURNING c_id
32
+ $$
33
+ LANGUAGE ' sql' SECURITY DEFINER;
29
34
```
30
35
31
- Complex type:
36
+ And a complex type:
32
37
33
38
``` java
34
- @SProcCall
35
- List<Order > findOrders(@SProcParam String email);
39
+ @SProcService
40
+ public interface OrderSProcService {
41
+ @SProcCall
42
+ List<Order > findOrders (@SProcParam String email );
43
+ }
36
44
```
37
45
38
46
``` sql
39
47
CREATE FUNCTION find_orders (p_email text ,
40
48
OUT order_id int ,
41
49
OUT order_date timestamp ,
42
- OUT shipping_address order_address) RETURNS SETOF RECORD AS
50
+ OUT shipping_address order_address)
51
+ RETURNS SETOF RECORD AS
43
52
$$
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
+ SELECT o_id,
54
+ o_date,
55
+ ROW(oa_street, oa_city, oa_country)::order_address
56
+ FROM z_data .order
57
+ JOIN z_data .order_address
58
+ ON oa_order_id = o_id
59
+ JOIN z_data .customer
60
+ ON c_id = o_customer_id
61
+ WHERE c_email = p_email
53
62
$$
54
63
LANGUAGE ' sql' SECURITY DEFINER;
55
64
```
56
65
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> |
66
+ SprocWrapper supports the following data types:
67
+
68
+ | Database | Java |
69
+ | ---------------- | ------------------------------------------------- |
70
+ | smallint | int |
71
+ | integer | int |
72
+ | bigint | long |
73
+ | decimal | java.math.BigDecimal |
74
+ | numeric | java.math.BigDecimal |
75
+ | real | float |
76
+ | double precision | double |
77
+ | serial | int |
78
+ | bigserial | long |
79
+ | varchar | java.lang.String |
80
+ | char | char |
81
+ | text | java.lang.String |
82
+ | timestamp | java.sql.Timestamp |
83
+ | date | java.sql.Timestamp |
84
+ | time | java.sql.Timestamp |
85
+ | boolean | boolean |
86
+ | enum | java.lang.Enum |
87
+ | array | java.util.List/java.util.Set |
88
+ | hstore | java.util.Map<java.lang.String, java.lang.String> |
107
89
108
90
109
91
Note: Sprocwrapper doesn't support functions returning arrays as a single output. If one wants to return a collection, please return a SETOF instead.
0 commit comments