Skip to content

Commit 130c61d

Browse files
committed
Merge branch 'bulkReadWrite' of github.com:marklogic/java-client-api into dev
2 parents ae7f5b6 + ac5a76e commit 130c61d

File tree

5 files changed

+82
-31
lines changed

5 files changed

+82
-31
lines changed

src/main/java/com/marklogic/client/impl/JerseyServices.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ private DocumentPage convertToDocumentPage(JerseyResultIterator iterator, boolea
726726
JerseyResult result = iterator.next();
727727
DocumentRecord record;
728728
if ( hasMetadata ) {
729-
if ( iterator.hasNext() ) {
729+
if ( ! iterator.hasNext() ) {
730730
throw new MarkLogicInternalException(
731731
"Metadata and content parts should always come in pairs!");
732732
}
@@ -750,6 +750,8 @@ private JerseyResultIterator getBulkDocumentsImpl(RequestLogger reqlog,
750750

751751
String path = "documents";
752752
RequestParameters params = new RequestParameters();
753+
boolean withContent = true;
754+
addCategoryParams(categories, params, withContent);
753755
if (format != null) params.add("format", format.toString().toLowerCase());
754756
for (String uri: uris) {
755757
params.add("uri", uri);
@@ -764,6 +766,8 @@ private JerseyResultIterator getBulkDocumentsImpl(RequestLogger reqlog,
764766
Set<Metadata> categories, Format format, RequestParameters extraParams)
765767
throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException {
766768
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
769+
boolean withContent = true;
770+
addCategoryParams(categories, params, withContent);
767771
if (searchHandle != null && view != null) params.add("view", view.toString().toLowerCase());
768772
if (start > 1) params.add("start", Long.toString(start));
769773
if (pageLength > 0) params.add("pageLength", Long.toString(pageLength));
@@ -1605,6 +1609,39 @@ private void completeTransaction(String transactionId, String result)
16051609
response.close();
16061610
}
16071611

1612+
private void addCategoryParams(Set<Metadata> categories, MultivaluedMap<String, String> params,
1613+
boolean withContent)
1614+
{
1615+
if (withContent && categories == null || categories.size() == 0) {
1616+
params.add("category", "content");
1617+
} else {
1618+
if (withContent) params.add("category", "content");
1619+
if (categories.contains(Metadata.ALL)) {
1620+
params.add("category", "metadata");
1621+
} else {
1622+
for (Metadata category : categories) {
1623+
params.add("category", category.name().toLowerCase());
1624+
}
1625+
}
1626+
}
1627+
}
1628+
private void addCategoryParams(Set<Metadata> categories, RequestParameters params,
1629+
boolean withContent)
1630+
{
1631+
if (withContent && categories == null || categories.size() == 0) {
1632+
params.add("category", "content");
1633+
} else {
1634+
if (withContent) params.add("category", "content");
1635+
if (categories.contains(Metadata.ALL)) {
1636+
params.add("category", "metadata");
1637+
} else {
1638+
for (Metadata category : categories) {
1639+
params.add("category", category.name().toLowerCase());
1640+
}
1641+
}
1642+
}
1643+
}
1644+
16081645
private MultivaluedMap<String, String> makeDocumentParams(String uri,
16091646
Set<Metadata> categories, String transactionId,
16101647
RequestParameters extraParams) {

src/main/java/com/marklogic/client/impl/PojoQueryBuilderImpl.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public StructuredQueryDefinition value(String pojoField, String[] options,
105105
return value(jsonProperty(pojoField), null, options, weight, values);
106106
}
107107
}
108-
public StructuredQueryDefinition word(String pojoField, String[] words) {
108+
public StructuredQueryDefinition word(String pojoField, String... words) {
109109
if ( wrapQueries ) {
110110
return super.containerQuery(jsonProperty(classWrapper),
111111
super.word(jsonProperty(pojoField), words));
@@ -123,12 +123,6 @@ public StructuredQueryDefinition word(String pojoField, String[] options,
123123
return super.word(jsonProperty(pojoField), null, options, weight, words);
124124
}
125125
}
126-
public StructuredQueryDefinition word(String... words) {
127-
return super.word(jsonProperty(classWrapper), words);
128-
}
129-
public StructuredQueryDefinition word(String[] options, double weight, String... words) {
130-
return super.word(jsonProperty(classWrapper), null, options, weight, words);
131-
}
132126

133127
public String getRangeIndexType(String fieldName) {
134128
// map java types to acceptable Range Index types

src/main/java/com/marklogic/client/pojo/PojoQueryBuilder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ public StructuredQueryDefinition range(String pojoField, String[] options,
2525
public StructuredQueryDefinition value(String pojoField, String... values);
2626
public StructuredQueryDefinition value(String pojoField, String[] options,
2727
double weight, String... values);
28-
public StructuredQueryDefinition word(String pojoField, String[] words);
28+
public StructuredQueryDefinition word(String pojoField, String... words);
2929
public StructuredQueryDefinition word(String pojoField, String[] options,
3030
double weight, String... words);
31-
public StructuredQueryDefinition word(String... words);
32-
public StructuredQueryDefinition word(String[] options, double weight, String... words);
3331

3432
// All following method signatures copied from StructuredQueryBuilder since it has no interface we can extend
3533
public StructuredQueryDefinition and(StructuredQueryDefinition... queries);

src/test/java/com/marklogic/client/test/BulkReadWriteTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.junit.Test;
4040

4141
import com.marklogic.client.document.DocumentDescriptor;
42+
import com.marklogic.client.document.DocumentManager.Metadata;
4243
import com.marklogic.client.document.DocumentPage;
4344
import com.marklogic.client.document.DocumentRecord;
4445
import com.marklogic.client.document.DocumentWriteSet;
@@ -305,6 +306,8 @@ public void testF_DefaultMetadata() {
305306
// Execute the write operation
306307
jdm.write(batch);
307308

309+
// need the "synthetic response" format to be XML
310+
jdm.setResponseFormat(Format.XML);
308311
// Check the results
309312
assertEquals("Doc1 should have the system default quality of 0", 0,
310313
jdm.readMetadata("doc1.json", new DocumentMetadataHandle()).getQuality());
@@ -325,6 +328,26 @@ public void testF_DefaultMetadata() {
325328
jdm.readMetadata("doc4.json", new DocumentMetadataHandle()).getQuality());
326329
assertEquals("Doc5 should use the 2nd batch default metadata, with quality 2", defaultMetadata2.getQuality(),
327330
jdm.readMetadata("doc5.json", new DocumentMetadataHandle()).getQuality());
331+
332+
// let's check getting just quality metadata with content in bulk read
333+
jdm.setMetadataCategories(Metadata.QUALITY);
334+
DocumentPage documents = jdm.read("doc1.json", "doc2.json", "doc3.json");
335+
336+
for ( DocumentRecord doc: documents ) {
337+
DocumentMetadataHandle metadata = doc.getMetadata(new DocumentMetadataHandle());
338+
StringHandle content = doc.getContent(new StringHandle());
339+
if ( "doc1.json".equals(doc.getUri()) ) {
340+
assertEquals("Doc 1 should have the system default quality of 0", 0, metadata.getQuality());
341+
assertTrue("Doc 1 contents are wrong", content.get().matches("\\{\"number\": ?1\\}"));
342+
} else if ( "doc2.json".equals(doc.getUri()) ) {
343+
assertEquals("Doc 2 should use the first batch default metadata, with quality 1", 1, metadata.getQuality());
344+
assertTrue("Doc 2 contents are wrong", content.get().matches("\\{\"number\": ?2\\}"));
345+
} else if ( "doc3.json".equals(doc.getUri()) ) {
346+
assertEquals("Doc 3 should have the system default document quality (0) because quality " +
347+
"was not included in the document-specific metadata.", 0, metadata.getQuality());
348+
assertTrue("Doc 3 contents are wrong", content.get().matches("\\{\"number\": ?3\\}"));
349+
}
350+
}
328351
}
329352

330353

src/test/java/com/marklogic/client/test/PojoFacadeTest.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void testC_QueryPojos() throws Exception {
107107

108108

109109
PojoQueryBuilder<City> qb = cities.getQueryBuilder();
110-
QueryDefinition query = qb.word("Tungi", "Dalatando", "Chittagong");
110+
QueryDefinition query = qb.term("Tungi", "Dalatando", "Chittagong");
111111
page = cities.search(query, 1);
112112
iterator = page.iterator();
113113
numRead = 0;
@@ -130,7 +130,7 @@ public void testC_QueryPojos() throws Exception {
130130
assertEquals("Failed to find number of records expected", 7, numRead);
131131
assertEquals("PojoPage failed to report number of records expected", numRead, page.size());
132132

133-
query = qb.containerQuery("alternateNames", qb.word("San", "Santo"));
133+
query = qb.containerQuery("alternateNames", qb.term("San", "Santo"));
134134
page = cities.search(query, 1);
135135
iterator = page.iterator();
136136
numRead = 0;
@@ -143,6 +143,17 @@ public void testC_QueryPojos() throws Exception {
143143
assertEquals("Failed to find number of records expected", 11, numRead);
144144
assertEquals("PojoPage failed to report number of records expected", numRead, page.size());
145145

146+
query = qb.range("population", Operator.LT, 350000);
147+
page = cities.search(query, 1);
148+
iterator = page.iterator();
149+
numRead = 0;
150+
while ( iterator.hasNext() ) {
151+
City city = iterator.next();
152+
numRead++;
153+
}
154+
assertEquals("Failed to find number of records expected", 21, numRead);
155+
assertEquals("PojoPage failed to report number of records expected", numRead, page.size());
156+
146157
query = qb.geospatial(
147158
qb.geoField("latLong"),
148159
qb.circle(-34, -58, 1)
@@ -190,17 +201,6 @@ public void testC_QueryPojos() throws Exception {
190201
// when this works we'll find out how many we expect
191202
assertEquals("Failed to find number of records expected", -1, numRead);
192203
assertEquals("PojoPage failed to report number of records expected", numRead, page.size());
193-
194-
query = qb.range("population", Operator.LT, 350000);
195-
page = cities.search(query, 1);
196-
iterator = page.iterator();
197-
numRead = 0;
198-
while ( iterator.hasNext() ) {
199-
City city = iterator.next();
200-
numRead++;
201-
}
202-
assertEquals("Failed to find number of records expected", 21, numRead);
203-
assertEquals("PojoPage failed to report number of records expected", numRead, page.size());
204204
}
205205

206206
@Test
@@ -241,17 +241,16 @@ public void testD_PojosWithChildren() throws Exception {
241241
query = countriesQb.range("continent", Operator.EQ, "AS");
242242
assertEquals("Should find two cities", 2, cities.search(query, 1).getTotalSize());
243243

244-
// the following currently don't work even in the cts:search layer
245-
// all countries containing the term "SA"
246-
query = countriesQb.word("SA");
244+
// all countries containing the term SA
245+
query = countriesQb.containerQuery(countriesQb.term("SA"));
247246
assertEquals("Should find one city", 1, cities.search(query, 1).getTotalSize());
248247

249-
// all cities containing the term "SA"
250-
query = qb.word("SA");
251-
assertEquals("Should find two cities", 2, cities.search(query, 1).getTotalSize());
248+
// all cities containing the term SA
249+
query = qb.containerQuery(qb.term("SA"));
250+
assertEquals("Should find two cities", 61, cities.search(query, 1).getTotalSize());
252251

253252
// all countries containing the field "currencyName" with the term "peso"
254-
query = countriesQb.word("currencyName", new String[]{"peso"});
253+
query = countriesQb.word("currencyName", "peso");
255254
assertEquals("Should find one city", 1, cities.search(query, 1).getTotalSize());
256255
}
257256

0 commit comments

Comments
 (0)