1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| @MappedJdbcTypes(JdbcType.ARRAY) @MappedTypes(Integer[].class) public class IntArrayTypeHandler extends BaseTypeHandler<Integer[]> {
@Override public void setNonNullParameter(PreparedStatement ps, int i, Integer[] parameter, JdbcType jdbcType) throws SQLException { Connection connection = ps.getConnection(); Array array = connection.createArrayOf("integer", parameter); ps.setArray(i, array); array.free(); }
@Override public Integer[] getNullableResult(ResultSet rs, String columnName) throws SQLException { return getArray(rs.getArray(columnName)); }
@Override public Integer[] getNullableResult(ResultSet rs, int columnIndex) throws SQLException { return getArray(rs.getArray(columnIndex)); }
@Override public Integer[] getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { return getArray(cs.getArray(columnIndex)); }
private Integer[] getArray(Array array) { if (array == null) { return null; } try { return (Integer[]) array.getArray(); } catch (Exception e) { } return null; } }
|