-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Testing OffsetDateTimeHandler which retains Offset from UTC #1368
Conversation
I wrote a JDBC test that does the following.
In case anyone is interested, the app is on my Gist. |
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.
Thank you for the PR, @raupachz and I'm sorry about the delay!
I now feel confident enough to proceed with merging this PR.
Could you check my reviews?
If you are busy, please just let me know and I may be able to add commits to this PR myself.
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.ibatis.submitted.usesjava8.timestamp_with_timezone; |
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 move the files to org.apache.ibatis.submitted.timestamp_with_timezone
.
We no longer use usesjava8
sub package because Java 8 will be the minimum required version in MyBatis 3.5.0.
import org.apache.ibatis.session.SqlSession; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.apache.ibatis.session.SqlSessionFactoryBuilder; | ||
import org.apache.ibatis.submitted.usesjava8.use_actual_param_name.User; |
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.
Unused import.
import org.apache.ibatis.submitted.usesjava8.use_actual_param_name.User; |
*/ | ||
package org.apache.ibatis.submitted.usesjava8.timestamp_with_timezone; | ||
|
||
import org.apache.ibatis.submitted.usesjava8.use_actual_param_name.*; |
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.
Unused import.
import org.apache.ibatis.submitted.usesjava8.use_actual_param_name.*; |
} | ||
|
||
@Override | ||
public OffsetDateTime getNullableResult(ResultSet rs, String columnName) throws SQLException { | ||
Timestamp timestamp = rs.getTimestamp(columnName); | ||
return getOffsetDateTime(timestamp); | ||
return (OffsetDateTime) rs.getObject(columnName); |
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.
Specify the second argument of getObject()
instead of cast.
return (OffsetDateTime) rs.getObject(columnName); | |
return rs.getObject(columnName, OffsetDateTime.class); |
|
||
<mapper namespace="org.apache.ibatis.submitted.usesjava8.timestamp_with_timezone.Mapper"> | ||
|
||
</mapper> |
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.
Empty file. Please delete it.
@@ -20,6 +20,7 @@ | |||
import java.sql.ResultSet; | |||
import java.sql.SQLException; | |||
import java.sql.Timestamp; | |||
import java.sql.Types; | |||
import java.time.OffsetDateTime; | |||
import java.time.ZoneId; |
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.
Some imports are not used.
} | ||
|
||
@Override | ||
public OffsetDateTime getNullableResult(ResultSet rs, int columnIndex) throws SQLException { | ||
Timestamp timestamp = rs.getTimestamp(columnIndex); | ||
return getOffsetDateTime(timestamp); | ||
return (OffsetDateTime) rs.getObject(columnIndex); |
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.
Specify the second argument of getObject()
instead of cast.
return (OffsetDateTime) rs.getObject(columnIndex); | |
return rs.getObject(columnIndex, OffsetDateTime.class); |
} | ||
|
||
@Override | ||
public OffsetDateTime getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { | ||
Timestamp timestamp = cs.getTimestamp(columnIndex); | ||
return getOffsetDateTime(timestamp); | ||
return (OffsetDateTime) cs.getObject(columnIndex); |
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.
Specify the second argument of getObject()
instead of cast.
return (OffsetDateTime) cs.getObject(columnIndex); | |
return cs.getObject(columnIndex, OffsetDateTime.class); |
} finally { | ||
sqlSession.close(); | ||
} | ||
} |
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.
There should be two tests with assertions at least (SELECT and INSERT).
@raupachz , |
Merged. Thank you, @raupachz ! |
@harawata Could you set labels? |
@kazuki43zoo |
@harawata I think that it is better to decide rules as a team. |
I see. May I ask why you prefer issues over PRs? I myself try to choose the one that is more informative as a milestone entry. |
Testing OffsetDateTimeHandler which retains Offset from UTC
PR for the issue in #1081.
Changes OffsetDateTimeHandler now uses getObject and setObject. This retains the offset. Before that we used setTimestamp which looses the offset.
This branch in my fork is over a year old. Not sure if everything is done well. Looking for feedback.