Created
May 20, 2021 15:21
-
-
Save ableasdale/09a045546b9c3eeea3a473c349bfcd22 to your computer and use it in GitHub Desktop.
MarkLogic Data Movement SDK - Batcher Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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