Skip to content

Commit caa3dd9

Browse files
author
ehennum
committed
use JSON serialization only without namespaces #1283
1 parent cf9de17 commit caa3dd9

File tree

8 files changed

+41
-6
lines changed

8 files changed

+41
-6
lines changed

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/impl/QueryBatcherImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
import com.marklogic.client.datamovement.QueryBatchException;
2828
import com.marklogic.client.datamovement.QueryEvent;
2929
import com.marklogic.client.datamovement.QueryBatcherListener;
30-
import com.marklogic.client.impl.HandleAccessor;
31-
import com.marklogic.client.impl.HandleImplementation;
30+
import com.marklogic.client.impl.*;
3231
import com.marklogic.client.io.Format;
3332
import com.marklogic.client.io.StringHandle;
3433
import com.marklogic.client.io.marker.StructureWriteHandle;
@@ -39,8 +38,6 @@
3938

4039
import com.marklogic.client.DatabaseClient;
4140
import com.marklogic.client.ResourceNotFoundException;
42-
import com.marklogic.client.impl.QueryManagerImpl;
43-
import com.marklogic.client.impl.UrisHandle;
4441

4542
import java.util.*;
4643
import java.util.concurrent.LinkedBlockingQueue;
@@ -93,8 +90,11 @@ public class QueryBatcherImpl extends BatcherImpl implements QueryBatcher {
9390
String serializedCtsQuery, Boolean filtered, int maxDocToUriBatchRatio, int defaultDocBatchSize, int maxUriBatchSize
9491
) {
9592
this(moveMgr, forestConfig, maxDocToUriBatchRatio, defaultDocBatchSize, maxUriBatchSize);
96-
QueryManagerImpl queryMgr = (QueryManagerImpl) getPrimaryClient().newQueryManager();
97-
if (serializedCtsQuery != null && serializedCtsQuery.length() > 0) {
93+
// TODO: skip conversion in DataMovementManagerImpl.newQueryBatcherImpl() unless canSerializeQueryAsJSON()
94+
if (serializedCtsQuery != null && serializedCtsQuery.length() > 0 &&
95+
originalQuery instanceof AbstractSearchQueryDefinition &&
96+
((AbstractSearchQueryDefinition) originalQuery).canSerializeQueryAsJSON()) {
97+
QueryManagerImpl queryMgr = (QueryManagerImpl) getPrimaryClient().newQueryManager();
9898
this.queryMethod = "POST";
9999
this.query = queryMgr.newRawCtsQueryDefinition(new StringHandle(serializedCtsQuery).withFormat(Format.JSON));
100100
this.originalQuery = originalQuery;

marklogic-client-api/src/main/java/com/marklogic/client/impl/AbstractSearchQueryDefinition.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ public ServerTransform getResponseTransform() {
4141
public void setResponseTransform(ServerTransform transform) {
4242
this.transform = transform;
4343
}
44+
45+
public abstract boolean canSerializeQueryAsJSON();
4446
}

marklogic-client-api/src/main/java/com/marklogic/client/impl/CombinedQueryBuilderImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ public Format getFormat() {
111111
return format;
112112
}
113113

114+
@Override
115+
public boolean canSerializeQueryAsJSON() {
116+
return getFormat() == Format.JSON && getOptionsName() == null;
117+
}
114118
}
115119

116120
@Override

marklogic-client-api/src/main/java/com/marklogic/client/impl/CtsQueryDefinitionImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ public String serialize() {
4848
str.append("}}");
4949
return str.toString();
5050
}
51+
52+
@Override
53+
public boolean canSerializeQueryAsJSON() {
54+
return getOptionsName() == null;
55+
}
5156
}

marklogic-client-api/src/main/java/com/marklogic/client/impl/DeleteQueryDefinitionImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ public ServerTransform getResponseTransform() {
3939
public void setResponseTransform(ServerTransform transform) {
4040
throw new UnsupportedOperationException("A server transform has no meaning on a DeleteQueryDefinition");
4141
}
42+
43+
@Override
44+
public boolean canSerializeQueryAsJSON() {
45+
return true;
46+
}
4247
}

marklogic-client-api/src/main/java/com/marklogic/client/impl/RawQueryDefinitionImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.marklogic.client.impl;
1717

18+
import com.marklogic.client.io.Format;
1819
import com.marklogic.client.io.marker.CtsQueryWriteHandle;
1920
import com.marklogic.client.io.marker.StructureWriteHandle;
2021
import com.marklogic.client.query.RawCombinedQueryDefinition;
@@ -176,4 +177,12 @@ public String toString() {
176177
}
177178
return handle.toString();
178179
}
180+
181+
@Override
182+
public boolean canSerializeQueryAsJSON() {
183+
StructureWriteHandle handle = getHandle();
184+
if (handle == null) return false;
185+
return HandleAccessor.checkHandle(handle, "raw query").getFormat() == Format.JSON &&
186+
getOptionsName() == null;
187+
}
179188
}

marklogic-client-api/src/main/java/com/marklogic/client/impl/StringQueryDefinitionImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ public StringQueryDefinition withCriteria(String criteria) {
3939
setCriteria(criteria);
4040
return this;
4141
}
42+
43+
@Override
44+
public boolean canSerializeQueryAsJSON() {
45+
return getOptionsName() == null;
46+
}
4247
}

marklogic-client-api/src/main/java/com/marklogic/client/query/StructuredQueryBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,11 @@ public String serialize() {
12371237
}
12381238

12391239
public abstract void innerSerialize(XMLStreamWriter serializer) throws XMLStreamException;
1240+
1241+
@Override
1242+
public boolean canSerializeQueryAsJSON() {
1243+
return StructuredQueryBuilder.this.getNamespaces() == null && getOptionsName() == null;
1244+
}
12401245
}
12411246

12421247
protected class AndQuery

0 commit comments

Comments
 (0)