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
Add JSR-310 Support #386
Add JSR-310 Support #386
Conversation
I see lots of code duplications. Can you please move all the code you've added to a separate class |
I can do this.
|
182877d
to
81bbe9d
Compare
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.
Looks very good now! Need few minor fixes.
@@ -0,0 +1,481 @@ | |||
package org.h2.util; |
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.
Please add file header.
try { | ||
return Class.forName(className); | ||
} catch (ClassNotFoundException e) { | ||
throw new IllegalStateException("Java 8 or later but class " + className + " is missing"); |
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.
Add the original ClassNotFoundException
as cause.
return clazz.getMethod(methodName, parameterTypes); | ||
} catch (NoSuchMethodException e) { | ||
throw new IllegalStateException("Java 8 or later but method " | ||
+ clazz.getName() + "#" + methodName + "(" + Arrays.toString(parameterTypes) + ") is missing"); |
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.
Add the original exception as cause.
try { | ||
return clazz.getField(fieldName).get(null); | ||
} catch (NoSuchFieldException | IllegalAccessException e) { | ||
throw new IllegalStateException("Java 8 or later but field " + clazz.getName() |
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.
Add the original exception as cause.
} catch (IllegalAccessException e) { | ||
throw DbException.convert(e); | ||
} catch (InvocationTargetException e) { | ||
throw DbException.convertInvocation(e, "timestampe conversion failed"); |
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.
timestamp
Looks very good now!
|
Add support for Java 8 Date and Time API AKA JSR-310. On the face of it the existing JDBC types java.sql.Date, java.sql.Time and java.sql.Timestamp offer conversion methods to and from JSR-310 data types. Unfortunately java.sql.Timestamp does silent data truncation when the timestamp falls into a DST transition on the JVM time zone. Worse still for java.time.OffsetDateTime there is no corresponding JDBC type. Therefore these conversions have to be implemented. All of this has to be programmed using reflection so the code compiles and can be executed on Java 7.
Thanks a lot for your contribution! |
Add support for Java 8 Date and Time API AKA JSR-310. On the face of it
the existing JDBC types java.sql.Date, java.sql.Time and
java.sql.Timestamp offer conversion methods to and from JSR-310 data
types. Unfortunately java.sql.Timestamp does silent data truncation
when the timestamp falls into a DST transition on the JVM time zone.
Worse still for java.time.OffsetDateTime there is no corresponding JDBC
type. Therefore these conversions have to be implemented. All of this
has to be programmed using reflection so the code compiles and can be
executed on Java 7.