Skip to content

Instantly share code, notes, and snippets.

@ableasdale
Created May 20, 2021 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ableasdale/09a045546b9c3eeea3a473c349bfcd22 to your computer and use it in GitHub Desktop.
Save ableasdale/09a045546b9c3eeea3a473c349bfcd22 to your computer and use it in GitHub Desktop.
MarkLogic Data Movement SDK - Batcher Example
import com.marklogic.client.DatabaseClient;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.datamovement.DataMovementManager;
import com.marklogic.client.datamovement.QueryBatcher;
import com.marklogic.client.query.StructuredQueryBuilder;
import com.marklogic.client.query.StructuredQueryDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.invoke.MethodHandles;
public class DMSDKBatch {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static void main(String[] args) {
DatabaseClient client = DatabaseClientFactory.newClient("localhost", 8000, "Meters",
new DatabaseClientFactory.DigestAuthContext("admin", "admin"));
// Generate a full and-query (to get every URI)
StructuredQueryDefinition sqd = new StructuredQueryBuilder().and();
DataMovementManager dmm = client.newDataMovementManager();
QueryBatcher batcher = dmm.newQueryBatcher(sqd);
batcher.onUrisReady(batch -> {
for (String uri : batch.getItems()) {
LOG.info("URI: " + uri);
}
}
)
.onQueryFailure(exception -> exception.printStackTrace());
// *** Step 4: Submit the DMSDK job ***
dmm.startJob(batcher);
// Wait for the job to complete, and then stop it.
batcher.awaitCompletion();
dmm.stopJob(batcher);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment