Skip to content

Commit 61d58ed

Browse files
mmerdesrtroilo
authored andcommitted
#470: fixe resource leak and copy-constructor issues
1 parent c55c0cc commit 61d58ed

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

oshdb-api/src/main/java/org/heigit/ohsome/oshdb/api/mapreducer/backend/MapReducerJdbc.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.IOException;
77
import java.io.ObjectInputStream;
88
import java.sql.Connection;
9+
import java.sql.PreparedStatement;
910
import java.sql.ResultSet;
1011
import java.sql.SQLException;
1112
import java.util.Iterator;
@@ -38,8 +39,9 @@ abstract class MapReducerJdbc<X> extends MapReducer<X> implements CancelableProc
3839
}
3940

4041
// copy constructor
41-
MapReducerJdbc(MapReducerJdbc obj) {
42-
super(obj);
42+
MapReducerJdbc(MapReducerJdbc<?> source) {
43+
super(source);
44+
this.executionStartTimeMillis = source.executionStartTimeMillis;
4345
}
4446

4547
@Override
@@ -83,7 +85,7 @@ protected Stream<GridOSHEntity> getOshCellsStream(CellIdRange cellIdRange) {
8385
pstmt.setLong(3, cellIdRange.getEnd().getId());
8486
var oshCellsRawData = pstmt.executeQuery();
8587
return StreamSupport.stream(spliteratorUnknownSize(
86-
new GridOSHEntityIterator(oshCellsRawData, conn), 0
88+
new GridOSHEntityIterator(oshCellsRawData, pstmt, conn), 0
8789
), false);
8890
} catch (SQLException e) {
8991
throw new OSHDBException(e);
@@ -93,11 +95,13 @@ protected Stream<GridOSHEntity> getOshCellsStream(CellIdRange cellIdRange) {
9395
private class GridOSHEntityIterator implements Iterator<GridOSHEntity> {
9496

9597
private final ResultSet oshCellsRawData;
98+
private final PreparedStatement preparedStatement;
9699
private final Connection conn;
97100
GridOSHEntity next;
98101

99-
public GridOSHEntityIterator(ResultSet oshCellsRawData, Connection conn) {
102+
public GridOSHEntityIterator(ResultSet oshCellsRawData, PreparedStatement pstmt, Connection conn) {
100103
this.oshCellsRawData = oshCellsRawData;
104+
this.preparedStatement = pstmt;
101105
this.conn = conn;
102106
}
103107

@@ -121,6 +125,7 @@ private GridOSHEntity getNext() {
121125
if (!oshCellsRawData.next()) {
122126
try {
123127
oshCellsRawData.close();
128+
preparedStatement.close();
124129
} finally {
125130
conn.close();
126131
}

0 commit comments

Comments
 (0)