|
1 | 1 | /* |
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. |
3 | 3 | */ |
4 | 4 | package com.marklogic.client.example.cookbook.datamovement; |
5 | 5 |
|
|
20 | 20 | import com.marklogic.client.expression.PlanBuilder.Plan; |
21 | 21 | import com.marklogic.client.row.RowManager; |
22 | 22 | import com.marklogic.client.row.RowRecord; |
| 23 | +import com.marklogic.client.row.RowSet; |
23 | 24 |
|
24 | 25 | /** |
25 | 26 | * An extension of OpticExportListener which facilitates writing all row records |
@@ -92,28 +93,30 @@ public void processEvent(QueryBatch batch) { |
92 | 93 | try { |
93 | 94 | PlanBuilder.Plan exportPlan = exportFunction.apply(batch); |
94 | 95 | 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); |
106 | 111 | } |
107 | | - if (output != null) |
108 | | - writer.write(output); |
| 112 | + } else { |
| 113 | + writer.write(record.toString()); |
109 | 114 | } |
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); |
112 | 119 | } |
113 | | - if (suffix != null) |
114 | | - writer.write(suffix); |
115 | | - } catch (IOException e) { |
116 | | - throw new DataMovementException("Failed to write the Optic API records", e); |
117 | 120 | } |
118 | 121 | } |
119 | 122 | } |
|
0 commit comments