1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.type;
17
18 import java.sql.CallableStatement;
19 import java.sql.PreparedStatement;
20 import java.sql.ResultSet;
21 import java.sql.SQLException;
22 import java.time.YearMonth;
23
24
25
26
27
28
29
30
31
32
33
34 public class YearMonthTypeHandler extends BaseTypeHandler<YearMonth> {
35
36 @Override
37 public void setNonNullParameter(PreparedStatement ps, int i, YearMonth yearMonth, JdbcType jt) throws SQLException {
38 ps.setString(i, yearMonth.toString());
39 }
40
41 @Override
42 public YearMonth getNullableResult(ResultSet rs, String columnName) throws SQLException {
43 return toYearMonth(rs.getString(columnName));
44 }
45
46 @Override
47 public YearMonth getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
48 return toYearMonth(rs.getString(columnIndex));
49 }
50
51 @Override
52 public YearMonth getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
53 return toYearMonth(cs.getString(columnIndex));
54 }
55
56 private YearMonth toYearMonth(String value) {
57 return value == null ? null : YearMonth.parse(value);
58 }
59
60 }