3131import java .util .stream .Collectors ;
3232
3333/**
34- * Modifies documents in-place in the database by applying a {@link
34+ * <p> Modifies documents in-place in the database by applying a {@link
3535 * com.marklogic.client.document.ServerTransform server-side transform}.
3636 * If the transform modifies documents to no longer match the query,
37- * ApplyTransformListener should only be used when:
37+ * ApplyTransformListener should only be used when:</p>
3838 *
39- * 1. [merge timestamp][] is enabled and
40- * {@link QueryBatcher#withConsistentSnapshot} is called, or
41- * 2. {@link DataMovementManager#newQueryBatcher(Iterator)
42- * newQueryBatcher(Iterator<String>)} is used to traverse a static data set
39+ * <ol>
40+ * <li><a href="https://docs.marklogic.com/guide/app-dev/point_in_time#id_32468">merge timestamp</a>
41+ * is enabled and {@link QueryBatcher#withConsistentSnapshot} is called, or</li>
42+ * <li>{@link DataMovementManager#newQueryBatcher(Iterator)
43+ * newQueryBatcher(Iterator<String>)} is used to traverse a static data set</li>
44+ * </ol>
4345 *
44- * [merge timestamp]: https://docs.marklogic.com/guide/app-dev/point_in_time#id_32468
46+ * <br>For example, given the REST transform myTransform.sjs:
4547 *
46- * For example, given the REST transform myTransform.sjs:
47- *
48- * function transform_function(context, params, content) {
49- * var document = content.toObject() ;
50- * document.someProperty = params.newValue ;
51- * return document ;
52- * } ;
53- * exports.transform = transform_function;
48+ * <pre>{@code
49+ * function transform_function(context, params, content) {
50+ * var document = content.toObject();
51+ * document.someProperty = params.newValue ;
52+ * return document;
53+ * } ;
54+ * exports.transform = transform_function ;
55+ *}</pre>
5456 *
5557 * installed in the server like so (using the MarkLogic Java Client API):
5658 *
57- * restAdminClient.newServerConfigManager().newTransformExtensionsManager().writeJavascriptTransform(
58- * "myTransform", new FileHandle(new File("myTransform.sjs")));
59+ * <pre>{@code
60+ * restAdminClient.newServerConfigManager().newTransformExtensionsManager().writeJavascriptTransform(
61+ * "myTransform", new FileHandle(new File("myTransform.sjs")));
62+ *}</pre>
5963 *
6064 * you can run the transform on documents matching a query like so:
6165 *
62- * ServerTransform transform = new ServerTransform(transformName2)
63- * .addParameter("newValue", "some new value");
64- * ApplyTransformListener listener = new ApplyTransformListener()
65- * .withTransform(transform)
66- * .withApplyResult(ApplyResult.REPLACE);
67- * QueryBatcher batcher = moveMgr.newQueryBatcher(query)
68- * .onUrisReady(listener);
69- * JobTicket ticket = moveMgr.startJob( batcher );
70- * batcher.awaitCompletion();
71- * moveMgr.stopJob(ticket);
72- *
73- * As with all the provided listeners, this listener will not meet the needs of
74- * all applications but the [source code][] for it should serve as helpful sample
75- * code so you can write your own custom listeners.
66+ * <pre>{@code
67+ * ServerTransform transform = new ServerTransform(transformName2)
68+ * .addParameter("newValue", "some new value");
69+ * ApplyTransformListener listener = new ApplyTransformListener()
70+ * .withTransform(transform)
71+ * .withApplyResult(ApplyResult.REPLACE);
72+ * QueryBatcher batcher = moveMgr.newQueryBatcher(query)
73+ * .onUrisReady(listener);
74+ * JobTicket ticket = moveMgr.startJob( batcher );
75+ * batcher.awaitCompletion();
76+ * moveMgr.stopJob(ticket);
77+ *}</pre>
7678 *
77- * [source code]: https://github.com/marklogic/java-client-api/blob/develop/src/main/java/com/marklogic/client/datamovement/ApplyTransformListener.java
79+ * <p>As with all the provided listeners, this listener will not meet the needs
80+ * of all applications but the
81+ * <a target="_blank" href="https://github.com/marklogic/java-client-api/blob/develop/src/main/java/com/marklogic/client/datamovement/ApplyTransformListener.java">source code</a>
82+ * for it should serve as helpful sample code so you can write your own custom
83+ * listeners.</p>
7884 *
79- * In this listener, we initialize only the HostAvailabilityListener's
85+ * <p> In this listener, we initialize only the HostAvailabilityListener's
8086 * RetryListener and not NoResponseListener's RetryListener because if we get
8187 * empty responses when we try to apply a transform to the batch of URIs
8288 * retrieved from the server, we are not sure what happened in the server - if
8389 * the transform has been applied or it has not been applied. Retrying in those
8490 * scenarios would apply the transform twice if the transform has been already
85- * applied and this is not desirable.
91+ * applied and this is not desirable.</p>
8692 *
87- * In order to handle such scenarios where we get an empty response, it is
93+ * <p> In order to handle such scenarios where we get an empty response, it is
8894 * recommended to add a BatchFailureListener which would take care of apply
8995 * transform failures and retry only for those URIs for which the apply
9096 * transform has failed. If the transform is idempotent, we can just initialize
91- * the RetryListener of the NoResponseListener by calling NoResponseListener.initializeRetryListener(this)
92- * and add it to the BatchFailureListeners similar to what we have in the other listeners.
97+ * the RetryListener of the NoResponseListener by calling
98+ * NoResponseListener.initializeRetryListener(this) and add it to the
99+ * BatchFailureListeners similar to what we have in the other listeners.</p>
93100 */
94101public class ApplyTransformListener implements QueryBatchListener {
95102 private static Logger logger = LoggerFactory .getLogger (ApplyTransformListener .class );
@@ -105,6 +112,11 @@ public ApplyTransformListener() {
105112 "if you see this once/batch, fix your job configuration" );
106113 }
107114
115+ /**
116+ * This implementation of initializeListener adds this instance of
117+ * ApplyTransformListener to the two RetryListener's in this QueryBatcher so
118+ * they will retry any batches that fail during the apply-transform request.
119+ */
108120 @ Override
109121 public void initializeListener (QueryBatcher queryBatcher ) {
110122 HostAvailabilityListener hostAvailabilityListener = HostAvailabilityListener .getInstance (queryBatcher );
0 commit comments