-
Notifications
You must be signed in to change notification settings - Fork 828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Define binary transfer for custom types dynamically (#2554) #2556
feat: Define binary transfer for custom types dynamically (#2554) #2556
Conversation
This sounds like a wrong level of abstraction to me. I do not understand what do you want to achieve |
This pull request only complements the already existing API. Currently it is possible to add custom types for binary transfer to a connection by using the connection properties while creating the connection. This works for some cases, but unfortunately not for all. Actually to do this you need to know the oid of the type before setting the connection properties. The second issue is more severe: If you use an enterprise application server like WildFly, you do not open new connections in your application. The application server maintains a connection pool and injects connections into the different applications. So you are not able to set these properties for your application only, but the administrator needs to do that and he needs to look up the oids per database, which would be a big hassle. In the existing API there are already functions for setting the oids to be sent or received binary on the Additionally I also added functions for getting the currently set oids: |
QueryExecutor is driver-private class, and I do not understand what are you going to achieve |
Just to clarify my intentions: If I know it is a PostgreSQL connection, I am able to use these classes and can add the oids for custom types. So can you please explain to me, what exactly is the issue with complementing the existing function for setting the oids with two functions for adding a single oid and getting the already set oids? These are all internals, but that is exactly were I come from here - the whole postgis-java-ng implementation is providing types based on |
The problem is that you are elevating QueryExecutor to being a supported API. The fact that it is currently public does not mean we support it to be used in Applications or 3rd party libraries. |
So what could be a solution for that? Push it up to To me it seemed a less intrusive change to just enhance I am aware that the core API might change and I will need to adjust my library accordingly. But I also see that it might benefit the user, if geometries are parsed from the byte data and not converted to a string and parsed back as byte data. And this data can be quite large if a lot of vertexes are used in lines. |
Would you please suggest an end-to-end test case? I agree binary support is worth improving, however, exposing "enable/disable" on a connection level looks like exposing an error-prone API. I would rather activate binary transfer whenever a relevant codec is registered. |
In general we support the official java.sql.* API The reason for this is that if we rewrite the underlying implementation we really don't want to be committed to supporting anything other than the official java.sql API Every extension adds a support burden to the project. |
@vlsi and @davecramer I see both your points, thank you for clarifying this. At first I just wanted to go for implementing From a design point of view I totally support your idea of only supporting the plain So ideally I would go for adding the custom type to the connection and in the background automatically enabling binary transfer for it if it implements I would basically register binary types when |
This seems more rational to me |
So we should definitely go for that. I will try to setup an end-to-end test case, I just need some help with that: Instead for testing I would like to have a simple custom datatype in PostgreSQL, which I can write binary data to and read it back. |
Well I think you can create a single type that has binary transfer for the test. That said yes we would have to figure out how to get that installed on the server |
I created a separate commit in the pull requests for these changes: Now I need to create an according unit test and this seems to be difficult: Maybe for a test I could also just use a built-in type like |
4ad5a8c
to
b2541f3
Compare
I just squashed the existing commits and rebased them on the current master to be more in line with the current development. One of of the unrelated tests as an example:
This is the exact AppVeyor build: |
b2541f3
to
1339516
Compare
Okay that's it... 😄 Furthermore I have added a new unit tests to not only verify the OIDs set to be transferred binary, but to also test the actual transfer from/to the database. |
1339516
to
27cb2ef
Compare
@davecramer @vlsi Do you have any comments on this? Is there something I can do to progress forward/get this merged? |
LGTM, @vlsi ? |
if (oids != null) { | ||
binaryOids.removeAll(getOidSet(oids)); | ||
return new HashSet<Integer>(getOidSet(oids)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be something like Collections.unmodifiableSet(...)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it consistent with getBinaryEnabledOids
, which also returns a modifiable set of values.
Actually this prevents the need to copy the set before modifying it (in the constructor of PgConnection
the disabled OIDs are removed from the enabled OIDs to get the binary OIDs as a result).
@Test | ||
public void testBinaryTransferOids() throws SQLException { | ||
con = TestUtil.openDB(); | ||
QueryExecutor queryExecutor = ((PgConnection) con).getQueryExecutor(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PgConnection
is driver-internal API. Client-facing APIs are java.sql.Connection
and org.postgresql.PGConnection
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also a driver-internal test. The APIs for checking if a type is sent or received as binary are only available on QueryExecutor
. So they can only be tested by either really sending and receiving them (what testCustomBinaryTypes
) does or using the QueryExecutor
API.
I added testBinaryTransferOids
by intention to make sure the internal API works before a database is used in the other test. So it is possible to first test the API works and then to test if the database access works.
con = TestUtil.openDB(); | ||
|
||
PgConnection pgconn = (PgConnection) con; | ||
QueryExecutor queryExecutor = pgconn.getQueryExecutor(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think you could "disable default binary transfer for POINT" via existing connection properties rather than using a private PgConnection + QueryExecutor
APIs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be possible, but as stated above I need to use the internal API anyway.
So it is more flat/simple to just remove this single type without introducing possible side effects by setting additional connection properties.
Sorry it takes so long to review. @sebasbaumh , would you please check if |
No problem and thank you for reviewing this pull request.
After all the changes are mostly to internal APIs and do not need to be accessible by the user - but we need to test the internal APIs. So the tests need to be able to access them. |
27cb2ef
to
5d6ba47
Compare
5d6ba47
to
9121202
Compare
I just rebased this pull request on the current master as there were merge conflicts after the latest commits to master. @davecramer & @vlsi I incorporated most of your proposed changes and commented on the others. |
@sebasbaumh , did you select See what I have in https://github.com/vlsi/pgjdbc/tree/pr2556 (e.g. vlsi@8a41067 ) |
9121202
to
a9e501f
Compare
Probably the last time I spelled the command wrong, it yielded "no permissions", so I assumed edits from maintainers was not enabled. |
@vlsi thank you very much for reviewing/adapting the pull request. |
There's a failure caused by the new code:
There's a chicken-and-egg issue:
A quick workaround is to skip registering binary types when the connection is in "simple queries only", however, we probably should add extra checks to methods like |
5407fd2
to
dd8b2f6
Compare
Good catch. I was wondering why it failed that test. |
dd8b2f6
to
cf99dbb
Compare
|
…ly (pgjdbc#2554) The driver would automatically register types for binary transfer when calling con.unwrap(PGConnection.class).addDataType(String, Class) Fixes pgjdbc#2554
I just realized we should better implement the standard API |
cf99dbb
to
9d2fb14
Compare
Yes, maybe we could deprecate the vendor-specific function later when the standard API gets implemented. |
I think this is mergeable. Of course, we might adjust oids used for testing, on the other hand, I doubt they will induce issues in the future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
editorconfig is a gratuitous change but that's fine
Thanks for merging! 👍 I will try to follow up @vlsi recommendation to implement this also in the standard API |
This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [flow-bin](https://github.com/flowtype/flow-bin) ([changelog](https://github.com/facebook/flow/blob/master/Changelog.md)) | devDependencies | minor | [`^0.198.0` -> `^0.199.0`](https://renovatebot.com/diffs/npm/flow-bin/0.198.0/0.199.0) | | [org.postgresql:postgresql](https://jdbc.postgresql.org) ([source](https://github.com/pgjdbc/pgjdbc)) | build | patch | `42.5.1` -> `42.5.2` | | [io.quarkus:quarkus-maven-plugin](https://github.com/quarkusio/quarkus) | build | patch | `2.16.0.Final` -> `2.16.1.Final` | | [io.quarkus:quarkus-universe-bom](https://github.com/quarkusio/quarkus-platform) | import | patch | `2.16.0.Final` -> `2.16.1.Final` | | [org.apache.maven.plugins:maven-enforcer-plugin](https://maven.apache.org/enforcer/) | build | minor | `3.1.0` -> `3.2.1` | --- ### Release Notes <details> <summary>flowtype/flow-bin</summary> ### [`v0.199.0`](flow/flow-bin@0568b6e...05bb4e3) [Compare Source](flow/flow-bin@0568b6e...05bb4e3) ### [`v0.198.2`](flow/flow-bin@0d01841...0568b6e) [Compare Source](flow/flow-bin@0d01841...0568b6e) ### [`v0.198.1`](flow/flow-bin@2b180bb...0d01841) [Compare Source](flow/flow-bin@2b180bb...0d01841) </details> <details> <summary>pgjdbc/pgjdbc</summary> ### [`v42.5.2`](https://github.com/pgjdbc/pgjdbc/blob/HEAD/CHANGELOG.md#​4252-2023-01-31-143046--0500) ##### Changed docs: specify that timeouts are in seconds and there is a maximum. Housekeeping on some tests fixes [#Issue 2671](pgjdbc/pgjdbc#2671) [MR #​2686](pgjdbc/pgjdbc#2686) docs: clarify binaryTransfer and add it to README [MR# 2698](pgjdbc/pgjdbc#2698) docs: Document the need to encode reserved characters in the connection URL [MR #​2700](pgjdbc/pgjdbc#2700) feat: Define binary transfer for custom types dynamically/automatically fixes [Issue #​2554](pgjdbc/pgjdbc#2554) [MR #​2556](pgjdbc/pgjdbc#2556) ##### Added fix: added gssResponseTimeout as part of [MR #​2687](pgjdbc/pgjdbc#2687) to make sure we don't wait forever on a GSS RESPONSE ##### Fixed fix: Ensure case of XML tags in Maven snippet is correct [MR #​2682](pgjdbc/pgjdbc#2682) fix: Make sure socket is closed if an exception is thrown in createSocket fixes [Issue #​2684](pgjdbc/pgjdbc#2684) [MR #​2685](pgjdbc/pgjdbc#2685) fix: Apply patch from [Issue #​2683](pgjdbc/pgjdbc#2683) to fix hanging ssl connections [MR #​2687](pgjdbc/pgjdbc#2687) fix - binary conversion of (very) long numeric values (longer than 4 \* 2^15 digits) [MR #​2697](pgjdbc/pgjdbc#2697) fixes [Issue #​2695](pgjdbc/pgjdbc#2695) minor: enhance readability connection of startup params [MR #​2705](pgjdbc/pgjdbc#2785) </details> <details> <summary>quarkusio/quarkus</summary> ### [`v2.16.1.Final`](https://github.com/quarkusio/quarkus/releases/tag/2.16.1.Final) [Compare Source](quarkusio/quarkus@2.16.0.Final...2.16.1.Final) ##### Complete changelog - [#​30729](quarkusio/quarkus#30729) - Bump mariadb-java-client from 3.1.1 to 3.1.2 - [#​30724](quarkusio/quarkus#30724) - Upgrade to Mutiny 1.9.0 - [#​30722](quarkusio/quarkus#30722) - Set SameSite Strict only on OIDC session cookie - [#​30720](quarkusio/quarkus#30720) - Bump picocli.version from 4.7.0 to 4.7.1 - [#​30719](quarkusio/quarkus#30719) - Bump jackson-bom from 2.14.1 to 2.14.2 - [#​30715](quarkusio/quarkus#30715) - PanacheRepositoryResource should implement ReactiveRestDataResource - [#​30713](quarkusio/quarkus#30713) - Use MapProperty instead of Map - [#​30694](quarkusio/quarkus#30694) - Use newer API for creating tmp files in RESTEasy Reactive - [#​30692](quarkusio/quarkus#30692) - Bump htmlunit version to 2.70.0 - [#​30686](quarkusio/quarkus#30686) - Don't fail send when a sse sink has been closed - [#​30681](quarkusio/quarkus#30681) - RESTEasy Reactive: SSE broadcaster fails if a sink has been closed - [#​30680](quarkusio/quarkus#30680) - Mark methods generatred by ASM transformations as synthetic - [#​30659](quarkusio/quarkus#30659) - Drop unused class GradleLogger - [#​30653](quarkusio/quarkus#30653) - Fix opening in IDE when more than IDE is running - [#​30652](quarkusio/quarkus#30652) - Match prometheus export metrics format - [#​30651](quarkusio/quarkus#30651) - ArC - use reflection fallback for PreDestroy callbacks if needed - [#​30649](quarkusio/quarkus#30649) - Document redirect options in RESTEasy Reactive - [#​30644](quarkusio/quarkus#30644) - Adjust source language absent in documentation code blocks - [#​30636](quarkusio/quarkus#30636) - PreDestroy hooks fail depending on method modifiers - [#​30635](quarkusio/quarkus#30635) - Introduce a `minimum-java-version` in the extension descriptor metadata - [#​30625](quarkusio/quarkus#30625) - OIDC authentication loop if Cookie Policy sameSite=strict - [#​30624](quarkusio/quarkus#30624) - Fix NPE obtaining a project map from Maven session - [#​30622](quarkusio/quarkus#30622) - Update invalid package in guide - [#​30612](quarkusio/quarkus#30612) - Fix import file name in redis-reference.adoc - [#​30609](quarkusio/quarkus#30609) - Qute generated resolvers - getters should take precedence over fields - [#​30593](quarkusio/quarkus#30593) - Qute validation - improve hierarchy indexing to fix assignability issues - [#​30591](quarkusio/quarkus#30591) - Resolve correct version when application version is unset - [#​30589](quarkusio/quarkus#30589) - Bump junit-bom from 5.9.1 to 5.9.2 - [#​30585](quarkusio/quarkus#30585) - Bump Microsoft SQL Server JDBC driver to 11.2.3 - [#​30584](quarkusio/quarkus#30584) - Update MS SQL JDBC driver to version 11.2.3 - [#​30576](quarkusio/quarkus#30576) - Use accept header to choose metrics export format - [#​30574](quarkusio/quarkus#30574) - Handle empty source directory for included builds - [#​30569](quarkusio/quarkus#30569) - Add default implementation for REST Data interfaces - [#​30564](quarkusio/quarkus#30564) - Update security-openid-connect-client.adoc - [#​30559](quarkusio/quarkus#30559) - container-image extension running with kubernetes extension - [#​30557](quarkusio/quarkus#30557) - AWT: JniRuntimeAccess: freetypeScaler.c calls sun.font.FontUtilities - [#​30548](quarkusio/quarkus#30548) - Add a blurb about not supporting validation.xml in Quarkus - [#​30526](quarkusio/quarkus#30526) - RESTEasy classic servlets - add RoutingContext to active request context - [#​30515](quarkusio/quarkus#30515) - Native build fails with hibernate-orm-rest-data-panache + elytron-security-properties-file - [#​30513](quarkusio/quarkus#30513) - Limit application.properties lookup to main source set - [#​30510](quarkusio/quarkus#30510) - Simplify logic in create-app.adoc and allow to define stream - [#​30501](quarkusio/quarkus#30501) - Fix HibernateOrmCodestart - [#​30500](quarkusio/quarkus#30500) - Place extension with an unknown category in the uncategorized category - [#​30496](quarkusio/quarkus#30496) - Update documentation - [#​30490](quarkusio/quarkus#30490) - Avoid adding the exception itself as a suppressed exception - [#​30488](quarkusio/quarkus#30488) - Updates to Infinispan 14.0.6.Final - [#​30485](quarkusio/quarkus#30485) - Verify code flow access token first if no UserInfo precondition exists - [#​30479](quarkusio/quarkus#30479) - Define defaultValueDocumentation for builderImage - [#​30474](quarkusio/quarkus#30474) - Docs - default value of `quarkus.native.builder-image` is not shown - [#​30470](quarkusio/quarkus#30470) - Revert --enable-monitoring with no arguments support - [#​30460](quarkusio/quarkus#30460) - Bump kafka3.version from 3.3.1 to 3.3.2 - [#​30453](quarkusio/quarkus#30453) - Gradle build failing w/ Quarkus 2.16.0 - [#​30430](quarkusio/quarkus#30430) - Bump gizmo from 1.5.0.Final to 1.6.0.Final - [#​30429](quarkusio/quarkus#30429) - Bump Keycloak version to 20.0.3 - [#​30426](quarkusio/quarkus#30426) - Fix redundant push when using buildx - [#​30424](quarkusio/quarkus#30424) - Building of container images with buildx causes build failures - [#​30423](quarkusio/quarkus#30423) - 2.15+ - Services dependent on libraries without classes no longer build - [#​30418](quarkusio/quarkus#30418) - Disable -D argument propagation in DevMojo - [#​30415](quarkusio/quarkus#30415) - Arc - Change Types#getTypeClosure so that superclasses and interfaces of producer types no longer throw on finding wildcards - [#​30412](quarkusio/quarkus#30412) - Arc - wildcard detection for producer methods/fields is too aggressive - [#​30410](quarkusio/quarkus#30410) - Introduce support for GraalVM `--enable-monitoring` - [#​30408](quarkusio/quarkus#30408) - Warning: Option 'AllowVMInspection' is deprecated and might be removed from future versions: Please use --enable-monitoring - [#​30405](quarkusio/quarkus#30405) - Quarkus Undertow doesn't work with blocking SecurityIdentityAugmentor - [#​30399](quarkusio/quarkus#30399) - Fix ElasticSearch Dev Services container restart - [#​30384](quarkusio/quarkus#30384) - Elasticsearch Dev Services restarts container on every auto-compile - [#​30368](quarkusio/quarkus#30368) - Allow Environment variables to populate property Maps in build time Config - [#​30354](quarkusio/quarkus#30354) - AWT `io.quarkus.awt.it.ImageGeometryFontsIT` native integration test failing with "GraalVM for Java 20" dev builds - [#​30347](quarkusio/quarkus#30347) - Bump junit-jupiter from 5.9.1 to 5.9.2 - [#​30343](quarkusio/quarkus#30343) - Trailing comma is lost from prometheus metrics - [#​30335](quarkusio/quarkus#30335) - Add native compilation section to Hibernate Validator guide - [#​30332](quarkusio/quarkus#30332) - NPE in toString method for Processor Parameters in kafka-streams 3.3.1 version - [#​30275](quarkusio/quarkus#30275) - Inline Log category property doesn't work - [#​30208](quarkusio/quarkus#30208) - OIDC: 401 when access-token needs to be refreshed and user-info-required=true - [#​30179](quarkusio/quarkus#30179) - Add an owasp-check profile - [#​28781](quarkusio/quarkus#28781) - RESTEasy Reactive: document redirects - [#​24027](quarkusio/quarkus#24027) - Hibernate Validator does not use META-INF/validation.xml, it should work or be stated in the documentation. - [#​23002](quarkusio/quarkus#23002) - if more than two running IDE while launching 'x' gives error </details> <details> <summary>quarkusio/quarkus-platform</summary> ### [`v2.16.1.Final`](quarkusio/quarkus-platform@2.16.0.Final...2.16.1.Final) [Compare Source](quarkusio/quarkus-platform@2.16.0.Final...2.16.1.Final) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This MR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNC4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjQuMCJ9-->
#2554
All Submissions:
New Feature Submissions:
./gradlew autostyleCheck checkstyleAll
pass ?