Class MarkLogicTemplate
- java.lang.Object
-
- io.github.malteseduck.springframework.data.marklogic.core.MarkLogicTemplate
-
- All Implemented Interfaces:
MarkLogicOperations
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
public class MarkLogicTemplate extends Object implements MarkLogicOperations, org.springframework.context.ApplicationContextAware
-
-
Constructor Summary
Constructors Constructor Description MarkLogicTemplate(com.marklogic.client.DatabaseClient client)
Create a template interface using the specified database client and the default entity converter and query conversion service.MarkLogicTemplate(com.marklogic.client.DatabaseClient client, MarkLogicConverter converter)
Create a template interface using the specified database client and the default query conversion service.MarkLogicTemplate(com.marklogic.client.DatabaseClient client, MarkLogicConverter converter, QueryConversionService queryConversionService)
Create a template interface using the specified database client.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(org.springframework.core.io.Resource configuration)
Configures the connected database using the specified JSON information.long
count(com.marklogic.client.query.StructuredQueryDefinition query)
Gives a count of the number of documents that would match the specified query.<T> long
count(com.marklogic.client.query.StructuredQueryDefinition query, Class<T> entityClass)
Count the number of entities that would match the specified query.<T> long
count(Class<T> entityClass)
Count the number of the specified entity that exist in the database.long
count(String... collections)
Count the number of documents that exist in the database under the specified collections.<T> void
delete(com.marklogic.client.query.StructuredQueryDefinition query, Class<T> entityClass)
Delete entities of the specified type that match the specified query.<T> void
delete(List<T> entities)
Delete the specified entities from the database.<T> void
deleteById(Object id, Class<T> entityClass)
Deletes the entity with the specified ID.<T> void
deleteByIds(List<?> ids, Class<T> entityClass)
Deletes the entities which have one of the specified IDs.void
deleteByUri(String... uris)
Delete a document from the database that is stored under the specified urisvoid
deleteByUris(List<String> uris)
Delete a set of documents from the database that are stored under one of the specified URIs<T> void
dropCollection(Class<T> entityClass)
Deletes all the entities of the specified type.<T> void
dropCollections(Class<T>... entityClasses)
Deletes all the entities of the specified types.void
dropCollections(String... collections)
Delete documents that are under the specified collection URIs.<T> T
execute(DocumentCallback<T> action)
Executes the specified action using aGenericDocumentManager
interface.<T> T
executeQuery(QueryCallback<T> action)
Executes the specified action using aQueryManager
.<T> T
executeWithClient(ClientCallback<T> action)
Executes the specified action using the fullDatabaseClient
.<T> boolean
exists(com.marklogic.client.query.StructuredQueryDefinition query, Class<T> entityClass)
Check for existence of entities matching the specified structured query.<T> boolean
exists(Object id, Class<T> entityClass)
Check for existence of an entity in the database by using it's ID.boolean
exists(String uri)
Check for existence of a document by using the full URI under which the document is stored.<T> FacetedPage<T>
facetedSearch(com.marklogic.client.query.StructuredQueryDefinition query, long start, int limit, Class<T> entityClass)
Similar to a normal paged query, except also includes facets for the matched results.<T> FacetedPage<T>
facetedSearch(com.marklogic.client.query.StructuredQueryDefinition query, long start, Class<T> entityClass)
<T> FacetedPage<T>
facetedSearch(com.marklogic.client.query.StructuredQueryDefinition query, org.springframework.data.domain.Pageable pageable, Class<T> entityClass)
Same as faceted search with int bounds, but allows paging/sorting based off Spring Pageable.MarkLogicConverter
getConverter()
Get the entity converter that is used to convert Java POJOs into a form with which they can be stored in the database.QueryConversionService
getQueryConversionService()
Get the query object convert service that is used to convert various Java types into their "correct" form for querying in MarkLogic.QueryMapper
getQueryMapper()
The query mapper is responsible for interpreting entity/query annotations and applying the information to a query before it is executed in MarkLogicTemplate.<T> com.marklogic.client.pojo.PojoQueryBuilder<T>
qb(Class<T> entityClass)
Get an instance of aPojoQueryBuilder
for the specified entity class.<T> T
read(Object id, Class<T> entityClass)
Read a document with the specified ID from the database.List<com.marklogic.client.document.DocumentRecord>
read(List<?> uris)
Reads a list of documents from the database by their URIs instead of ids.<T> List<T>
read(List<?> ids, Class<T> entityClass)
Reads a set of documents that have the specified IDs.List<com.marklogic.client.document.DocumentRecord>
search(com.marklogic.client.query.StructuredQueryDefinition query)
Query for a list of documents using the specified structured query.com.marklogic.client.document.DocumentPage
search(com.marklogic.client.query.StructuredQueryDefinition query, long start)
Query for a page of documents using the specified structured query, starting at the specified item in the result set.com.marklogic.client.document.DocumentPage
search(com.marklogic.client.query.StructuredQueryDefinition query, long start, int length)
Query for a page of documents using the specified structured query.<T> org.springframework.data.domain.Page<T>
search(com.marklogic.client.query.StructuredQueryDefinition query, long start, int limit, Class<T> entityClass)
Queries for a page of documents of the specified type, using the specified structured query to constrain which documents are returned.<T> org.springframework.data.domain.Page<T>
search(com.marklogic.client.query.StructuredQueryDefinition query, long start, Class<T> entityClass)
Query for a page of of documents of the specified type using the specified structured query.<T> List<T>
search(com.marklogic.client.query.StructuredQueryDefinition query, Class<T> entityClass)
Query for a list of of documents of the specified type using the specified structured query.com.marklogic.client.document.DocumentPage
search(com.marklogic.client.query.StructuredQueryDefinition query, org.springframework.data.domain.Pageable pageable)
Same as search with int bounds, but allows paging/sorting based off Spring Pageable.<T> org.springframework.data.domain.Page<T>
search(com.marklogic.client.query.StructuredQueryDefinition query, org.springframework.data.domain.Pageable pageable, Class<T> entityClass)
Same as search with int bounds, but allows paging/sorting based off Spring Pageable.<T> List<T>
search(Class<T> entityClass)
Query for a list of of documents of the specified type.<T> T
searchOne(com.marklogic.client.query.StructuredQueryDefinition query, Class<T> entityClass)
Query for a single entity using the specified structured query.void
setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
com.marklogic.client.query.StructuredQueryDefinition
sortQuery(org.springframework.data.domain.Sort sort, com.marklogic.client.query.StructuredQueryDefinition query)
Adds sorting configuration to the specified query.<T> com.marklogic.client.query.StructuredQueryDefinition
sortQuery(org.springframework.data.domain.Sort sort, com.marklogic.client.query.StructuredQueryDefinition query, Class<T> entityClass)
Add sorting configuration to the specified query.InputStream
stream(com.marklogic.client.query.StructuredQueryDefinition query)
InputStream
stream(com.marklogic.client.query.StructuredQueryDefinition query, long start)
InputStream
stream(com.marklogic.client.query.StructuredQueryDefinition query, long start, int length)
<T> InputStream
stream(com.marklogic.client.query.StructuredQueryDefinition query, long start, int length, Class<T> entityClass)
Queries just like theMarkLogicOperations.search(StructuredQueryDefinition, long, int, Class)
method does, but instead of a page/list of documents it returns an input stream straight from the results of the REST call against the database.<T> InputStream
stream(com.marklogic.client.query.StructuredQueryDefinition query, long start, Class<T> entityClass)
<T> InputStream
stream(com.marklogic.client.query.StructuredQueryDefinition query, Class<T> entityClass)
InputStream
stream(com.marklogic.client.query.StructuredQueryDefinition query, org.springframework.data.domain.Pageable pageable)
Same as method taking int bounds, but allows use of Pagable for paging/sorting.<T> InputStream
stream(com.marklogic.client.query.StructuredQueryDefinition query, org.springframework.data.domain.Pageable pageable, Class<T> entityClass)
Same as method taking int bounds, but allows use of Pagable for paging/sorting.com.marklogic.client.query.StructuredQueryDefinition
termQuery(String term, com.marklogic.client.query.StructuredQueryDefinition query)
Add a search term to the specified query.protected <T> List<T>
toEntityList(Class<T> entityClass, com.marklogic.client.document.DocumentPage page)
protected List<com.marklogic.client.document.DocumentRecord>
toRecordList(com.marklogic.client.document.DocumentPage page)
<T> List<T>
write(List<T> entities)
Write the specified entities to the database into the default entity collection, without any transforms<T> List<T>
write(List<T> entities, com.marklogic.client.document.ServerTransform transform)
Write the specified entities to the database into the default entity collection using the specified transform.<T> List<T>
write(List<T> entities, com.marklogic.client.document.ServerTransform transform, String... collections)
Write the specified list of entities to the database.<T> List<T>
write(List<T> entities, String... collections)
Write the specified entities to the database into the specified collections, without any transforms.<T> T
write(T entity)
Write a single entity to the database into the default entity collection without any transforms.<T> T
write(T entity, com.marklogic.client.document.ServerTransform transform)
Write the specified entity to the database into the default entity collection using the specified transform.<T> T
write(T entity, com.marklogic.client.document.ServerTransform transform, String... collections)
Write the specified entity to the database into the specified collections with the specified transform.<T> T
write(T entity, String... collections)
Write a single entity to the database into the specified collections, without any transforms.
-
-
-
Constructor Detail
-
MarkLogicTemplate
public MarkLogicTemplate(com.marklogic.client.DatabaseClient client)
Create a template interface using the specified database client and the default entity converter and query conversion service.- Parameters:
client
- The MarkLogic database client created from @seeDatabaseClientFactory
-
MarkLogicTemplate
public MarkLogicTemplate(com.marklogic.client.DatabaseClient client, MarkLogicConverter converter)
Create a template interface using the specified database client and the default query conversion service.- Parameters:
client
- The MarkLogic database client created from DatabaseClientFactory.converter
- A custom entity converter.
-
MarkLogicTemplate
public MarkLogicTemplate(com.marklogic.client.DatabaseClient client, MarkLogicConverter converter, QueryConversionService queryConversionService)
Create a template interface using the specified database client. Also provide a custom convert that handles the translation of entities between Java and MarkLogic. You can also provide a custom query conversion service that will handle the conversion of different types used in finder queries and @Query queries.- Parameters:
client
- The MarkLogic database client created from @seeDatabaseClientFactory
.converter
- A custom entity converter.queryConversionService
- A custom query object conversion service.
-
-
Method Detail
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
- Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
execute
public <T> T execute(DocumentCallback<T> action)
Description copied from interface:MarkLogicOperations
Executes the specified action using aGenericDocumentManager
interface. For all the basic operations this is sufficient.- Specified by:
execute
in interfaceMarkLogicOperations
- Type Parameters:
T
- The result type of the function.- Parameters:
action
- A function to execute using the document manager. The active transaction is also provided so that the function can add additional operations to it.- Returns:
- The results of the document manager interactions (results of a query, etc.).
-
executeWithClient
public <T> T executeWithClient(ClientCallback<T> action)
Description copied from interface:MarkLogicOperations
Executes the specified action using the fullDatabaseClient
. This gives you full control of your interactions with the database with the full power of the MarkLogic Java Client Library, but it also requires you to do a lot of the busy work yourself. Should mainly be used for operations not supported currently in this template interface either through the helper methods, aGenericDocumentManager
, or aQueryManager
.- Specified by:
executeWithClient
in interfaceMarkLogicOperations
- Type Parameters:
T
- The result type of the function.- Parameters:
action
- A function to execute using the database client and active transaction.- Returns:
- The results of the function.
-
executeQuery
public <T> T executeQuery(QueryCallback<T> action)
Description copied from interface:MarkLogicOperations
Executes the specified action using aQueryManager
.- Specified by:
executeQuery
in interfaceMarkLogicOperations
- Type Parameters:
T
- The result type of the function.- Parameters:
action
- A function to execute using the query manager and active transaction.- Returns:
- The results from the query manager.
-
qb
public <T> com.marklogic.client.pojo.PojoQueryBuilder<T> qb(Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Get an instance of aPojoQueryBuilder
for the specified entity class. This is a simplified interface for building structured queries against JSON objects in the database. For full control of all query options use theStructuredQueryBuilder
instead.- Specified by:
qb
in interfaceMarkLogicOperations
- Type Parameters:
T
- The type of the entity.- Parameters:
entityClass
- Type of Java entity being stored in the database.- Returns:
-
sortQuery
public com.marklogic.client.query.StructuredQueryDefinition sortQuery(org.springframework.data.domain.Sort sort, com.marklogic.client.query.StructuredQueryDefinition query)
Description copied from interface:MarkLogicOperations
Adds sorting configuration to the specified query.- Specified by:
sortQuery
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.sortQuery(Sort, StructuredQueryDefinition, Class)
-
sortQuery
public <T> com.marklogic.client.query.StructuredQueryDefinition sortQuery(org.springframework.data.domain.Sort sort, com.marklogic.client.query.StructuredQueryDefinition query, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Add sorting configuration to the specified query. The default sort algorithm will expect to use a path range index with specified sort properties, 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 that the entity type is specified.- Specified by:
sortQuery
in interfaceMarkLogicOperations
- Parameters:
sort
- Sort information for the query, i.e. which properties and which orders.query
- The structured query to "enhance".entityClass
- The entity type.- Returns:
- The "enhanced" query definition for use in continued building.
-
termQuery
public com.marklogic.client.query.StructuredQueryDefinition termQuery(String term, com.marklogic.client.query.StructuredQueryDefinition query)
Description copied from interface:MarkLogicOperations
Add a search term to the specified 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:
termQuery
in interfaceMarkLogicOperations
- Parameters:
term
- A search phrase.query
- The structured query to "enhance".- Returns:
- The "enhanced" query definition for use in continued building.
-
configure
public void configure(org.springframework.core.io.Resource configuration) throws IOException
Description copied from interface:MarkLogicOperations
Configures the connected database using the specified JSON information. The format of the JSON is outlined at http://docs.marklogic.com/REST/PUT/manage/v2/databases/[id-or-name]/properties. This requires that the client was created with a user that has "admin" privileges.- Specified by:
configure
in interfaceMarkLogicOperations
- Parameters:
configuration
- Resource pointing to a JSON document containing database configuration information.- Throws:
IOException
-
write
public <T> T write(T entity)
Description copied from interface:MarkLogicOperations
Write a single entity to the database into the default entity collection without any transforms.- Specified by:
write
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.write(List, ServerTransform, String...)
-
write
public <T> T write(T entity, String... collections)
Description copied from interface:MarkLogicOperations
Write a single entity to the database into the specified collections, without any transforms.- Specified by:
write
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.write(List, ServerTransform, String...)
-
write
public <T> T write(T entity, @Nullable com.marklogic.client.document.ServerTransform transform)
Description copied from interface:MarkLogicOperations
Write the specified entity to the database into the default entity collection using the specified transform.- Specified by:
write
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.write(List, ServerTransform, String...)
-
write
public <T> T write(T entity, @Nullable com.marklogic.client.document.ServerTransform transform, String... collections)
Description copied from interface:MarkLogicOperations
Write the specified entity to the database into the specified collections with the specified transform.- Specified by:
write
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.write(List, ServerTransform, String...)
-
write
public <T> List<T> write(List<T> entities)
Description copied from interface:MarkLogicOperations
Write the specified entities to the database into the default entity collection, without any transforms- Specified by:
write
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.write(List, ServerTransform, String...)
-
write
public <T> List<T> write(List<T> entities, String... collections)
Description copied from interface:MarkLogicOperations
Write the specified entities to the database into the specified collections, without any transforms.- Specified by:
write
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.write(List, ServerTransform, String...)
-
write
public <T> List<T> write(List<T> entities, @Nullable com.marklogic.client.document.ServerTransform transform)
Description copied from interface:MarkLogicOperations
Write the specified entities to the database into the default entity collection using the specified transform.- Specified by:
write
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.write(List, ServerTransform, String...)
-
write
public <T> List<T> write(List<T> entities, @Nullable com.marklogic.client.document.ServerTransform transform, String... collections)
Description copied from interface:MarkLogicOperations
Write the specified list of entities to the database. Using theDocument
annotation you can specify some information as to how it is persisted (i.e. whether or not to store it in a "type" collection, what path, etc.). If a transform is specified then before the entity is saved into the database they transform will be run against each entity. For more information see http://docs.marklogic.com/guide/java/transforms.- Specified by:
write
in interfaceMarkLogicOperations
- Type Parameters:
T
- The type of entity- Parameters:
entities
- A list of POJO entities you wish to save into the database.transform
- The transform to use before finally persisting to the database.collections
- Additional collections to which you want the document to be a part of inside the database.- Returns:
- The list of entities that were saved to the database. This is mainly for convenience as they are not modified through this process.
-
read
public <T> T read(Object id, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Read a document with the specified ID from the database.- Specified by:
read
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.read(List, Class)
-
read
public List<com.marklogic.client.document.DocumentRecord> read(List<?> uris)
Description copied from interface:MarkLogicOperations
Reads a list of documents from the database by their URIs instead of ids. Since type information is not know a "raw"DocumentRecord
is returned, and can be handled as desired.- Specified by:
read
in interfaceMarkLogicOperations
- Parameters:
uris
- A list of database URIs of documents.- Returns:
- A list of
DocumentRecord
objects from the database.
-
read
public <T> List<T> read(List<?> ids, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Reads a set of documents that have the specified IDs. The documents must match the specified type or they will not be included in the result set.- Specified by:
read
in interfaceMarkLogicOperations
- Type Parameters:
T
- The type of the entity.- Parameters:
ids
- A list of IDs of entities.entityClass
- The Java type of the entity.- Returns:
- A list of all the entities that matched the specified IDs.
-
search
public List<com.marklogic.client.document.DocumentRecord> search(com.marklogic.client.query.StructuredQueryDefinition query)
Description copied from interface:MarkLogicOperations
Query for a list of documents using the specified structured query.- Specified by:
search
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.search(StructuredQueryDefinition, long, int)
-
search
public <T> List<T> search(com.marklogic.client.query.StructuredQueryDefinition query, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Query for a list of of documents of the specified type using the specified structured query. Only the firstDocumentManagerImpl.DEFAULT_PAGE_LENGTH
documents are returned.- Specified by:
search
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.search(StructuredQueryDefinition, long, int, Class)
-
searchOne
public <T> T searchOne(com.marklogic.client.query.StructuredQueryDefinition query, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Query for a single entity using the specified structured query. If for some reason multiple results are matched then only the first is returned. This is a convenience method to get a single item when you "know" that is all there is.- Specified by:
searchOne
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.search(StructuredQueryDefinition, long, int, Class)
-
search
public <T> List<T> search(Class<T> entityClass)
Query for a list of of documents of the specified type. As this returns all the documents for the type it can potentially take a long time to resolve pulling all of them back from the database. The query will be fast, but transmitting all the records could time out if the result set is sufficiently large. It is recommended that you page your results. This method is mainly created to accommodate creating an implementation for theCrudRepository.findAll()
method.- Specified by:
search
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.search(StructuredQueryDefinition, long, int, Class)
-
search
public com.marklogic.client.document.DocumentPage search(com.marklogic.client.query.StructuredQueryDefinition query, long start)
Description copied from interface:MarkLogicOperations
Query for a page of documents using the specified structured query, starting at the specified item in the result set.- Specified by:
search
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.search(StructuredQueryDefinition, long, int)
-
search
public <T> org.springframework.data.domain.Page<T> search(com.marklogic.client.query.StructuredQueryDefinition query, long start, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Query for a page of of documents of the specified type using the specified structured query. Only a page of documents is returned, starting from the specified start index and containingDocumentManagerImpl.DEFAULT_PAGE_LENGTH
entities.- Specified by:
search
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.search(StructuredQueryDefinition, long, int, Class)
-
search
public com.marklogic.client.document.DocumentPage search(com.marklogic.client.query.StructuredQueryDefinition query, long start, int length)
Description copied from interface:MarkLogicOperations
Query for a page of documents using the specified structured query. Specify a start and length to get different "chunks" of data in the result set from the database. You seldom want to return all results, as this could be a very large number and will degrade the performance of your application. You instead should query out "pages" of data as needed.- Specified by:
search
in interfaceMarkLogicOperations
- Parameters:
query
- A structured query defining the constraints to use to match the desired documents.start
- The start index within the result set that acts as the start of the "page".length
- The number of items to include in the "page"- Returns:
- A
DocumentPage
containing the records for this "chunk" of the result set.
-
search
public com.marklogic.client.document.DocumentPage search(com.marklogic.client.query.StructuredQueryDefinition query, org.springframework.data.domain.Pageable pageable)
Description copied from interface:MarkLogicOperations
Same as search with int bounds, but allows paging/sorting based off Spring Pageable.- Specified by:
search
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.search(StructuredQueryDefinition, long, int, Class)
-
search
public <T> org.springframework.data.domain.Page<T> search(com.marklogic.client.query.StructuredQueryDefinition query, long start, int limit, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Queries for a page of documents of the specified type, using the specified structured query to constrain which documents are returned. Only a page is returned, starting from the specified index and containing the specified number of entries.- Specified by:
search
in interfaceMarkLogicOperations
- Type Parameters:
T
- The type of entity.- Parameters:
query
- The structured query to use to match documents in the database.start
- The starting index within the result set of matches.limit
- The number of documents to return.entityClass
- The entity type class.- Returns:
- A page of documents matching the specified parameters.
-
search
public <T> org.springframework.data.domain.Page<T> search(com.marklogic.client.query.StructuredQueryDefinition query, org.springframework.data.domain.Pageable pageable, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Same as search with int bounds, but allows paging/sorting based off Spring Pageable.- Specified by:
search
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.search(StructuredQueryDefinition, long, int, Class)
-
facetedSearch
public <T> FacetedPage<T> facetedSearch(com.marklogic.client.query.StructuredQueryDefinition query, long start, Class<T> entityClass)
- Specified by:
facetedSearch
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.facetedSearch(StructuredQueryDefinition, long, int, Class)
-
facetedSearch
public <T> FacetedPage<T> facetedSearch(com.marklogic.client.query.StructuredQueryDefinition query, long start, int limit, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Similar to a normal paged query, except also includes facets for the matched results. In order for the facets to be generated you need to ensure the specified query has the name of persisted options that describe the facets, or the query is aCombinedQueryDefinition
that includes the ad-hoc options definitions for them.- Specified by:
facetedSearch
in interfaceMarkLogicOperations
- Type Parameters:
T
- The type of entity.- Parameters:
query
- The structured query to use to match documents in the database.start
- The starting index within the result set of matches.limit
- The number of documents to return.entityClass
- The entity type class.- Returns:
- A page of documents matching the specified parameters with the included facets.
-
facetedSearch
public <T> FacetedPage<T> facetedSearch(com.marklogic.client.query.StructuredQueryDefinition query, org.springframework.data.domain.Pageable pageable, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Same as faceted search with int bounds, but allows paging/sorting based off Spring Pageable.- Specified by:
facetedSearch
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.search(StructuredQueryDefinition, long, int, Class)
-
stream
public InputStream stream(com.marklogic.client.query.StructuredQueryDefinition query)
- Specified by:
stream
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.stream(StructuredQueryDefinition, long, int, Class)
-
stream
public <T> InputStream stream(com.marklogic.client.query.StructuredQueryDefinition query, Class<T> entityClass)
- Specified by:
stream
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.stream(StructuredQueryDefinition, long, int, Class)
-
stream
public InputStream stream(com.marklogic.client.query.StructuredQueryDefinition query, long start)
- Specified by:
stream
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.stream(StructuredQueryDefinition, long, int, Class)
-
stream
public <T> InputStream stream(com.marklogic.client.query.StructuredQueryDefinition query, long start, Class<T> entityClass)
- Specified by:
stream
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.stream(StructuredQueryDefinition, long, int, Class)
-
stream
public InputStream stream(com.marklogic.client.query.StructuredQueryDefinition query, long start, int length)
- Specified by:
stream
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.stream(StructuredQueryDefinition, long, int, Class)
-
stream
public InputStream stream(com.marklogic.client.query.StructuredQueryDefinition query, org.springframework.data.domain.Pageable pageable)
Description copied from interface:MarkLogicOperations
Same as method taking int bounds, but allows use of Pagable for paging/sorting.- Specified by:
stream
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.stream(StructuredQueryDefinition, long, int, Class)
-
stream
public <T> InputStream stream(com.marklogic.client.query.StructuredQueryDefinition query, long start, int length, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Queries just like theMarkLogicOperations.search(StructuredQueryDefinition, long, int, Class)
method does, but instead of a page/list of documents it returns an input stream straight from the results of the REST call against the database. The purpose of these methods is to skip the serialization/deserialization process of your application layer and just return raw data. If you don't need to access any parts of the document and just need to return the raw JSON/XML then it is easier/faster to just copy the stream from the database into the HTTP response directly. Extractions or server-side transforms can still be used to change how the data is returned in cases where there are properties you don't want returned through a public API, etc.- Specified by:
stream
in interfaceMarkLogicOperations
- Returns:
- An input stream of all the documents that matched the specified parameters.
-
stream
public <T> InputStream stream(com.marklogic.client.query.StructuredQueryDefinition query, org.springframework.data.domain.Pageable pageable, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Same as method taking int bounds, but allows use of Pagable for paging/sorting.- Specified by:
stream
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.stream(StructuredQueryDefinition, long, int, Class)
-
exists
public boolean exists(String uri)
Description copied from interface:MarkLogicOperations
Check for existence of a document by using the full URI under which the document is stored.- Specified by:
exists
in interfaceMarkLogicOperations
- Parameters:
uri
- The full URI of the document, i.e. "/Person/my-id.json"- Returns:
- True if a document with the specified URI exists.
-
exists
public <T> boolean exists(Object id, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Check for existence of an entity in the database by using it's ID.- Specified by:
exists
in interfaceMarkLogicOperations
- Type Parameters:
T
- The type of an entity.- Parameters:
id
- The ID value of an entity.entityClass
- The type class of an entity.- Returns:
- True if an entity with the specified ID exists.
-
exists
public <T> boolean exists(com.marklogic.client.query.StructuredQueryDefinition query, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Check for existence of entities matching the specified structured query. This will not show which ones match, but is a way to do a quick estimate on whether or not any exist in the first place.- Specified by:
exists
in interfaceMarkLogicOperations
- Type Parameters:
T
- The type of an entity.- Parameters:
query
- The structured query to use to match documents in the database.entityClass
- The type class of an entity.- Returns:
- True if there are any entities that match the query.
-
count
public long count(String... collections)
Description copied from interface:MarkLogicOperations
Count the number of documents that exist in the database under the specified collections.- Specified by:
count
in interfaceMarkLogicOperations
- Parameters:
collections
- Collection URIs to which to scope the count.- Returns:
- The number of documents contained under the specified collections.
-
count
public <T> long count(Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Count the number of the specified entity that exist in the database.- Specified by:
count
in interfaceMarkLogicOperations
- Type Parameters:
T
- The type of an entity.- Parameters:
entityClass
- The type class of an entity.- Returns:
- The number of the specified entity contained in the database.
-
count
public long count(com.marklogic.client.query.StructuredQueryDefinition query)
Description copied from interface:MarkLogicOperations
Gives a count of the number of documents that would match the specified query.- Specified by:
count
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.count(StructuredQueryDefinition, Class)
-
count
public <T> long count(com.marklogic.client.query.StructuredQueryDefinition query, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Count the number of entities that would match the specified query.- Specified by:
count
in interfaceMarkLogicOperations
- Type Parameters:
T
- The type of an entity.- Parameters:
query
- The structured query to use to match documents in the database.entityClass
- The type class of an entity.- Returns:
- The count of entities that are in the database.
-
deleteByUri
public void deleteByUri(String... uris)
Description copied from interface:MarkLogicOperations
Delete a document from the database that is stored under the specified uris- Specified by:
deleteByUri
in interfaceMarkLogicOperations
- Parameters:
uris
- The uris to delete, i.e. "/Person/my-id.json"
-
deleteByUris
public void deleteByUris(List<String> uris)
Description copied from interface:MarkLogicOperations
Delete a set of documents from the database that are stored under one of the specified URIs- Specified by:
deleteByUris
in interfaceMarkLogicOperations
- Parameters:
uris
- A list of uris to delete.
-
deleteById
public <T> void deleteById(Object id, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Deletes the entity with the specified ID.- Specified by:
deleteById
in interfaceMarkLogicOperations
- See Also:
MarkLogicOperations.deleteByIds(List, Class)
-
delete
public <T> void delete(List<T> entities)
Description copied from interface:MarkLogicOperations
Delete the specified entities from the database.- Specified by:
delete
in interfaceMarkLogicOperations
- Type Parameters:
T
- The type of an entity.- Parameters:
entities
- A list of entities.
-
delete
public <T> void delete(com.marklogic.client.query.StructuredQueryDefinition query, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Delete entities of the specified type that match the specified query.- Specified by:
delete
in interfaceMarkLogicOperations
- Type Parameters:
T
- The type of an entity.- Parameters:
query
- The structured query to use to match documents in the database.entityClass
- The type class of an entity.
-
deleteByIds
public <T> void deleteByIds(List<?> ids, Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Deletes the entities which have one of the specified IDs.- Specified by:
deleteByIds
in interfaceMarkLogicOperations
- Type Parameters:
T
- The type of an entity.- Parameters:
ids
- A list of entity IDs.entityClass
- The type class of an entity.
-
dropCollections
public void dropCollections(String... collections)
Description copied from interface:MarkLogicOperations
Delete documents that are under the specified collection URIs.- Specified by:
dropCollections
in interfaceMarkLogicOperations
- Parameters:
collections
- Collection URIs containing documents to delete.
-
dropCollection
public <T> void dropCollection(Class<T> entityClass)
Description copied from interface:MarkLogicOperations
Deletes all the entities of the specified type.- Specified by:
dropCollection
in interfaceMarkLogicOperations
- Type Parameters:
T
- The type of an entity.- Parameters:
entityClass
- The type class of an entity.
-
dropCollections
public <T> void dropCollections(Class<T>... entityClasses)
Description copied from interface:MarkLogicOperations
Deletes all the entities of the specified types.- Specified by:
dropCollections
in interfaceMarkLogicOperations
- Type Parameters:
T
- The type of an entity.- Parameters:
entityClasses
- The type classes of entities.
-
getConverter
public MarkLogicConverter getConverter()
Description copied from interface:MarkLogicOperations
Get the entity converter that is used to convert Java POJOs into a form with which they can be stored in the database.- Specified by:
getConverter
in interfaceMarkLogicOperations
- Returns:
- The converter object.
-
getQueryMapper
public QueryMapper getQueryMapper()
Description copied from interface:MarkLogicOperations
The query mapper is responsible for interpreting entity/query annotations and applying the information to a query before it is executed in MarkLogicTemplate. It also handles converting Query By Example objects into a MarkLogic query. The query mapper can be used when it is necessary to use the "execute" methods but you still want to take advantage of the annotations and other logic that is part of this framework.- Specified by:
getQueryMapper
in interfaceMarkLogicOperations
-
getQueryConversionService
public QueryConversionService getQueryConversionService()
Description copied from interface:MarkLogicOperations
Get the query object convert service that is used to convert various Java types into their "correct" form for querying in MarkLogic.- Specified by:
getQueryConversionService
in interfaceMarkLogicOperations
- Returns:
- The service object.
-
toEntityList
protected <T> List<T> toEntityList(Class<T> entityClass, com.marklogic.client.document.DocumentPage page)
-
toRecordList
protected List<com.marklogic.client.document.DocumentRecord> toRecordList(com.marklogic.client.document.DocumentPage page)
-
-