Class CombinedQueryDefinitionBuilder
- java.lang.Object
-
- com.marklogic.client.impl.AbstractQueryDefinition
-
- io.github.malteseduck.springframework.data.marklogic.repository.query.CombinedQueryDefinitionBuilder
-
- All Implemented Interfaces:
com.marklogic.client.pojo.PojoQueryDefinition
,com.marklogic.client.query.QueryDefinition
,com.marklogic.client.query.StructuredQueryDefinition
,com.marklogic.client.query.ValueQueryDefinition
,CombinedQueryDefinition
public class CombinedQueryDefinitionBuilder extends com.marklogic.client.impl.AbstractQueryDefinition implements CombinedQueryDefinition
Allow us to keep a running build of query/options so we can set them throughout the different processing levels. The CombinedQueryDefinition in the driver library is for a specific purpose and not modifiable, nor is it passable down to the template methods. Since the structure is well-defined as part of MarkLogic's REST API we can create the appropriate combined query from what we have.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CombinedQueryDefinition
and(com.marklogic.client.query.StructuredQueryDefinition... queries)
Combine the current structured queries in the combined query with the specified queries using an "and".CombinedQueryDefinition
byExample(com.marklogic.client.query.RawQueryByExampleDefinition qbe)
Adds a raw Query By Example definition to the current combined query.CombinedQueryDefinition
byExample(com.marklogic.client.query.RawQueryByExampleDefinition qbe, com.marklogic.client.io.Format format)
Adds a raw Query By Example definition to the current combined query.CombinedQueryDefinition
collections(String... collections)
Adds constraints to limit results to only documents contained in one of the specified collections.static CombinedQueryDefinition
combine()
static CombinedQueryDefinition
combine(com.marklogic.client.query.StructuredQueryDefinition query)
CombinedQueryDefinition
context(org.springframework.data.mapping.context.MappingContext mappingContext)
Override the default mapping context to use when building queries.CombinedQueryDefinition
directory(String directory)
Adds contraints to limit results to only documents contained in the specified directory.CombinedQueryDefinition
extracts(List<String> extracts)
Specify which properties of a document will be included/excluded from the results.CombinedQueryDefinition
extracts(List<String> extracts, SelectedMode mode)
Specify which properties of a document will be included/excluded from the results.String
getCriteria()
Class
getEntityClass()
List<String>
getExtracts()
int
getLimit()
Gets the configured limit for the current limit.org.springframework.data.mapping.context.MappingContext<? extends MarkLogicPersistentEntity<?>,MarkLogicPersistentProperty>
getMappingContext()
List<String>
getOptions()
com.marklogic.client.query.RawQueryByExampleDefinition
getQbe()
com.marklogic.client.io.Format
getQbeFormat()
String
getQtext()
com.marklogic.client.query.RawQueryByExampleDefinition
getRawQbe()
Gets the raw Query By Example definition from the combined query.SelectedMode
getSelected()
String
getSparql()
com.marklogic.client.query.StructuredQueryDefinition
getStructuredQuery()
boolean
isLimiting()
Indicates whether or not a limit has been specified on this query.boolean
isQbe()
Indicates whether or not this combined query is a raw Query By Example query.CombinedQueryDefinition
limit(int limit)
Limit the results that come back to the specified number.CombinedQueryDefinition
options(String... options)
Add a snippet of XML query options to the combined query.CombinedQueryDefinition
optionsName(String name)
Sets the query to use persisted options that have the specified name.CombinedQueryDefinition
or(com.marklogic.client.query.StructuredQueryDefinition... queries)
Combine the current structured queries in the combined query with the specified queries using an "or".String
serialize()
Used by the MarkLogic Java Client Library to get the "low-level" representation of the query that can be submitted to the MarkLogic REST API.void
setCriteria(String criteria)
void
setQbe(com.marklogic.client.query.RawQueryByExampleDefinition qbe)
CombinedQueryDefinition
sort(String propertyName, String order, IndexType type)
Adds sorting configuration to the query.CombinedQueryDefinition
sort(org.springframework.data.domain.Sort sort)
Add sorting configuration to the query.CombinedQueryDefinition
sort(org.springframework.data.domain.Sort sort, IndexType type)
Add sorting configuration to the query.CombinedQueryDefinition
sparql(String sparql)
Add SPARQL queries to constraint results to only documents that have the matched triples.CombinedQueryDefinition
term(String qtext)
Add a search term to the current query.CombinedQueryDefinition
transform(com.marklogic.client.document.ServerTransform transform)
Specify a server transform to use on the results that are matched in the database.CombinedQueryDefinition
type(Class entityClass)
Specified the entity type to use when building the query.CombinedQueryDefinition
withCriteria(String criteria)
-
Methods inherited from class com.marklogic.client.impl.AbstractQueryDefinition
getCollections, getDirectory, getOptionsName, getResponseTransform, setCollections, setDirectory, setOptionsName, setResponseTransform
-
-
-
-
Method Detail
-
combine
public static CombinedQueryDefinition combine()
-
combine
public static CombinedQueryDefinition combine(com.marklogic.client.query.StructuredQueryDefinition query)
-
serialize
public String serialize()
Description copied from interface:CombinedQueryDefinition
Used by the MarkLogic Java Client Library to get the "low-level" representation of the query that can be submitted to the MarkLogic REST API.- Specified by:
serialize
in interfaceCombinedQueryDefinition
- Specified by:
serialize
in interfacecom.marklogic.client.query.StructuredQueryDefinition
- Returns:
- JSON/XML string of a combined query.
-
isQbe
public boolean isQbe()
Description copied from interface:CombinedQueryDefinition
Indicates whether or not this combined query is a raw Query By Example query.- Specified by:
isQbe
in interfaceCombinedQueryDefinition
- Returns:
- True if the combined query contains a raw QBE.
-
getRawQbe
public com.marklogic.client.query.RawQueryByExampleDefinition getRawQbe()
Description copied from interface:CombinedQueryDefinition
Gets the raw Query By Example definition from the combined query.- Specified by:
getRawQbe
in interfaceCombinedQueryDefinition
- Returns:
- the raw QBE object.
-
getQbe
public com.marklogic.client.query.RawQueryByExampleDefinition getQbe()
-
setQbe
public void setQbe(com.marklogic.client.query.RawQueryByExampleDefinition qbe)
-
byExample
public CombinedQueryDefinition byExample(com.marklogic.client.query.RawQueryByExampleDefinition qbe)
Description copied from interface:CombinedQueryDefinition
Adds a raw Query By Example definition to the current combined query.- Specified by:
byExample
in interfaceCombinedQueryDefinition
- See Also:
byExample(RawQueryByExampleDefinition, Format)
-
byExample
public CombinedQueryDefinition byExample(com.marklogic.client.query.RawQueryByExampleDefinition qbe, com.marklogic.client.io.Format format)
Description copied from interface:CombinedQueryDefinition
Adds a raw Query By Example definition to the current combined query. This will supercede any structured query that currently exists in the combined query, so use one or the other.- Specified by:
byExample
in interfaceCombinedQueryDefinition
- Parameters:
qbe
- the raw QBE object.format
- Either JSON or XML, using theFormat
enum.- Returns:
- The current query definition for use in continued building.
-
and
public CombinedQueryDefinition and(com.marklogic.client.query.StructuredQueryDefinition... queries)
Description copied from interface:CombinedQueryDefinition
Combine the current structured queries in the combined query with the specified queries using an "and".- Specified by:
and
in interfaceCombinedQueryDefinition
- Parameters:
queries
- Queries to add to the combined query- Returns:
- The current query definition for use in continued building.
-
or
public CombinedQueryDefinition or(com.marklogic.client.query.StructuredQueryDefinition... queries)
Description copied from interface:CombinedQueryDefinition
Combine the current structured queries in the combined query with the specified queries using an "or".- Specified by:
or
in interfaceCombinedQueryDefinition
- Parameters:
queries
- Queries to add to the combined query- Returns:
- The current query definition for use in continued building.
-
collections
public CombinedQueryDefinition collections(String... collections)
Description copied from interface:CombinedQueryDefinition
Adds constraints to limit results to only documents contained in one of the specified collections. This can be called multiple times and the result is additive. By default all documents are in a collection named after the entity class, i.e. a Person entity is stored in a collection with the URI "Person".- Specified by:
collections
in interfaceCombinedQueryDefinition
- Parameters:
collections
- A list of collection URIs- Returns:
- The current query definition for use in continued building.
-
directory
public CombinedQueryDefinition directory(String directory)
Description copied from interface:CombinedQueryDefinition
Adds contraints to limit results to only documents contained in the specified directory. Multiple calls to this function will replace the value of previous calls. By default all documents are stored under a path named after the entity class (to avoid ID clashes, since the database URI is the "true" primary key). So a Person entity is stored under the path "/Person/".- Specified by:
directory
in interfaceCombinedQueryDefinition
- Parameters:
directory
- The directory path under which to limit results.- Returns:
- The current query definition for use in continued building.
-
optionsName
public CombinedQueryDefinition optionsName(String name)
Description copied from interface:CombinedQueryDefinition
Sets the query to use persisted options that have the specified name. If you find you are adding lots of ad-hoc options to your queries or that you are having performance issues because of building them each time you can save those options and reference them in your query. For more information see http://docs.marklogic.com/guide/java/query-options#id_20346.- Specified by:
optionsName
in interfaceCombinedQueryDefinition
- Parameters:
name
- The name of the options as they are saved in the database.- Returns:
- The current query definition for use in continued building.
-
options
public CombinedQueryDefinition options(String... options)
Description copied from interface:CombinedQueryDefinition
Add a snippet of XML query options to the combined query. If you wanted to configure the query to return the metrics of the query you would call the method like so: combinedQuery.options("<return-metrics>true</return-metrics>");- Specified by:
options
in interfaceCombinedQueryDefinition
- Parameters:
options
- Variable number of options XML strings to add to the query.- Returns:
- The current query definition for use in continued building.
-
sort
public CombinedQueryDefinition sort(org.springframework.data.domain.Sort sort)
Description copied from interface:CombinedQueryDefinition
Add sorting configuration to the query. The default sort algorithm will expect to use a path range index, i.e. if sorting on "name" then a path index of "/name" should exist. Through use of theIndexed
annotation you can indicate use of a different type of range index for the property sorting, or specify the full path that should be used in creation of the sort options. This requires thatCombinedQueryDefinition.type(Class)
be called first to specify the entity type.- Specified by:
sort
in interfaceCombinedQueryDefinition
- Parameters:
sort
- Sort information for the query, i.e. which properties and which orders.- Returns:
- The current query definition for use in continued building.
-
sort
public CombinedQueryDefinition sort(org.springframework.data.domain.Sort sort, IndexType type)
Description copied from interface:CombinedQueryDefinition
Add sorting configuration to the query. The type that is specified will be used on all sort properties specified in theSort
object, and the assumption will be that how they are specified in that object is exactly how the index is defined in the configuration. For example, if you have a sort property of "name" and you specify the type of IndexType.PATH then you would need a path range index defined for "name". If the property is "/pets/name" with the same index type then a path range index would need to be defined for "/pets/name". Usually it is better to be consistent in how you define your indexes (i.e. use either path range or element (property) range indexes) so that the same type of index can be configured for many properties in a sort.- Specified by:
sort
in interfaceCombinedQueryDefinition
- Parameters:
sort
- Sort information for the query, i.e. which properties and which orders.type
- The type of index that is configured for the properties. Used to create the correct options in the combined query.- Returns:
- The current query definition for use in continued building.
-
sort
public CombinedQueryDefinition sort(String propertyName, String order, IndexType type)
Description copied from interface:CombinedQueryDefinition
Adds sorting configuration to the query. This is the most fine-grained control of sort index configuration - you can specify details for each property. The downside would be typically you would have to iterate over aSort
yourself and perform logic to determine index type yourself.- Specified by:
sort
in interfaceCombinedQueryDefinition
- Parameters:
propertyName
- The name of the property, or path, or whatever (depending on index type used)order
- The order, either "descending" or "ascending"type
- The type of index that is configured for the properties. Used to create the correct options in the combined query.- Returns:
- The current query definition for use in continued building.
-
extracts
public CombinedQueryDefinition extracts(List<String> extracts)
Description copied from interface:CombinedQueryDefinition
Specify which properties of a document will be included/excluded from the results.- Specified by:
extracts
in interfaceCombinedQueryDefinition
- See Also:
CombinedQueryDefinition.extracts(List, SelectedMode)
-
extracts
public CombinedQueryDefinition extracts(List<String> extracts, SelectedMode mode)
Description copied from interface:CombinedQueryDefinition
Specify which properties of a document will be included/excluded from the results. The default is for the entire document to be returned. Ideally you keep the mode asSelectedMode.HIERARCHICAL
so that your entities will be de-serialized correctly. If you create a custom entity to handle the results of just the properties flattened out then you can just use theSelectedMode.INCLUDE
. For more information see http://docs.marklogic.com/guide/java/searches#id_90087.- Specified by:
extracts
in interfaceCombinedQueryDefinition
- Parameters:
extracts
- A list of XPaths that describe which properties in a document to include/excludemode
- Specify whether to include or exclude the specified properties.- Returns:
- The current query definition for use in continued building.
-
limit
public CombinedQueryDefinition limit(int limit)
Description copied from interface:CombinedQueryDefinition
Limit the results that come back to the specified number. For configuring paging of the queries it is usually better to just specify your bounds inMarkLogicOperations.search(StructuredQueryDefinition, long, int, Class)
.- Specified by:
limit
in interfaceCombinedQueryDefinition
- Parameters:
limit
- Limit the results to this number of records.- Returns:
- The current query definition for use in continued building.
-
transform
public CombinedQueryDefinition transform(com.marklogic.client.document.ServerTransform transform)
Description copied from interface:CombinedQueryDefinition
Specify a server transform to use on the results that are matched in the database. This server transform will be applied to each document before the set is returned from the database, so for complicated transformation logic this could be more efficient than trying to do it in the Java layer. For more information see http://docs.marklogic.com/guide/java/transforms.- Specified by:
transform
in interfaceCombinedQueryDefinition
- Returns:
- The current query definition for use in continued building.
-
isLimiting
public boolean isLimiting()
Description copied from interface:CombinedQueryDefinition
Indicates whether or not a limit has been specified on this query.- Specified by:
isLimiting
in interfaceCombinedQueryDefinition
- Returns:
- True if the query is limiting.
-
getLimit
public int getLimit()
Description copied from interface:CombinedQueryDefinition
Gets the configured limit for the current limit.- Specified by:
getLimit
in interfaceCombinedQueryDefinition
- Returns:
- The limit, or -1 if not set.
-
term
public CombinedQueryDefinition term(String qtext)
Description copied from interface:CombinedQueryDefinition
Add a search term to the current query. This is used for word searches across your entire document. For more fine-grained control useStructuredQueryBuilder.word(StructuredQueryBuilder.TextIndex, String...)
to specify specific properties or fields into which to scope the word search.- Specified by:
term
in interfaceCombinedQueryDefinition
- Parameters:
qtext
- A search phrase.- Returns:
- The current query definition for use in continued building.
-
sparql
public CombinedQueryDefinition sparql(String sparql)
Description copied from interface:CombinedQueryDefinition
Add SPARQL queries to constraint results to only documents that have the matched triples.- Specified by:
sparql
in interfaceCombinedQueryDefinition
- Parameters:
sparql
- The SPARQL query.- Returns:
- The current query definition for use in continued building.
-
type
public CombinedQueryDefinition type(Class entityClass)
Description copied from interface:CombinedQueryDefinition
Specified the entity type to use when building the query. There are various annotations that can be used on your entity classes. If you want those to be used in making decisions on how to build certain options then make sure to use this to "add" it to the query. If not specified then the defaults will always be used.- Specified by:
type
in interfaceCombinedQueryDefinition
- Parameters:
entityClass
- The type of the entity.- Returns:
- The current query definition for use in continued building.
-
context
public CombinedQueryDefinition context(org.springframework.data.mapping.context.MappingContext mappingContext)
Description copied from interface:CombinedQueryDefinition
Override the default mapping context to use when building queries.- Specified by:
context
in interfaceCombinedQueryDefinition
- Parameters:
mappingContext
- A mapping context that maps entity information for methods that specify entity types.- Returns:
- The current query definition for use in continued building.
-
getCriteria
public String getCriteria()
- Specified by:
getCriteria
in interfacecom.marklogic.client.query.StructuredQueryDefinition
-
setCriteria
public void setCriteria(String criteria)
- Specified by:
setCriteria
in interfacecom.marklogic.client.query.StructuredQueryDefinition
-
withCriteria
public CombinedQueryDefinition withCriteria(String criteria)
- Specified by:
withCriteria
in interfacecom.marklogic.client.query.StructuredQueryDefinition
-
getQbeFormat
public com.marklogic.client.io.Format getQbeFormat()
-
getStructuredQuery
public com.marklogic.client.query.StructuredQueryDefinition getStructuredQuery()
-
getQtext
public String getQtext()
-
getSparql
public String getSparql()
-
getSelected
public SelectedMode getSelected()
-
getEntityClass
public Class getEntityClass()
-
getMappingContext
public org.springframework.data.mapping.context.MappingContext<? extends MarkLogicPersistentEntity<?>,MarkLogicPersistentProperty> getMappingContext()
-
-