|
52 | 52 | import javax.xml.bind.DatatypeConverter; |
53 | 53 |
|
54 | 54 | import com.marklogic.client.extensions.ResourceServices; |
| 55 | +import com.marklogic.client.query.ElementLocator; |
| 56 | +import com.marklogic.client.query.KeyLocator; |
| 57 | +import com.marklogic.client.query.KeyValueQueryDefinition; |
| 58 | +import com.marklogic.client.query.ValueLocator; |
55 | 59 | import org.apache.http.HttpHost; |
56 | 60 | import org.apache.http.HttpVersion; |
57 | 61 | import org.apache.http.auth.params.AuthPNames; |
@@ -2078,6 +2082,27 @@ void init() { |
2078 | 2082 | builder = (payloadMimetype != null) ? |
2079 | 2083 | webResource.type(payloadMimetype).accept(mimetype) : |
2080 | 2084 | webResource.accept(mimetype); |
| 2085 | + } else if (queryDef instanceof KeyValueQueryDefinition ) { |
| 2086 | + if (logger.isDebugEnabled()) |
| 2087 | + logger.debug("Searching for keys/values"); |
| 2088 | + |
| 2089 | + Map<ValueLocator, String> pairs = ((KeyValueQueryDefinition) queryDef); |
| 2090 | + for (Map.Entry<ValueLocator, String> entry: pairs.entrySet()) { |
| 2091 | + ValueLocator loc = entry.getKey(); |
| 2092 | + if (loc instanceof KeyLocator ) { |
| 2093 | + addEncodedParam(params, "key", ((KeyLocator) loc).getKey()); |
| 2094 | + } else { |
| 2095 | + ElementLocator eloc = (ElementLocator) loc; |
| 2096 | + params.add("element", eloc.getElement().toString()); |
| 2097 | + if (eloc.getAttribute() != null) { |
| 2098 | + params.add("attribute", eloc.getAttribute().toString()); |
| 2099 | + } |
| 2100 | + } |
| 2101 | + addEncodedParam(params, "value", entry.getValue()); |
| 2102 | + } |
| 2103 | + |
| 2104 | + webResource = getConnection().path("keyvalue").queryParams(params); |
| 2105 | + builder = webResource.accept(mimetype); |
2081 | 2106 | } else if (queryDef instanceof CombinedQueryDefinition) { |
2082 | 2107 | structure = ((CombinedQueryDefinition) queryDef).serialize(); |
2083 | 2108 |
|
@@ -2121,7 +2146,9 @@ ClientResponse getResponse() { |
2121 | 2146 | } |
2122 | 2147 | } |
2123 | 2148 |
|
2124 | | - if (queryDef instanceof StructuredQueryDefinition && ! (queryDef instanceof RawQueryDefinition)) { |
| 2149 | + if (queryDef instanceof KeyValueQueryDefinition) { |
| 2150 | + response = doGet(builder); |
| 2151 | + } else if (queryDef instanceof StructuredQueryDefinition && ! (queryDef instanceof RawQueryDefinition)) { |
2125 | 2152 | response = doPost(reqlog, builder, structure, true); |
2126 | 2153 | } else if (queryDef instanceof CombinedQueryDefinition) { |
2127 | 2154 | response = doPost(reqlog, builder, structure, true); |
|
0 commit comments