Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
package com.marklogic.client.example.cookbook.datamovement;

Expand All @@ -18,6 +18,7 @@
import com.marklogic.client.expression.PlanBuilder;
import com.marklogic.client.row.RowManager;
import com.marklogic.client.row.RowRecord;
import com.marklogic.client.row.RowSet;

/**
* Takes in a Function which takes QueryBatch as argument and converts it into a
Expand Down Expand Up @@ -74,12 +75,14 @@ public OpticExportListener(Function<QueryBatch, PlanBuilder.Plan> function, RowM
public void processEvent(QueryBatch batch) {
try {
PlanBuilder.Plan exportPlan = exportFunction.apply(batch);
for (RowRecord record : rowManager.resultRows(exportPlan)) {
for (Consumer<RowRecord> listener : opticExportListeners) {
try {
listener.accept(record);
} catch (Throwable t) {
logger.error("Exception thrown by an onRowRecordReady listener ", t);
try (RowSet<RowRecord> rows = rowManager.resultRows(exportPlan)) {
for (RowRecord record : rows) {
for (Consumer<RowRecord> listener : opticExportListeners) {
try {
listener.accept(record);
} catch (Throwable t) {
logger.error("Exception thrown by an onRowRecordReady listener ", t);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
package com.marklogic.client.example.cookbook.datamovement;

Expand All @@ -20,6 +20,7 @@
import com.marklogic.client.expression.PlanBuilder.Plan;
import com.marklogic.client.row.RowManager;
import com.marklogic.client.row.RowRecord;
import com.marklogic.client.row.RowSet;

/**
* An extension of OpticExportListener which facilitates writing all row records
Expand Down Expand Up @@ -92,28 +93,30 @@ public void processEvent(QueryBatch batch) {
try {
PlanBuilder.Plan exportPlan = exportFunction.apply(batch);
synchronized (writer) {
for (RowRecord record : rowManager.resultRows(exportPlan)) {
try {
if (prefix != null)
writer.write(prefix);
if (outputListeners.size() > 0) {
for (OpticOutputListener listener : outputListeners) {
String output = null;
try {
output = listener.generateOutput(record);
} catch (Throwable t) {
logger.error("Exception thrown by an onGenerateOutput listener", t);
try (RowSet<RowRecord> rows = rowManager.resultRows(exportPlan)) {
for (RowRecord record : rows) {
try {
if (prefix != null)
writer.write(prefix);
if (outputListeners.size() > 0) {
for (OpticOutputListener listener : outputListeners) {
String output = null;
try {
output = listener.generateOutput(record);
} catch (Throwable t) {
logger.error("Exception thrown by an onGenerateOutput listener", t);
}
if (output != null)
writer.write(output);
}
if (output != null)
writer.write(output);
} else {
writer.write(record.toString());
}
} else {
writer.write(record.toString());
if (suffix != null)
writer.write(suffix);
} catch (IOException e) {
throw new DataMovementException("Failed to write the Optic API records", e);
}
if (suffix != null)
writer.write(suffix);
} catch (IOException e) {
throw new DataMovementException("Failed to write the Optic API records", e);
}
}
}
Expand Down
Loading