Skip to content

Commit

Permalink
[NOID] Close resources for open readers (neo4j#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
gem-neo4j authored May 8, 2024
1 parent 3587920 commit 27c604c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
3 changes: 1 addition & 2 deletions core/src/main/java/apoc/export/csv/CsvEntityLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ public void loadRelationships(
final Object data,
final String type,
final GraphDatabaseService db,
final Map<String, Map<String, String>> idMapping,
final URLAccessChecker urlAccessChecker)
final Map<String, Map<String, String>> idMapping)
throws IOException {

try (final CountingReader reader = FileUtils.readerFor(data, clc.getCompressionAlgo(), urlAccessChecker)) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/apoc/export/csv/ImportCsv.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public Stream<ProgressInfo> importCsv(

final Map<String, Map<String, String>> idMapping = new HashMap<>();
for (Map<String, Object> node : nodes) {
final Object data = node.getOrDefault("fileName", node.get("data"));
final Object fileName = node.getOrDefault("fileName", node.get("data"));
final List<String> labels = (List<String>) node.get("labels");
loader.loadNodes(data, labels, db, idMapping);
loader.loadNodes(fileName, labels, db, idMapping);
}

for (Map<String, Object> relationship : relationships) {
final Object fileName = relationship.getOrDefault("fileName", relationship.get("data"));
final String type = (String) relationship.get("type");
loader.loadRelationships(fileName, type, db, idMapping, urlAccessChecker);
loader.loadRelationships(fileName, type, db, idMapping);
}

return reporter.getTotal();
Expand Down
9 changes: 6 additions & 3 deletions core/src/main/java/apoc/export/graphml/ExportGraphML.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import apoc.Pools;
import apoc.export.cypher.ExportFileManager;
import apoc.export.cypher.FileManagerFactory;
import apoc.export.util.CountingReader;
import apoc.export.util.ExportConfig;
import apoc.export.util.ExportUtils;
import apoc.export.util.NodesAndRelsSubGraph;
Expand Down Expand Up @@ -98,9 +99,11 @@ public Stream<ProgressInfo> file(

if (exportConfig.storeNodeIds()) graphMLReader.storeNodeIds();

graphMLReader.parseXML(
FileUtils.readerFor(urlOrBinaryFile, exportConfig.getCompressionAlgo(), urlAccessChecker),
terminationGuard);
try (CountingReader reader =
FileUtils.readerFor(urlOrBinaryFile, exportConfig.getCompressionAlgo(), urlAccessChecker)) {
graphMLReader.parseXML(reader, terminationGuard);
}

return reporter.getTotal();
});
return Stream.of(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ public long parseXML(Reader input, TerminationGuard terminationGuard) throws XML
throw e;
} finally {
tx.close();
reader.close();
}
return count;
}
Expand Down

0 comments on commit 27c604c

Please sign in to comment.