Skip to content

Commit

Permalink
fixes #1427 ArrayTypeHandler should call java.sql.Array#free().
Browse files Browse the repository at this point in the history
  • Loading branch information
harawata committed Jan 4, 2019
1 parent 56b91e5 commit 179d315
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
20 changes: 13 additions & 7 deletions src/main/java/org/apache/ibatis/type/ArrayTypeHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2015 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,20 +37,26 @@ public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, J

@Override
public Object getNullableResult(ResultSet rs, String columnName) throws SQLException {
Array array = rs.getArray(columnName);
return array == null ? null : array.getArray();
return extractArray(rs.getArray(columnName));
}

@Override
public Object getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
Array array = rs.getArray(columnIndex);
return array == null ? null : array.getArray();
return extractArray(rs.getArray(columnIndex));
}

@Override
public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
Array array = cs.getArray(columnIndex);
return array == null ? null : array.getArray();
return extractArray(cs.getArray(columnIndex));
}

protected Object extractArray(Array array) throws SQLException {
if (array == null) {
return null;
}
Object result = array.getArray();
array.free();
return result;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,6 +46,7 @@ public void shouldGetResultFromResultSetByName() throws Exception {
String[] stringArray = new String[]{"a", "b"};
when(mockArray.getArray()).thenReturn(stringArray);
assertEquals(stringArray, TYPE_HANDLER.getResult(rs, "column"));
verify(mockArray).free();
}

@Override
Expand All @@ -62,6 +63,7 @@ public void shouldGetResultFromResultSetByPosition() throws Exception {
String[] stringArray = new String[]{"a", "b"};
when(mockArray.getArray()).thenReturn(stringArray);
assertEquals(stringArray, TYPE_HANDLER.getResult(rs, 1));
verify(mockArray).free();
}

@Override
Expand All @@ -78,6 +80,7 @@ public void shouldGetResultFromCallableStatement() throws Exception {
String[] stringArray = new String[]{"a", "b"};
when(mockArray.getArray()).thenReturn(stringArray);
assertEquals(stringArray, TYPE_HANDLER.getResult(cs, 1));
verify(mockArray).free();
}

@Override
Expand Down

0 comments on commit 179d315

Please sign in to comment.