Skip to content

Commit d47a200

Browse files
committed
fix for http://code.google.com/p/mybatis/issues/detail?id=388 : Add generic types to TypeHandler
1 parent 31cc216 commit d47a200

29 files changed

+153
-153
lines changed

src/main/java/org/apache/ibatis/type/ArrayTypeHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.sql.ResultSet;
77
import java.sql.SQLException;
88

9-
public class ArrayTypeHandler extends BaseTypeHandler {
9+
public class ArrayTypeHandler extends BaseTypeHandler<Object> {
1010

1111
public ArrayTypeHandler() {
1212
super();

src/main/java/org/apache/ibatis/type/BaseTypeHandler.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import java.sql.ResultSet;
66
import java.sql.SQLException;
77

8-
public abstract class BaseTypeHandler implements TypeHandler {
8+
public abstract class BaseTypeHandler<T> implements TypeHandler<T> {
99

10-
public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
10+
public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType)
1111
throws SQLException {
1212
if (parameter == null) {
1313
if (jdbcType == null) {
@@ -24,33 +24,33 @@ public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType
2424
}
2525
}
2626

27-
public Object getResult(ResultSet rs, String columnName)
27+
public T getResult(ResultSet rs, String columnName)
2828
throws SQLException {
29-
Object result = getNullableResult(rs, columnName);
29+
T result = getNullableResult(rs, columnName);
3030
if (rs.wasNull()) {
3131
return null;
3232
} else {
3333
return result;
3434
}
3535
}
3636

37-
public Object getResult(CallableStatement cs, int columnIndex)
37+
public T getResult(CallableStatement cs, int columnIndex)
3838
throws SQLException {
39-
Object result = getNullableResult(cs, columnIndex);
39+
T result = getNullableResult(cs, columnIndex);
4040
if (cs.wasNull()) {
4141
return null;
4242
} else {
4343
return result;
4444
}
4545
}
4646

47-
public abstract void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
47+
public abstract void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType)
4848
throws SQLException;
4949

50-
public abstract Object getNullableResult(ResultSet rs, String columnName)
50+
public abstract T getNullableResult(ResultSet rs, String columnName)
5151
throws SQLException;
5252

53-
public abstract Object getNullableResult(CallableStatement cs, int columnIndex)
53+
public abstract T getNullableResult(CallableStatement cs, int columnIndex)
5454
throws SQLException;
5555

5656
}

src/main/java/org/apache/ibatis/type/BigDecimalTypeHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
import java.sql.ResultSet;
77
import java.sql.SQLException;
88

9-
public class BigDecimalTypeHandler extends BaseTypeHandler {
9+
public class BigDecimalTypeHandler extends BaseTypeHandler<BigDecimal> {
1010

11-
public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
11+
public void setNonNullParameter(PreparedStatement ps, int i, BigDecimal parameter, JdbcType jdbcType)
1212
throws SQLException {
13-
ps.setBigDecimal(i, ((BigDecimal) parameter));
13+
ps.setBigDecimal(i, parameter);
1414
}
1515

16-
public Object getNullableResult(ResultSet rs, String columnName)
16+
public BigDecimal getNullableResult(ResultSet rs, String columnName)
1717
throws SQLException {
1818
return rs.getBigDecimal(columnName);
1919
}
2020

21-
public Object getNullableResult(CallableStatement cs, int columnIndex)
21+
public BigDecimal getNullableResult(CallableStatement cs, int columnIndex)
2222
throws SQLException {
2323
return cs.getBigDecimal(columnIndex);
2424
}

src/main/java/org/apache/ibatis/type/BigIntegerTypeHandler.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@
66
import java.sql.ResultSet;
77
import java.sql.SQLException;
88

9-
public class BigIntegerTypeHandler extends BaseTypeHandler {
9+
public class BigIntegerTypeHandler extends BaseTypeHandler<BigInteger> {
1010

11-
public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
11+
public void setNonNullParameter(PreparedStatement ps, int i, BigInteger parameter, JdbcType jdbcType)
1212
throws SQLException {
13-
BigInteger bigint = (BigInteger) parameter;
14-
ps.setLong(i, bigint.longValue());
13+
ps.setLong(i, parameter.longValue());
1514
}
1615

17-
public Object getNullableResult(ResultSet rs, String columnName)
16+
public BigInteger getNullableResult(ResultSet rs, String columnName)
1817
throws SQLException {
1918
return BigInteger.valueOf(rs.getLong(columnName));
2019
}
2120

22-
public Object getNullableResult(CallableStatement cs, int columnIndex)
21+
public BigInteger getNullableResult(CallableStatement cs, int columnIndex)
2322
throws SQLException {
2423
return BigInteger.valueOf(cs.getLong(columnIndex));
2524
}

src/main/java/org/apache/ibatis/type/BlobTypeHandler.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
import java.io.ByteArrayInputStream;
44
import java.sql.*;
55

6-
public class BlobTypeHandler extends BaseTypeHandler {
6+
public class BlobTypeHandler extends BaseTypeHandler<byte[]> {
77

8-
public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
8+
public void setNonNullParameter(PreparedStatement ps, int i, byte[] parameter, JdbcType jdbcType)
99
throws SQLException {
10-
byte[] bytes = (byte[]) parameter;
11-
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
12-
ps.setBinaryStream(i, bis, bytes.length);
10+
ByteArrayInputStream bis = new ByteArrayInputStream(parameter);
11+
ps.setBinaryStream(i, bis, parameter.length);
1312
}
1413

15-
public Object getNullableResult(ResultSet rs, String columnName)
14+
public byte[] getNullableResult(ResultSet rs, String columnName)
1615
throws SQLException {
1716
Blob blob = rs.getBlob(columnName);
1817
byte[] returnValue = null;
@@ -22,7 +21,7 @@ public Object getNullableResult(ResultSet rs, String columnName)
2221
return returnValue;
2322
}
2423

25-
public Object getNullableResult(CallableStatement cs, int columnIndex)
24+
public byte[] getNullableResult(CallableStatement cs, int columnIndex)
2625
throws SQLException {
2726
Blob blob = cs.getBlob(columnIndex);
2827
byte[] returnValue = null;

src/main/java/org/apache/ibatis/type/BooleanTypeHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
import java.sql.ResultSet;
66
import java.sql.SQLException;
77

8-
public class BooleanTypeHandler extends BaseTypeHandler {
8+
public class BooleanTypeHandler extends BaseTypeHandler<Boolean> {
99

10-
public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
10+
public void setNonNullParameter(PreparedStatement ps, int i, Boolean parameter, JdbcType jdbcType)
1111
throws SQLException {
12-
ps.setBoolean(i, (Boolean) parameter);
12+
ps.setBoolean(i, parameter);
1313
}
1414

15-
public Object getNullableResult(ResultSet rs, String columnName)
15+
public Boolean getNullableResult(ResultSet rs, String columnName)
1616
throws SQLException {
1717
return rs.getBoolean(columnName);
1818
}
1919

20-
public Object getNullableResult(CallableStatement cs, int columnIndex)
20+
public Boolean getNullableResult(CallableStatement cs, int columnIndex)
2121
throws SQLException {
2222
return cs.getBoolean(columnIndex);
2323
}

src/main/java/org/apache/ibatis/type/ByteArrayTypeHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
import java.sql.ResultSet;
66
import java.sql.SQLException;
77

8-
public class ByteArrayTypeHandler extends BaseTypeHandler {
8+
public class ByteArrayTypeHandler extends BaseTypeHandler<byte[]> {
99

10-
public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
10+
public void setNonNullParameter(PreparedStatement ps, int i, byte[] parameter, JdbcType jdbcType)
1111
throws SQLException {
12-
ps.setBytes(i, (byte[]) parameter);
12+
ps.setBytes(i, parameter);
1313
}
1414

15-
public Object getNullableResult(ResultSet rs, String columnName)
15+
public byte[] getNullableResult(ResultSet rs, String columnName)
1616
throws SQLException {
1717
return rs.getBytes(columnName);
1818
}
1919

20-
public Object getNullableResult(CallableStatement cs, int columnIndex)
20+
public byte[] getNullableResult(CallableStatement cs, int columnIndex)
2121
throws SQLException {
2222
return cs.getBytes(columnIndex);
2323
}

src/main/java/org/apache/ibatis/type/ByteTypeHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
import java.sql.ResultSet;
66
import java.sql.SQLException;
77

8-
public class ByteTypeHandler extends BaseTypeHandler {
8+
public class ByteTypeHandler extends BaseTypeHandler<Byte> {
99

10-
public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
10+
public void setNonNullParameter(PreparedStatement ps, int i, Byte parameter, JdbcType jdbcType)
1111
throws SQLException {
12-
ps.setByte(i, (Byte) parameter);
12+
ps.setByte(i, parameter);
1313
}
1414

15-
public Object getNullableResult(ResultSet rs, String columnName)
15+
public Byte getNullableResult(ResultSet rs, String columnName)
1616
throws SQLException {
1717
return rs.getByte(columnName);
1818
}
1919

20-
public Object getNullableResult(CallableStatement cs, int columnIndex)
20+
public Byte getNullableResult(CallableStatement cs, int columnIndex)
2121
throws SQLException {
2222
return cs.getByte(columnIndex);
2323
}

src/main/java/org/apache/ibatis/type/ClobTypeHandler.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
import java.io.StringReader;
44
import java.sql.*;
55

6-
public class ClobTypeHandler extends BaseTypeHandler {
6+
public class ClobTypeHandler extends BaseTypeHandler<String> {
77

88

9-
public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
9+
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType)
1010
throws SQLException {
11-
String s = (String) parameter;
12-
StringReader reader = new StringReader(s);
13-
ps.setCharacterStream(i, reader, s.length());
11+
StringReader reader = new StringReader(parameter);
12+
ps.setCharacterStream(i, reader, parameter.length());
1413
}
1514

16-
public Object getNullableResult(ResultSet rs, String columnName)
15+
public String getNullableResult(ResultSet rs, String columnName)
1716
throws SQLException {
1817
String value = "";
1918
Clob clob = rs.getClob(columnName);
@@ -24,7 +23,7 @@ public Object getNullableResult(ResultSet rs, String columnName)
2423
return value;
2524
}
2625

27-
public Object getNullableResult(CallableStatement cs, int columnIndex)
26+
public String getNullableResult(CallableStatement cs, int columnIndex)
2827
throws SQLException {
2928
String value = "";
3029
Clob clob = cs.getClob(columnIndex);

src/main/java/org/apache/ibatis/type/DateOnlyTypeHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import java.sql.SQLException;
77
import java.util.Date;
88

9-
public class DateOnlyTypeHandler extends BaseTypeHandler {
9+
public class DateOnlyTypeHandler extends BaseTypeHandler<Date> {
1010

11-
public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)
11+
public void setNonNullParameter(PreparedStatement ps, int i, Date parameter, JdbcType jdbcType)
1212
throws SQLException {
13-
ps.setDate(i, new java.sql.Date(((Date) parameter).getTime()));
13+
ps.setDate(i, new java.sql.Date((parameter.getTime())));
1414
}
1515

16-
public Object getNullableResult(ResultSet rs, String columnName)
16+
public Date getNullableResult(ResultSet rs, String columnName)
1717
throws SQLException {
1818
java.sql.Date sqlDate = rs.getDate(columnName);
1919
if (sqlDate != null) {
@@ -22,7 +22,7 @@ public Object getNullableResult(ResultSet rs, String columnName)
2222
return null;
2323
}
2424

25-
public Object getNullableResult(CallableStatement cs, int columnIndex)
25+
public Date getNullableResult(CallableStatement cs, int columnIndex)
2626
throws SQLException {
2727
java.sql.Date sqlDate = cs.getDate(columnIndex);
2828
if (sqlDate != null) {

0 commit comments

Comments
 (0)