public class ApplyTransformListener extends Object implements QueryBatchListener
Modifies documents in-place in the database by applying a server-side transform. If the transform modifies documents to no longer match the query, ApplyTransformListener should only be used when:
QueryBatcher.withConsistentSnapshot() is called, ornewQueryBatcher(Iterator<String>) is used to traverse a static data setFor example, given the REST transform myTransform.sjs:
function transform_function(context, params, content) {
var document = content.toObject();
document.someProperty = params.newValue;
return document;
};
exports.transform = transform_function;
installed in the server like so (using the MarkLogic Java Client API):
restAdminClient.newServerConfigManager().newTransformExtensionsManager().writeJavascriptTransform(
"myTransform", new FileHandle(new File("myTransform.sjs")));
you can run the transform on documents matching a query like so:
ServerTransform transform = new ServerTransform(transformName2)
.addParameter("newValue", "some new value");
ApplyTransformListener listener = new ApplyTransformListener()
.withTransform(transform)
.withApplyResult(ApplyResult.REPLACE);
QueryBatcher batcher = moveMgr.newQueryBatcher(query)
.onUrisReady(listener);
JobTicket ticket = moveMgr.startJob( batcher );
batcher.awaitCompletion();
moveMgr.stopJob(ticket);
As with all the provided listeners, this listener will not meet the needs of all applications but the source code for it should serve as helpful sample code so you can write your own custom listeners.
| Modifier and Type | Class and Description |
|---|---|
static class |
ApplyTransformListener.ApplyResult
Either
ApplyTransformListener.ApplyResult.REPLACE each document with the result of the transform, or run the transform with each document as input, but ApplyTransformListener.ApplyResult.IGNORE the result. |
| Constructor and Description |
|---|
ApplyTransformListener() |
| Modifier and Type | Method and Description |
|---|---|
ApplyTransformListener |
onBatchFailure(BatchFailureListener<Batch<String>> listener)
When a batch fails or a callback throws an Exception, run this listener code.
|
ApplyTransformListener |
onSkipped(QueryBatchListener listener)
When documents were not found and therefore not transformed, run this listener code.
|
ApplyTransformListener |
onSuccess(QueryBatchListener listener)
When a batch has been successfully transformed, run this listener code.
|
void |
processEvent(QueryBatch batch)
The standard BatchListener action called by QueryBatcher.
|
ApplyTransformListener |
withApplyResult(ApplyTransformListener.ApplyResult applyResult)
|
ApplyTransformListener |
withTransform(ServerTransform transform)
The ServerTransform to run on each document from each batch.
|
public void processEvent(QueryBatch batch)
The standard BatchListener action called by QueryBatcher.
processEvent in interface BatchListener<QueryBatch>processEvent in interface QueryBatchListenerbatch - the batch of uris and some metadata about the current status of the jobpublic ApplyTransformListener onSuccess(QueryBatchListener listener)
When a batch has been successfully transformed, run this listener code. Multiple listeners can be registered with this method.
listener - the code to run when a batch is successfully transformedpublic ApplyTransformListener onSkipped(QueryBatchListener listener)
When documents were not found and therefore not transformed, run this listener code. Multiple listeners can be registered with this method.
listener - the code to run when documents were not transformedpublic ApplyTransformListener onBatchFailure(BatchFailureListener<Batch<String>> listener)
When a batch fails or a callback throws an Exception, run this listener code. Multiple listeners can be registered with this method.
listener - the code to run when a failure occurspublic ApplyTransformListener withTransform(ServerTransform transform)
The ServerTransform to run on each document from each batch.
transform - the ServerTransform to run on each document from each batchpublic ApplyTransformListener withApplyResult(ApplyTransformListener.ApplyResult applyResult)
Whether to REPLACE each document with the result of the transform, or run the transform with each document as input, but IGNORE the result.
applyResult - the behavior required after each transform is runCopyright © 2013-2017 MarkLogic Corporation.