-
Notifications
You must be signed in to change notification settings - Fork 1.1k
spanner-jdbc: Step 13 - Add JDBC types and type mappings for Cloud Spanner #5877
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
spanner-jdbc: Step 13 - Add JDBC types and type mappings for Cloud Spanner #5877
Conversation
| } | ||
|
|
||
| @Override | ||
| public Type getGoogleType() { |
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.
maybe getSpannerType()?
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.
Changed to getSpannerType()
| if (targetType.equals(String.class)) return value.toString(); | ||
|
|
||
| try { | ||
| if (targetType.equals(Boolean.class) && type.getCode() == Code.BOOL) return value; |
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 would simplify this a bit. First check for targetType in one if, then the codes separately.
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.
That is certainly a good idea.
|
|
||
| static List<java.sql.Timestamp> toSqlTimestamps(List<Timestamp> timestamps) { | ||
| List<java.sql.Timestamp> res = new ArrayList<>(timestamps.size()); | ||
| for (Timestamp timestamp : timestamps) res.add(toSqlTimestamp(timestamp)); |
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 will likely break the code formatter
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.
Actually it was the code formatter that put it like that, but this is really not readable. I've added curly braces to all for loops in the class and reformatted.
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.
huh, surprising! That sounds good to me.
Codecov Report
@@ Coverage Diff @@
## spanner-jdbc #5877 +/- ##
===============================================
Coverage 46.12% 46.12%
Complexity 24187 24187
===============================================
Files 2456 2456
Lines 262236 262236
Branches 29602 29602
===============================================
Hits 120944 120944
Misses 132179 132179
Partials 9113 9113Continue to review full report at Codecov.
|
| return Date.fromYearMonthDay(1970, 1, 1); | ||
| } | ||
|
|
||
| @SuppressWarnings("deprecation") |
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.
what's deprecated here?
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.
Specifically in this place: java.sql.Date#getYear(), java.sql.Date#getMonth() and java.sql.Date#getDate().
More in general: Many methods in java.sql.Date and java.sql.Timestamp have been deprecated since JDK version 1.1. They made some very bad choices regarding timezone handling in these classes, but they are still used as both return types and parameter types in the JDBC interfaces.
Cloud Spanner does not support storing timestamps with timezone information in the database, so the mismatch with these classes is a little bit less of a problem for Cloud Spanner than for many other DBMS'es.
73eec3d to
dbcb883
Compare
…anner (googleapis#5877) * add jdbc types and type mappings for Cloud Spanner * update CR year * changed name to getSpannerType * simplified if statements and added curly braces to for loops
Adds JDBC Array, Blob and Clob data types and the default type mapping between Cloud Spanner, JDBC types and Java types.
(This PR will have a build error until step 12 is merged into the Spanner client library)