@Override public void initialize() { super.initialize(); if (batchHandler == null) { DefaultBatchHandler dbh = new DefaultBatchHandler(); dbh.setContentFormat(contentFormat); dbh.setServerTransform(serverTransform); this.batchHandler = dbh; } }
@Override public void run() { batchHandler.handleBatch(client, items); } };
@Override public void write(List<? extends DocumentWriteOperation> items) { initialize(); DatabaseClient client = determineDatabaseClientToUse(); Runnable runnable = buildRunnable(client, items); executeRunnable(runnable, items); }
/** * The given DatabaseClient is used to construct a BatchWriter that writes to MarkLogic via the REST API. The * expectation is that the client will then either call setDocumentFileReader or will rely on the default one * that's created by this class if one has not yet been set. * * @param client */ public GenericFileLoader(DatabaseClient client) { RestBatchWriter restBatchWriter = new RestBatchWriter(client); restBatchWriter.setReleaseDatabaseClients(false); this.batchWriter = restBatchWriter; }
@Override public void write(final List<? extends DocumentWriteOperation> items) { ContentSource contentSource = determineContentSourceToUse(); Runnable runnable = buildRunnable(contentSource, items); executeRunnable(runnable, items); }
RestBatchWriter assetBatchWriter = new RestBatchWriter(appConfig.newModulesDatabaseClient(), false); assetBatchWriter.setThreadCount(threadCount); AssetFileLoader assetFileLoader = new AssetFileLoader(assetBatchWriter, modulesManager); if (appConfig.getModulesLoaderBatchSize() != null) {
/** * Load files from each of the given paths, using the underlying DocumentFileReader. * <p> * If a DocumentFileReader has not been set yet, then one will be constructed before any files are read. * * @param paths * @return */ public List<DocumentFile> loadFiles(String... paths) { batchWriter.initialize(); initializeDocumentFileReader(); List<DocumentFile> documentFiles = documentFileReader.readDocumentFiles(paths); if (documentFiles != null && !documentFiles.isEmpty()) { writeBatchOfDocuments(documentFiles, 0); if (waitForCompletion) { batchWriter.waitForCompletion(); } } return documentFiles; }
@Override public void initialize() { if (taskExecutor == null) { initializeDefaultTaskExecutor(); } }
@Override public void onFailure(Throwable ex) { writeListener.onWriteFailure(ex, items); } @Override
@Override public void waitForCompletion() { super.waitForCompletion(); if (databaseClients != null && releaseDatabaseClients) { logger.info("Releasing DatabaseClient instances..."); for (DatabaseClient client : databaseClients) { client.release(); } logger.info("Finished releasing DatabaseClient instances"); } }
batchWriter.write(batch);
@Override public void handleBatch(DatabaseClient client, List<? extends DocumentWriteOperation> items) { DocumentManager<?, ?> mgr = buildDocumentManager(client); if (contentFormat != null) { mgr.setContentFormat(contentFormat); } DocumentWriteSet set = mgr.newWriteSet(); for (DocumentWriteOperation item : items) { set.add(item); } int count = set.size(); if (logger.isDebugEnabled()) { logger.debug("Writing " + count + " documents to MarkLogic"); } if (serverTransform != null) { mgr.write(set, serverTransform); } else { mgr.write(set); } if (logger.isInfoEnabled()) { logger.info("Wrote " + count + " documents to MarkLogic"); } }