Skip to content

Commit 4af868a

Browse files
MLE-32054: [java-client-api][polaris]Improper Resource Shutdown or
1 parent 0c45494 commit 4af868a

2 files changed

Lines changed: 33 additions & 27 deletions

File tree

examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/OpticExportListener.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
2+
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
33
*/
44
package com.marklogic.client.example.cookbook.datamovement;
55

@@ -18,6 +18,7 @@
1818
import com.marklogic.client.expression.PlanBuilder;
1919
import com.marklogic.client.row.RowManager;
2020
import com.marklogic.client.row.RowRecord;
21+
import com.marklogic.client.row.RowSet;
2122

2223
/**
2324
* Takes in a Function which takes QueryBatch as argument and converts it into a
@@ -74,12 +75,14 @@ public OpticExportListener(Function<QueryBatch, PlanBuilder.Plan> function, RowM
7475
public void processEvent(QueryBatch batch) {
7576
try {
7677
PlanBuilder.Plan exportPlan = exportFunction.apply(batch);
77-
for (RowRecord record : rowManager.resultRows(exportPlan)) {
78-
for (Consumer<RowRecord> listener : opticExportListeners) {
79-
try {
80-
listener.accept(record);
81-
} catch (Throwable t) {
82-
logger.error("Exception thrown by an onRowRecordReady listener ", t);
78+
try (RowSet<RowRecord> rows = rowManager.resultRows(exportPlan)) {
79+
for (RowRecord record : rows) {
80+
for (Consumer<RowRecord> listener : opticExportListeners) {
81+
try {
82+
listener.accept(record);
83+
} catch (Throwable t) {
84+
logger.error("Exception thrown by an onRowRecordReady listener ", t);
85+
}
8386
}
8487
}
8588
}

examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/OpticExportToWriterListener.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
2+
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
33
*/
44
package com.marklogic.client.example.cookbook.datamovement;
55

@@ -20,6 +20,7 @@
2020
import com.marklogic.client.expression.PlanBuilder.Plan;
2121
import com.marklogic.client.row.RowManager;
2222
import com.marklogic.client.row.RowRecord;
23+
import com.marklogic.client.row.RowSet;
2324

2425
/**
2526
* An extension of OpticExportListener which facilitates writing all row records
@@ -92,28 +93,30 @@ public void processEvent(QueryBatch batch) {
9293
try {
9394
PlanBuilder.Plan exportPlan = exportFunction.apply(batch);
9495
synchronized (writer) {
95-
for (RowRecord record : rowManager.resultRows(exportPlan)) {
96-
try {
97-
if (prefix != null)
98-
writer.write(prefix);
99-
if (outputListeners.size() > 0) {
100-
for (OpticOutputListener listener : outputListeners) {
101-
String output = null;
102-
try {
103-
output = listener.generateOutput(record);
104-
} catch (Throwable t) {
105-
logger.error("Exception thrown by an onGenerateOutput listener", t);
96+
try (RowSet<RowRecord> rows = rowManager.resultRows(exportPlan)) {
97+
for (RowRecord record : rows) {
98+
try {
99+
if (prefix != null)
100+
writer.write(prefix);
101+
if (outputListeners.size() > 0) {
102+
for (OpticOutputListener listener : outputListeners) {
103+
String output = null;
104+
try {
105+
output = listener.generateOutput(record);
106+
} catch (Throwable t) {
107+
logger.error("Exception thrown by an onGenerateOutput listener", t);
108+
}
109+
if (output != null)
110+
writer.write(output);
106111
}
107-
if (output != null)
108-
writer.write(output);
112+
} else {
113+
writer.write(record.toString());
109114
}
110-
} else {
111-
writer.write(record.toString());
115+
if (suffix != null)
116+
writer.write(suffix);
117+
} catch (IOException e) {
118+
throw new DataMovementException("Failed to write the Optic API records", e);
112119
}
113-
if (suffix != null)
114-
writer.write(suffix);
115-
} catch (IOException e) {
116-
throw new DataMovementException("Failed to write the Optic API records", e);
117120
}
118121
}
119122
}

0 commit comments

Comments
 (0)