Created
October 12, 2018 19:27
-
-
Save petarov/65924012f4eceb4258f58cf2b2e8b961 to your computer and use it in GitHub Desktop.
MyBatis Microsoft OffsetDateTimeTypeHandlerJDBC42
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OffsetDateTimeTypeHandlerJDBC42 extends BaseTypeHandler<OffsetDateTime> { | |
@Override | |
public void setNonNullParameter(PreparedStatement ps, int i, OffsetDateTime parameter, JdbcType jdbcType) | |
throws SQLException { | |
ps.setObject(i, parameter); | |
} | |
@Override | |
public OffsetDateTime getNullableResult(ResultSet rs, String columnName) throws SQLException { | |
return toOffsetDateTime(rs.getObject(columnName, DateTimeOffset.class)); | |
} | |
@Override | |
public OffsetDateTime getNullableResult(ResultSet rs, int columnIndex) throws SQLException { | |
return toOffsetDateTime(rs.getObject(columnIndex, DateTimeOffset.class)); | |
} | |
@Override | |
public OffsetDateTime getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { | |
return toOffsetDateTime(cs.getObject(columnIndex, DateTimeOffset.class)); | |
} | |
private OffsetDateTime toOffsetDateTime(DateTimeOffset dto) { | |
if (dto != null) { | |
return OffsetDateTime.ofInstant(dto.getTimestamp().toInstant(), | |
ZoneOffset.ofHours(dto.getMinutesOffset() / 60)); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment