{"id":21280280,"url":"https://github.com/zalando-stups/java-sproc-wrapper","last_synced_at":"2025-07-11T09:31:55.285Z","repository":{"id":543921,"uuid":"6443745","full_name":"zalando-stups/java-sproc-wrapper","owner":"zalando-stups","description":"Java Stored Procedure Wrapper: Calling PostgreSQL stored procedures from Java","archived":false,"fork":false,"pushed_at":"2023-06-14T22:42:06.000Z","size":916,"stargazers_count":64,"open_issues_count":5,"forks_count":30,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-04-06T02:33:33.123Z","etag":null,"topics":["hacktoberfest","java","postgresql","proxy","rpc","stored-procedures"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zalando-stups.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.MD","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2012-10-29T16:32:36.000Z","updated_at":"2024-11-15T23:00:12.000Z","dependencies_parsed_at":"2023-07-05T15:01:32.855Z","dependency_job_id":null,"html_url":"https://github.com/zalando-stups/java-sproc-wrapper","commit_stats":null,"previous_names":["zalando-incubator/java-sproc-wrapper"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/zalando-stups/java-sproc-wrapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalando-stups%2Fjava-sproc-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalando-stups%2Fjava-sproc-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalando-stups%2Fjava-sproc-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalando-stups%2Fjava-sproc-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zalando-stups","download_url":"https://codeload.github.com/zalando-stups/java-sproc-wrapper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalando-stups%2Fjava-sproc-wrapper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264777752,"owners_count":23662552,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","java","postgresql","proxy","rpc","stored-procedures"],"created_at":"2024-11-21T10:29:06.930Z","updated_at":"2025-07-11T09:31:54.703Z","avatar_url":"https://github.com/zalando-stups.png","language":"Java","readme":"SProcWrapper\n============\n\n[![Build Status](https://travis-ci.org/zalando-stups/java-sproc-wrapper.svg)](https://travis-ci.org/zalando-stups/java-sproc-wrapper) [![Coverage Status](https://coveralls.io/repos/zalando-stups/java-sproc-wrapper/badge.svg)](https://coveralls.io/r/zalando-stups/java-sproc-wrapper)\n[![Javadoc](https://javadoc-emblem.rhcloud.com/doc/org.zalando/zalando-sprocwrapper/badge.svg)](http://www.javadoc.io/doc/org.zalando/zalando-sprocwrapper)\n[![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)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/zalando/problem-spring-web/master/LICENSE)\n\nLibrary to make PostgreSQL stored procedures(SProcs) available through simple Java \"SProcService\" interfaces including\nautomatic object serialization and deserialization (using typemapper and convention-over-configuration).\n\nSupports horizontal database sharding (partition/access logic lies within application), easy use of `pg_advisory_lock`\nthrough annotations to ensure single Java node execution, configurable statement timeouts per stored procedure, and\nPostgreSQL types including enums and hstore.\n\nUsage\n------------\nTo use SProcWrapper, add the following lines to your pom.xml:\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.zalando\u003c/groupId\u003e\n    \u003cartifactId\u003ezalando-sprocwrapper\u003c/artifactId\u003e\n    \u003cversion\u003e${zalando-sprocwrapper.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nType Mapping\n------------\n\nSProcWrapper provides an efficient and easy-to-use mechanism for translating values from database to Java objects and\nvice-versa. It allows us to map not only primitive types, but also complex types (Java domain objects).\n\nHere are some examples!\n\nUsing basic types:\n\n```java\n\n@SProcService\npublic interface CustomerSProcService {\n    @SProcCall\n    int registerCustomer(@SProcParam String name, @SProcParam String email);\n}\n```\n\n```sql\nCREATE FUNCTION register_customer(p_name TEXT, p_email TEXT)\n    RETURNS INT AS\n$$\nINSERT INTO z_data.customer(c_name, c_email)\nVALUES (p_name, p_email)\nRETURNING c_id\n$$\n    LANGUAGE 'sql'\n    SECURITY DEFINER;\n```\n\nAnd a complex type:\n\n```java\n\n@SProcService\npublic interface OrderSProcService {\n    @SProcCall\n    List\u003cOrder\u003e findOrders(@SProcParam String email);\n}\n```\n\n```sql\nCREATE FUNCTION find_orders(p_email TEXT,\n                            OUT order_id INT,\n                            OUT order_date TIMESTAMP,\n                            OUT shipping_address ORDER_ADDRESS)\n    RETURNS SETOF RECORD AS\n$$\nSELECT o_id,\n       o_date,\n       ROW (oa_street, oa_city, oa_country)::ORDER_ADDRESS\nFROM z_data.order\n         JOIN z_data.order_address\n              ON oa_order_id = o_id\n         JOIN z_data.customer\n              ON c_id = o_customer_id\nWHERE c_email = p_email\n$$\n    LANGUAGE 'sql'\n    SECURITY DEFINER;\n```\n\nPlease check [unit/integration tests](src/test/java/de/zalando/sprocwrapper) for more examples.\n\nThe following table shows the mapping between a database type and a Java type:\n\n| Database         | Java Type                                         |\n| ---------------- | ------------------------------------------------- |\n| smallint         | int                                               |\n| integer          | int                                               |\n| bigint           | long                                              |\n| decimal          | java.math.BigDecimal                              |\n| numeric          | java.math.BigDecimal                              |\n| real             | float                                             |\n| double precision | double                                            |\n| serial           | int                                               |\n| bigserial        | long                                              |\n| varchar          | java.lang.String                                  |\n| char             | char                                              |\n| text             | java.lang.String                                  |\n| timestamp        | java.sql.Timestamp                                |\n| timestamptz      | java.sql.Timestamp                                |\n| date             | java.sql.Timestamp                                |\n| time             | java.sql.Timestamp                                |\n| timetz           | java.sql.Timestamp                                |\n| boolean          | boolean                                           |\n| enum             | java.lang.Enum                                    |\n| array            | java.util.List / java.util.Set                    |\n| hstore           | java.util.Map\u003cjava.lang.String, java.lang.String\u003e |\n\nNote: SProcwrapper doesn't support functions returning arrays as a single output. If one wants to return a collection,\nplease return a SETOF instead.\n\n### Configure global value transformer loader\n\nGlobal value transformer loader loads global value transformers from the classpath. By default, it searches value\ntransformers in `org.zalando` package. You can change this behaviour using\nthe `global.value.transformer.search.namespace` environment variable:\n\n```shell\nEXPORT global.value.transformer.search.namespace=\"my.package\"\n```\n\nor by calling a method:\n\n```java\nGlobalValueTransformerLoader.changeNamespaceToScan(\"my.package\");\n```\n\nIt is also possible to provide multiple scan packages using `;` separator:\n\n```shell\nEXPORT global.value.transformer.search.namespace=\"my.package;another.package;third.package\"\n```\n\nPrerequisites\n-------------\n\n* Java 11\n* To compile, one should use [Maven](http://maven.apache.org/) 3.0.0 or above\n\nDependencies\n------------\n\n* Spring Framework 5.x\n* PostgreSQL JDBC driver ;)\n* Google Guava\n\nSee [pom.xml](pom.xml) for the full list of dependencies.\n\nHow to run integration tests\n----------------------------\n\nThe provided helper script will start a PostgreSQL instance with Docker on port 5432 and run integration tests:\n```shell\n./test.sh\n```\n\nKnown issues\n------------\n\n* PostgreSQL JDBC driver does not honor identical type names in different schemas, this may lead to issues if typemapper\n  is used where types are present with equal name in more than one schema (this problem is solved now with the\n  commit [3ca94e64d6322fa91c477200bfb3719deaeac153](https://github.com/pgjdbc/pgjdbc/commit/3ca94e64d6322fa91c477200bfb3719deaeac153)\n  to [pgjdbc](https://github.com/pgjdbc/pgjdbc/) driver);\n* PostgreSQL domains are not supported as for now;\n* PostgreSQL `hstore` type is mapped from and to `Map\u003cString,String\u003e`, there is no way to use `Map` of different types\n  for now;\n* Two different datasources with the same JDBC URL and different search paths might not work properly when we have types\n  with the identical name;\n* SProcWrapper relies on the search path to resolve conflicting types with the same name (right now, we are not checking\n  the schema). If one specifies the schema of the stored procedure's return type, SProcWrapper might end up using the\n  wrong one, because it will use the `search_path` to resolve the conflict. For more info check\n  test: `SimpleIT.testTypeLookupBugWithSchema`;\n* For integration with Spring's transaction management use the `TransactionAwareDataSourceProxy` as the data source\n  injected into the data source provider.\n\nDocumentation\n-------------\n\nYou can find some more information about the SProcWrapper in our various Zalando Technology blog posts:\n\n* http://tech.zalando.com/blog/goto-2013-why-zalando-trusts-in-postgresql/\n* http://tech.zalando.com/blog/zalando-stored-procedure-wrapper-part-i/\n* http://tech.zalando.com/blog/files/2013/04/jug_dortmund_april_2013.pdf\n\n🚨 Upgrading from 2.x to 3.x? Please be aware that default scanning package for custom objectTransformer has changed from `de.zalando` to `org.zalando`.\n\n## Contributing\n\nSee [contributing guideline](CONTRIBUTING.md).\n\n\nLicense\n-------\n\nMIT license. See [license file](LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzalando-stups%2Fjava-sproc-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzalando-stups%2Fjava-sproc-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzalando-stups%2Fjava-sproc-wrapper/lists"}