Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit c27b67e

Browse files
committed
#129 Depending on ML Java 5.1.0
Also upgraded XCC version
1 parent d005f15 commit c27b67e

File tree

4 files changed

+44
-107
lines changed

4 files changed

+44
-107
lines changed

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ plugins {
77
id "com.github.jk1.dependency-license-report" version "1.3"
88
}
99

10-
sourceCompatibility = "1.8"
11-
targetCompatibility = "1.8"
10+
sourceCompatibility = "9"
11+
targetCompatibility = "9"
1212

1313
repositories {
1414
jcenter()
@@ -17,8 +17,8 @@ repositories {
1717
}
1818

1919
dependencies {
20-
api 'com.marklogic:marklogic-client-api:4.2.0'
21-
api 'com.marklogic:marklogic-xcc:9.0.9'
20+
api 'com.marklogic:marklogic-client-api:5.1.0'
21+
api 'com.marklogic:marklogic-xcc:10.0.3'
2222
api 'org.jdom:jdom2:2.0.6'
2323
api 'org.springframework:spring-context:4.3.7.RELEASE'
2424

src/main/java/com/marklogic/client/ext/batch/SimpleDocumentWriteOperation.java

Lines changed: 0 additions & 78 deletions
This file was deleted.

src/main/java/com/marklogic/client/ext/file/DocumentFile.java

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.marklogic.client.ext.file;
22

33
import com.marklogic.client.document.DocumentWriteOperation;
4-
import com.marklogic.client.io.*;
4+
import com.marklogic.client.impl.DocumentWriteOperationImpl;
5+
import com.marklogic.client.io.DocumentMetadataHandle;
6+
import com.marklogic.client.io.Format;
7+
import com.marklogic.client.io.InputStreamHandle;
8+
import com.marklogic.client.io.StringHandle;
59
import com.marklogic.client.io.marker.AbstractWriteHandle;
610
import com.marklogic.client.io.marker.DocumentMetadataWriteHandle;
711
import org.springframework.core.io.FileSystemResource;
@@ -12,14 +16,14 @@
1216
import java.nio.file.Path;
1317

1418
/**
15-
* Encapsulates a file that should be written to MarkLogic as a single document. Implements DocumentWriteOperation so
16-
* that it can be easily written via the Java Client API.
17-
*
18-
* The modifiedContent allows for the content of this DocumentWriteOperation to be set via that property instead of via
19-
* the File. The assumption is that something like a DocumentFileProcessor has read in the contents of the File used to
20-
* construct this class,
19+
* Encapsulates a file that should be written to MarkLogic as a single document. A DocumentWriteOperation can be
20+
* constructed via the toDocumentWriteOperation method.
21+
* <p>
22+
* The modifiedContent allows for the content of the constructed DocumentWriteOperation to be set via that property
23+
* instead of via the File. The assumption is that something like a DocumentFileProcessor has read in the contents of
24+
* the File used to construct this class.
2125
*/
22-
public class DocumentFile implements DocumentWriteOperation {
26+
public class DocumentFile {
2327

2428
private String uri;
2529
private Resource resource;
@@ -43,22 +47,28 @@ private void init(String uri, Resource resource) {
4347
this.documentMetadata = new DocumentMetadataHandle();
4448
}
4549

46-
@Override
50+
public DocumentWriteOperation toDocumentWriteOperation() {
51+
return new DocumentWriteOperationImpl(
52+
getOperationType(),
53+
uri,
54+
getMetadata(),
55+
getContent(),
56+
getTemporalDocumentURI()
57+
);
58+
}
59+
4760
public String getUri() {
4861
return uri;
4962
}
5063

51-
@Override
52-
public OperationType getOperationType() {
53-
return OperationType.DOCUMENT_WRITE;
64+
public DocumentWriteOperation.OperationType getOperationType() {
65+
return DocumentWriteOperation.OperationType.DOCUMENT_WRITE;
5466
}
5567

56-
@Override
5768
public DocumentMetadataWriteHandle getMetadata() {
5869
return documentMetadata;
5970
}
6071

61-
@Override
6272
public AbstractWriteHandle getContent() {
6373
if (modifiedContent != null) {
6474
StringHandle h = new StringHandle(modifiedContent);
@@ -73,7 +83,6 @@ public AbstractWriteHandle getContent() {
7383
return format != null ? h.withFormat(format) : h;
7484
}
7585

76-
@Override
7786
public String getTemporalDocumentURI() {
7887
return temporalDocumentURI;
7988
}
@@ -143,6 +152,7 @@ public Path getRootPath() {
143152

144153
/**
145154
* Optional to set - the Path that this File was loaded relative to
155+
*
146156
* @param rootPath
147157
*/
148158
public void setRootPath(Path rootPath) {

src/main/java/com/marklogic/client/ext/file/GenericFileLoader.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.marklogic.client.ext.file;
22

33
import com.marklogic.client.DatabaseClient;
4+
import com.marklogic.client.document.DocumentWriteOperation;
45
import com.marklogic.client.ext.batch.BatchWriter;
56
import com.marklogic.client.ext.batch.RestBatchWriter;
67
import com.marklogic.client.ext.helper.LoggingObject;
@@ -10,12 +11,13 @@
1011
import java.util.ArrayList;
1112
import java.util.Arrays;
1213
import java.util.List;
14+
import java.util.stream.Collectors;
1315

1416
/**
1517
* Generic implementation of FileLoader. Delegates to a DocumentFileReader for reading from a set of file paths, and
1618
* delegates to a BatchWriter for writing to MarkLogic (where that BatchWriter could use XCC, the REST API, or the
1719
* Data Movement SDK in ML9).
18-
*
20+
* <p>
1921
* The batchSize property defaults to null, which means all files are written in one call via the BatchWriter. Setting
2022
* this means that the List of DocumentFile objects read from the DocumentFileReader will be written in batches, each
2123
* the size of the batchSize property, except for the final one that may be less than this size.
@@ -108,15 +110,18 @@ protected void writeBatchOfDocuments(List<DocumentFile> documentFiles, final int
108110

109111
List<DocumentFile> batch = documentFiles.subList(startPosition, endPosition);
110112
if (!batch.isEmpty()) {
111-
if (logger.isInfoEnabled()) {
113+
final boolean infoEnabled = logger.isInfoEnabled();
114+
if (infoEnabled) {
112115
logger.info(format("Writing %d files", batch.size()));
113-
if (logFileUris) {
114-
for (DocumentFile df : batch) {
115-
logger.info("Writing: " + df.getUri());
116-
}
117-
}
118116
}
119-
batchWriter.write(batch);
117+
List<DocumentWriteOperation> documentWriteOperations = batch.stream().map(file -> {
118+
if (logFileUris && infoEnabled) {
119+
final String uri = file.getUri();
120+
logger.info("Writing: " + uri != null ? uri : file.getTemporalDocumentURI());
121+
}
122+
return file.toDocumentWriteOperation();
123+
}).collect(Collectors.toList());
124+
batchWriter.write(documentWriteOperations);
120125
}
121126

122127
if (endPosition < documentFilesSize) {
@@ -161,7 +166,7 @@ public void prepareAbstractDocumentFileReader(AbstractDocumentFileReader reader)
161166
FormatDocumentFileProcessor processor = reader.getFormatDocumentFileProcessor();
162167
FormatGetter formatGetter = processor.getFormatGetter();
163168
if (formatGetter instanceof DefaultDocumentFormatGetter) {
164-
DefaultDocumentFormatGetter ddfg = (DefaultDocumentFormatGetter)formatGetter;
169+
DefaultDocumentFormatGetter ddfg = (DefaultDocumentFormatGetter) formatGetter;
165170
for (String ext : additionalBinaryExtensions) {
166171
ddfg.getBinaryExtensions().add(ext);
167172
}
@@ -181,7 +186,7 @@ public void prepareAbstractDocumentFileReader(AbstractDocumentFileReader reader)
181186
*/
182187
protected void applyTokenReplacerOnKnownDocumentProcessors(AbstractDocumentFileReader reader) {
183188
if (reader instanceof DefaultDocumentFileReader && tokenReplacer != null) {
184-
DefaultDocumentFileReader defaultReader = (DefaultDocumentFileReader)reader;
189+
DefaultDocumentFileReader defaultReader = (DefaultDocumentFileReader) reader;
185190
CollectionsFileDocumentFileProcessor cp = defaultReader.getCollectionsFileDocumentFileProcessor();
186191
if (cp != null) {
187192
cp.setTokenReplacer(tokenReplacer);

0 commit comments

Comments
 (0)