Class CouchbaseTemplate
java.lang.Object
org.springframework.data.couchbase.core.CouchbaseTemplate
- All Implemented Interfaces:
Aware
,ApplicationContextAware
,CouchbaseOperations
,ExecutableExistsByIdOperation
,ExecutableFindByAnalyticsOperation
,ExecutableFindByIdOperation
,ExecutableFindByQueryOperation
,ExecutableFindFromReplicasByIdOperation
,ExecutableInsertByIdOperation
,ExecutableMutateInByIdOperation
,ExecutableRangeScanOperation
,ExecutableRemoveByIdOperation
,ExecutableRemoveByQueryOperation
,ExecutableReplaceByIdOperation
,ExecutableUpsertByIdOperation
,FluentCouchbaseOperations
public class CouchbaseTemplate
extends Object
implements CouchbaseOperations, ApplicationContextAware
Implements lower-level couchbase operations on top of the SDK with entity mapping capabilities.
- Since:
- 3.0
- Author:
- Michael Nitschinger, Michael Reiche, Jorge Rodriguez Martin, Tigran Babloyan
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.data.couchbase.core.ExecutableExistsByIdOperation
ExecutableExistsByIdOperation.ExecutableExistsById, ExecutableExistsByIdOperation.ExistsByIdInCollection<T>, ExecutableExistsByIdOperation.ExistsByIdInScope<T>, ExecutableExistsByIdOperation.ExistsByIdWithOptions<T>, ExecutableExistsByIdOperation.TerminatingExistsById
Nested classes/interfaces inherited from interface org.springframework.data.couchbase.core.ExecutableFindByAnalyticsOperation
ExecutableFindByAnalyticsOperation.ExecutableFindByAnalytics<T>, ExecutableFindByAnalyticsOperation.FindByAnalyticsConsistentWith<T>, ExecutableFindByAnalyticsOperation.FindByAnalyticsInCollection<T>, ExecutableFindByAnalyticsOperation.FindByAnalyticsInScope<T>, ExecutableFindByAnalyticsOperation.FindByAnalyticsWithConsistency<T>, ExecutableFindByAnalyticsOperation.FindByAnalyticsWithOptions<T>, ExecutableFindByAnalyticsOperation.FindByAnalyticsWithProjection<T>, ExecutableFindByAnalyticsOperation.FindByAnalyticsWithQuery<T>, ExecutableFindByAnalyticsOperation.TerminatingFindByAnalytics<T>
Nested classes/interfaces inherited from interface org.springframework.data.couchbase.core.ExecutableFindByIdOperation
ExecutableFindByIdOperation.ExecutableFindById<T>, ExecutableFindByIdOperation.FindByIdInCollection<T>, ExecutableFindByIdOperation.FindByIdInScope<T>, ExecutableFindByIdOperation.FindByIdWithExpiry<T>, ExecutableFindByIdOperation.FindByIdWithLock<T>, ExecutableFindByIdOperation.FindByIdWithOptions<T>, ExecutableFindByIdOperation.FindByIdWithProjection<T>, ExecutableFindByIdOperation.TerminatingFindById<T>
Nested classes/interfaces inherited from interface org.springframework.data.couchbase.core.ExecutableFindByQueryOperation
ExecutableFindByQueryOperation.ExecutableFindByQuery<T>, ExecutableFindByQueryOperation.FindByQueryConsistentWith<T>, ExecutableFindByQueryOperation.FindByQueryInCollection<T>, ExecutableFindByQueryOperation.FindByQueryInScope<T>, ExecutableFindByQueryOperation.FindByQueryWithConsistency<T>, ExecutableFindByQueryOperation.FindByQueryWithDistinct<T>, ExecutableFindByQueryOperation.FindByQueryWithOptions<T>, ExecutableFindByQueryOperation.FindByQueryWithProjecting<T>, ExecutableFindByQueryOperation.FindByQueryWithProjection<T>, ExecutableFindByQueryOperation.FindByQueryWithQuery<T>, ExecutableFindByQueryOperation.TerminatingFindByQuery<T>
Nested classes/interfaces inherited from interface org.springframework.data.couchbase.core.ExecutableFindFromReplicasByIdOperation
ExecutableFindFromReplicasByIdOperation.ExecutableFindFromReplicasById<T>, ExecutableFindFromReplicasByIdOperation.FindFromReplicasByIdInCollection<T>, ExecutableFindFromReplicasByIdOperation.FindFromReplicasByIdInScope<T>, ExecutableFindFromReplicasByIdOperation.FindFromReplicasByIdWithOptions<T>, ExecutableFindFromReplicasByIdOperation.TerminatingFindFromReplicasById<T>
Nested classes/interfaces inherited from interface org.springframework.data.couchbase.core.ExecutableInsertByIdOperation
ExecutableInsertByIdOperation.ExecutableInsertById<T>, ExecutableInsertByIdOperation.InsertByIdInCollection<T>, ExecutableInsertByIdOperation.InsertByIdInScope<T>, ExecutableInsertByIdOperation.InsertByIdWithDurability<T>, ExecutableInsertByIdOperation.InsertByIdWithExpiry<T>, ExecutableInsertByIdOperation.InsertByIdWithOptions<T>, ExecutableInsertByIdOperation.TerminatingInsertById<T>
Nested classes/interfaces inherited from interface org.springframework.data.couchbase.core.ExecutableMutateInByIdOperation
ExecutableMutateInByIdOperation.ExecutableMutateInById<T>, ExecutableMutateInByIdOperation.MutateInByIdInCollection<T>, ExecutableMutateInByIdOperation.MutateInByIdInScope<T>, ExecutableMutateInByIdOperation.MutateInByIdWithDurability<T>, ExecutableMutateInByIdOperation.MutateInByIdWithExpiry<T>, ExecutableMutateInByIdOperation.MutateInByIdWithOptions<T>, ExecutableMutateInByIdOperation.MutateInByIdWithPaths<T>, ExecutableMutateInByIdOperation.TerminatingMutateInById<T>
Nested classes/interfaces inherited from interface org.springframework.data.couchbase.core.ExecutableRangeScanOperation
ExecutableRangeScanOperation.ExecutableRangeScan<T>, ExecutableRangeScanOperation.RangeScanConsistentWith<T>, ExecutableRangeScanOperation.RangeScanInCollection<T>, ExecutableRangeScanOperation.RangeScanInScope<T>, ExecutableRangeScanOperation.RangeScanWithBatchByteLimit<T>, ExecutableRangeScanOperation.RangeScanWithBatchItemLimit<T>, ExecutableRangeScanOperation.RangeScanWithOptions<T>, ExecutableRangeScanOperation.RangeScanWithProjection<T>, ExecutableRangeScanOperation.RangeScanWithSort<T>, ExecutableRangeScanOperation.TerminatingRangeScan<T>
Nested classes/interfaces inherited from interface org.springframework.data.couchbase.core.ExecutableRemoveByIdOperation
ExecutableRemoveByIdOperation.ExecutableRemoveById, ExecutableRemoveByIdOperation.RemoveByIdInCollection, ExecutableRemoveByIdOperation.RemoveByIdInScope, ExecutableRemoveByIdOperation.RemoveByIdWithCas, ExecutableRemoveByIdOperation.RemoveByIdWithDurability, ExecutableRemoveByIdOperation.RemoveByIdWithOptions, ExecutableRemoveByIdOperation.TerminatingRemoveById
Nested classes/interfaces inherited from interface org.springframework.data.couchbase.core.ExecutableRemoveByQueryOperation
ExecutableRemoveByQueryOperation.ExecutableRemoveByQuery<T>, ExecutableRemoveByQueryOperation.RemoveByQueryConsistentWith<T>, ExecutableRemoveByQueryOperation.RemoveByQueryInCollection<T>, ExecutableRemoveByQueryOperation.RemoveByQueryInScope<T>, ExecutableRemoveByQueryOperation.RemoveByQueryWithConsistency<T>, ExecutableRemoveByQueryOperation.RemoveByQueryWithOptions<T>, ExecutableRemoveByQueryOperation.RemoveByQueryWithQuery<T>, ExecutableRemoveByQueryOperation.TerminatingRemoveByQuery<T>
Nested classes/interfaces inherited from interface org.springframework.data.couchbase.core.ExecutableReplaceByIdOperation
ExecutableReplaceByIdOperation.ExecutableReplaceById<T>, ExecutableReplaceByIdOperation.ReplaceByIdInCollection<T>, ExecutableReplaceByIdOperation.ReplaceByIdInScope<T>, ExecutableReplaceByIdOperation.ReplaceByIdWithDurability<T>, ExecutableReplaceByIdOperation.ReplaceByIdWithExpiry<T>, ExecutableReplaceByIdOperation.ReplaceByIdWithOptions<T>, ExecutableReplaceByIdOperation.TerminatingReplaceById<T>
Nested classes/interfaces inherited from interface org.springframework.data.couchbase.core.ExecutableUpsertByIdOperation
ExecutableUpsertByIdOperation.ExecutableUpsertById<T>, ExecutableUpsertByIdOperation.TerminatingUpsertById<T>, ExecutableUpsertByIdOperation.UpsertByIdInCollection<T>, ExecutableUpsertByIdOperation.UpsertByIdInScope<T>, ExecutableUpsertByIdOperation.UpsertByIdWithDurability<T>, ExecutableUpsertByIdOperation.UpsertByIdWithExpiry<T>, ExecutableUpsertByIdOperation.UpsertByIdWithOptions<T>
-
Constructor Summary
ConstructorDescriptionCouchbaseTemplate
(CouchbaseClientFactory clientFactory, CouchbaseConverter converter) CouchbaseTemplate
(CouchbaseClientFactory clientFactory, CouchbaseConverter converter, TranslationService translationService) CouchbaseTemplate
(CouchbaseClientFactory clientFactory, CouchbaseConverter converter, TranslationService translationService, com.couchbase.client.java.query.QueryScanConsistency scanConsistency) -
Method Summary
Modifier and TypeMethodDescription<T> Long
Returns the count of documents found by the query.Deprecated.existsById
(Class<?> domainType) Checks if the document exists in the bucket.findByAnalytics
(Class<T> domainType) Queries the analytics service.Loads a document from a bucket.findByQuery
(Class<T> domainType) Queries the N1QL service.findFromReplicasById
(Class<T> domainType) Loads a document from a replica.The name of the bucket used.com.couchbase.client.java.Collection
getCollection
(String collectionName) Provides access to aCollection
on the configuredCouchbaseClientFactory
.com.couchbase.client.java.query.QueryScanConsistency
Returns the default consistency to use for queriesReturns the converter used for this template/operations.Returns the underlying client factory.The name of the scope used, null if the default scope is used.insertById
(Class<T> domainType) Insert using the KV service.mutateInById
(Class<T> domainType) Mutate using the KV service.Loads a document from a bucket.reactive()
Deprecated.removeById
(Class<?> domainType) Removes a document.removeByQuery
(Class<T> domainType) Remove via the query service.replaceById
(Class<T> domainType) Replace using the KV service.<T> T
Save the entity to couchbase.
If there is no version property on the entity class, and this is in a transaction, use insert.void
setApplicationContext
(ApplicationContext applicationContext) support()
upsertById
(Class<T> domainType) Upsert using the KV service.
-
Constructor Details
-
CouchbaseTemplate
-
CouchbaseTemplate
public CouchbaseTemplate(CouchbaseClientFactory clientFactory, CouchbaseConverter converter, TranslationService translationService) -
CouchbaseTemplate
public CouchbaseTemplate(CouchbaseClientFactory clientFactory, CouchbaseConverter converter, TranslationService translationService, com.couchbase.client.java.query.QueryScanConsistency scanConsistency)
-
-
Method Details
-
save
Description copied from interface:CouchbaseOperations
Save the entity to couchbase.
If there is no version property on the entity class, and this is in a transaction, use insert.
If there is no version property on the entity class, and this is not in a transaction, use upsert.
If there is a version property on the entity class, and it is non-zero, then this is an existing document, use replace.
Otherwise, there is a version property for the entity, but it is zero or null, use insert.- Specified by:
save
in interfaceCouchbaseOperations
- Type Parameters:
T
- the entity class- Parameters:
entity
- the entity to save in couchbasescopeAndCollection
- for use by repositories only. these are varargs for the scope and collection.- Returns:
-
count
Description copied from interface:CouchbaseOperations
Returns the count of documents found by the query.- Specified by:
count
in interfaceCouchbaseOperations
- Returns:
-
upsertById
Description copied from interface:ExecutableUpsertByIdOperation
Upsert using the KV service.- Specified by:
upsertById
in interfaceExecutableUpsertByIdOperation
- Parameters:
domainType
- the entity type to upsert.
-
mutateInById
public <T> ExecutableMutateInByIdOperation.ExecutableMutateInById<T> mutateInById(Class<T> domainType) Description copied from interface:ExecutableMutateInByIdOperation
Mutate using the KV service.- Specified by:
mutateInById
in interfaceExecutableMutateInByIdOperation
- Parameters:
domainType
- the entity type to mutate.
-
insertById
Description copied from interface:ExecutableInsertByIdOperation
Insert using the KV service.- Specified by:
insertById
in interfaceExecutableInsertByIdOperation
- Parameters:
domainType
- the entity type to insert.
-
replaceById
Description copied from interface:ExecutableReplaceByIdOperation
Replace using the KV service.- Specified by:
replaceById
in interfaceExecutableReplaceByIdOperation
- Parameters:
domainType
- the entity type to replace.
-
findById
Description copied from interface:ExecutableFindByIdOperation
Loads a document from a bucket.- Specified by:
findById
in interfaceExecutableFindByIdOperation
- Parameters:
domainType
- the entity type to use for the results.
-
findFromReplicasById
public <T> ExecutableFindFromReplicasByIdOperation.ExecutableFindFromReplicasById<T> findFromReplicasById(Class<T> domainType) Description copied from interface:ExecutableFindFromReplicasByIdOperation
Loads a document from a replica.- Specified by:
findFromReplicasById
in interfaceExecutableFindFromReplicasByIdOperation
- Parameters:
domainType
- the entity type to use for the results.
-
findByQuery
Description copied from interface:ExecutableFindByQueryOperation
Queries the N1QL service.- Specified by:
findByQuery
in interfaceExecutableFindByQueryOperation
- Parameters:
domainType
- the entity type to use for the results.
-
findByAnalytics
public <T> ExecutableFindByAnalyticsOperation.ExecutableFindByAnalytics<T> findByAnalytics(Class<T> domainType) Description copied from interface:ExecutableFindByAnalyticsOperation
Queries the analytics service.- Specified by:
findByAnalytics
in interfaceExecutableFindByAnalyticsOperation
- Parameters:
domainType
- the entity type to use for the results.
-
removeById
Deprecated.Description copied from interface:ExecutableRemoveByIdOperation
Removes a document.- Specified by:
removeById
in interfaceExecutableRemoveByIdOperation
-
removeById
Description copied from interface:ExecutableRemoveByIdOperation
Removes a document.- Specified by:
removeById
in interfaceExecutableRemoveByIdOperation
-
existsById
Deprecated.Description copied from interface:ExecutableExistsByIdOperation
Checks if the document exists in the bucket.- Specified by:
existsById
in interfaceExecutableExistsByIdOperation
-
existsById
Description copied from interface:ExecutableExistsByIdOperation
Checks if the document exists in the bucket.- Specified by:
existsById
in interfaceExecutableExistsByIdOperation
-
removeByQuery
public <T> ExecutableRemoveByQueryOperation.ExecutableRemoveByQuery<T> removeByQuery(Class<T> domainType) Description copied from interface:ExecutableRemoveByQueryOperation
Remove via the query service.- Specified by:
removeByQuery
in interfaceExecutableRemoveByQueryOperation
-
rangeScan
Description copied from interface:ExecutableRangeScanOperation
Loads a document from a bucket.- Specified by:
rangeScan
in interfaceExecutableRangeScanOperation
- Parameters:
domainType
- the entity type to use for the results.
-
getBucketName
Description copied from interface:CouchbaseOperations
The name of the bucket used.- Specified by:
getBucketName
in interfaceCouchbaseOperations
-
getScopeName
Description copied from interface:CouchbaseOperations
The name of the scope used, null if the default scope is used.- Specified by:
getScopeName
in interfaceCouchbaseOperations
-
getCouchbaseClientFactory
Description copied from interface:CouchbaseOperations
Returns the underlying client factory.- Specified by:
getCouchbaseClientFactory
in interfaceCouchbaseOperations
-
getConsistency
public com.couchbase.client.java.query.QueryScanConsistency getConsistency()Description copied from interface:CouchbaseOperations
Returns the default consistency to use for queries- Specified by:
getConsistency
in interfaceCouchbaseOperations
-
getCollection
Provides access to aCollection
on the configuredCouchbaseClientFactory
.- Parameters:
collectionName
- the name of the collection, if null is passed in the default collection is assumed.- Returns:
- the collection instance.
-
getConverter
Description copied from interface:CouchbaseOperations
Returns the converter used for this template/operations.- Specified by:
getConverter
in interfaceCouchbaseOperations
-
reactive
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Throws:
BeansException
-
support
-