Skip to content
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

Make JSON type loading conditional upon server support #1111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

coladict
Copy link

@coladict coladict commented Feb 13, 2018

It's partly feature, partly fix. Not sure how to tag it.

And adding the JAVA_OBJECT to the acceptable null types fixes a small issue in an experiment of mine. The rest of the time it works fine, when the values are not nulls.

Changing the SQL type integer constant from OTHER to JAVA_OBJECT (while having no positive or negative effect) makes it consistent with the Hibernate JPA provider's choice for type association. Even though they don't fully support it out-of-the-box. I've checked with EclipseLink and OpenJPA and they're even further behind on this, with no

Reference 1

Copy link
Member

@vlsi vlsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please add test cases to cover the change?

@@ -311,6 +311,14 @@ public TimeZone get() {
types.addCoreType("xml", Oid.XML, Types.SQLXML, "java.sql.SQLXML", Oid.XML_ARRAY);
}

if (haveMinimumServerVersion(ServerVersion.v9_2)) {
types.addCoreType("json", Oid.JSON, Types.JAVA_OBJECT, "org.postgresql.util.PGobject", Oid.JSON_ARRAY);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use Types.JAVA_OBJECT here?
It looks like it was declared as Types.OTHER.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAVA_OBJECT, while not entirely correct is more meaningful than OTHER, and it makes no difference either way. But I don't have old server instances running to be able to test the conditional adding. I simply repeated the pattern of the other checks with the appropriate version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is tested via Travis, and it does use multiple PostgreSQL versions (see https://travis-ci.org/pgjdbc/pgjdbc/builds/340856695?utm_source=github_status&utm_medium=notification )

JAVA_OBJECT, while not entirely correct is more meaningful than OTHER

This change breaks backward compatibility. Is there a reason to do that?

I simply repeated the pattern of the other checks with the appropriate version.

The changes should be tested otherwise they can be silently reverted.
The tests are useful as code samples for those who want to use json/jsonb

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks backward compatibility. Is there a reason to do that?

I believe this change is justified, because OTHER can literally mean anything, and there is no standardized usage in higher-level APIs that would be broken from it. They're all still "cooking".

If I am to add tests for the presence of the two types, should I change the SQL type back to OTHER?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants