public class CouchbaseTemplate extends Object implements CouchbaseOperations, ApplicationEventPublisherAware
| Modifier and Type | Field and Description |
|---|---|
protected MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> |
mappingContext |
| Constructor and Description |
|---|
CouchbaseTemplate(com.couchbase.client.java.cluster.ClusterInfo clusterInfo,
com.couchbase.client.java.Bucket client) |
CouchbaseTemplate(com.couchbase.client.java.cluster.ClusterInfo clusterInfo,
com.couchbase.client.java.Bucket client,
CouchbaseConverter converter,
TranslationService translationService) |
CouchbaseTemplate(com.couchbase.client.java.cluster.ClusterInfo clusterInfo,
com.couchbase.client.java.Bucket client,
TranslationService translationService) |
| Modifier and Type | Method and Description |
|---|---|
protected static void |
ensureNotIterable(Object o)
Make sure the given object is not a iterable.
|
<T> T |
execute(BucketCallback<T> action)
Executes a BucketCallback translating any exceptions as necessary.
|
<T> rx.Observable<T> |
executeAsync(rx.Observable<T> asyncAction) |
boolean |
exists(String id)
Checks if the given document exists.
|
<T> T |
findById(String id,
Class<T> entityClass)
Find an object by its given Id and map it to the corresponding entity.
|
<T> List<T> |
findByN1QL(com.couchbase.client.java.query.N1qlQuery n1ql,
Class<T> entityClass)
Query the N1QL Service for JSON data of type T.
|
<T> List<T> |
findByN1QLProjection(com.couchbase.client.java.query.N1qlQuery n1ql,
Class<T> entityClass)
Query the N1QL Service for partial JSON data of type T.
|
<T> List<T> |
findBySpatialView(com.couchbase.client.java.view.SpatialViewQuery query,
Class<T> entityClass)
Query a Spatial View for a list of documents of type T.
|
<T> List<T> |
findByView(com.couchbase.client.java.view.ViewQuery query,
Class<T> entityClass)
Query a View for a list of documents of type T.
|
CouchbaseConverter |
getConverter()
Returns the underlying
CouchbaseConverter. |
com.couchbase.client.java.Bucket |
getCouchbaseBucket()
Returns the linked
Bucket to this template. |
com.couchbase.client.java.cluster.ClusterInfo |
getCouchbaseClusterInfo()
Returns the
ClusterInfo about the cluster linked to this template. |
Consistency |
getDefaultConsistency()
Returns the
consistency parameter to be used by default for generated queries (views and N1QL)
in repositories. |
String |
getGeneratedId(Object entity)
Get generated id - applies both using prefix and suffix through entity as well as template
KeySettings
** NOTE: UNIQUE strategy will generate different ids each time *** |
void |
insert(Collection<?> batchToInsert)
Insert a list of objects.
|
void |
insert(Collection<?> batchToInsert,
com.couchbase.client.java.PersistTo persistTo,
com.couchbase.client.java.ReplicateTo replicateTo)
Insert a list of objects.
|
void |
insert(Object objectToInsert)
Insert the given object.
|
void |
insert(Object objectToInsert,
com.couchbase.client.java.PersistTo persistTo,
com.couchbase.client.java.ReplicateTo replicateTo)
Insert the given object.
|
KeySettings |
keySettings()
Get key settings associated with the template
|
void |
keySettings(KeySettings settings)
Add common key settings
Throws
UnsupportedOperationException if KeySettings is already set. |
protected <T> void |
maybeEmitEvent(CouchbaseMappingEvent<T> event)
Helper method to publish an event if the event publisher is set.
|
com.couchbase.client.java.query.N1qlQueryResult |
queryN1QL(com.couchbase.client.java.query.N1qlQuery query)
Query the N1QL Service with direct access to the
N1qlQueryResult. |
com.couchbase.client.java.view.SpatialViewResult |
querySpatialView(com.couchbase.client.java.view.SpatialViewQuery query)
Query a Spatial View with direct access to the
SpatialViewResult. |
com.couchbase.client.java.view.ViewResult |
queryView(com.couchbase.client.java.view.ViewQuery query)
Query a View with direct access to the
ViewResult. |
void |
remove(Collection<?> batchToRemove)
Remove a list of objects from the bucket by id.
|
void |
remove(Collection<?> batchToRemove,
com.couchbase.client.java.PersistTo persistTo,
com.couchbase.client.java.ReplicateTo replicateTo)
Remove a list of objects from the bucket by id.
|
void |
remove(Object objectToRemove)
Remove the given object from the bucket by id.
|
void |
remove(Object objectToRemove,
com.couchbase.client.java.PersistTo persistTo,
com.couchbase.client.java.ReplicateTo replicateTo)
Remove the given object from the bucket by id.
|
void |
save(Collection<?> batchToSave)
Save a list of objects.
|
void |
save(Collection<?> batchToSave,
com.couchbase.client.java.PersistTo persistTo,
com.couchbase.client.java.ReplicateTo replicateTo)
Save a list of objects.
|
void |
save(Object objectToSave)
Save the given object.
|
void |
save(Object objectToSave,
com.couchbase.client.java.PersistTo persistTo,
com.couchbase.client.java.ReplicateTo replicateTo)
Save the given object.
|
void |
setApplicationEventPublisher(ApplicationEventPublisher eventPublisher) |
void |
setDefaultConsistency(Consistency consistency) |
void |
setWriteResultChecking(WriteResultChecking writeResultChecking)
Configures the WriteResultChecking to be used with the template.
|
void |
update(Collection<?> batchToUpdate)
Insert a list of objects.
|
void |
update(Collection<?> batchToUpdate,
com.couchbase.client.java.PersistTo persistTo,
com.couchbase.client.java.ReplicateTo replicateTo)
Insert a list of objects.
|
void |
update(Object objectToUpdate)
Update the given object.
|
void |
update(Object objectToUpdate,
com.couchbase.client.java.PersistTo persistTo,
com.couchbase.client.java.ReplicateTo replicateTo)
Update the given object.
|
protected final MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> mappingContext
public CouchbaseTemplate(com.couchbase.client.java.cluster.ClusterInfo clusterInfo,
com.couchbase.client.java.Bucket client)
public CouchbaseTemplate(com.couchbase.client.java.cluster.ClusterInfo clusterInfo,
com.couchbase.client.java.Bucket client,
TranslationService translationService)
public CouchbaseTemplate(com.couchbase.client.java.cluster.ClusterInfo clusterInfo,
com.couchbase.client.java.Bucket client,
CouchbaseConverter converter,
TranslationService translationService)
protected static void ensureNotIterable(Object o)
o - the object to verify.public void setWriteResultChecking(WriteResultChecking writeResultChecking)
writeResultChecking - the setting to use.public void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher)
setApplicationEventPublisher in interface ApplicationEventPublisherAwareprotected <T> void maybeEmitEvent(CouchbaseMappingEvent<T> event)
T - the enclosed type.event - the event to emit.public void save(Object objectToSave)
CouchbaseOperationsWhen the document already exists (specified by its unique id), then it will be overriden. Otherwise it will be created.
save in interface CouchbaseOperationsobjectToSave - the object to store in the bucket.public void save(Object objectToSave, com.couchbase.client.java.PersistTo persistTo, com.couchbase.client.java.ReplicateTo replicateTo)
CouchbaseOperationsWhen the document already exists (specified by its unique id), then it will be overriden. Otherwise it will be created.
save in interface CouchbaseOperationsobjectToSave - the object to store in the bucket.public void save(Collection<?> batchToSave)
CouchbaseOperationsWhen one of the documents already exists (specified by its unique id), then it will be overriden. Otherwise it will be created.
save in interface CouchbaseOperationsbatchToSave - the list of objects to store in the bucket.public void save(Collection<?> batchToSave, com.couchbase.client.java.PersistTo persistTo, com.couchbase.client.java.ReplicateTo replicateTo)
CouchbaseOperationsWhen one of the documents already exists (specified by its unique id), then it will be overriden. Otherwise it will be created.
save in interface CouchbaseOperationsbatchToSave - the list of objects to store in the bucket.persistTo - the persistence constraint setting.replicateTo - the replication constraint setting.public void insert(Object objectToInsert)
CouchbaseOperationsWhen the document already exists (specified by its unique id), then it will not be overriden. Use the
CouchbaseOperations.save(java.lang.Object) method for this task.
insert in interface CouchbaseOperationsobjectToInsert - the object to add to the bucket.public void insert(Object objectToInsert, com.couchbase.client.java.PersistTo persistTo, com.couchbase.client.java.ReplicateTo replicateTo)
CouchbaseOperationsWhen the document already exists (specified by its unique id), then it will not be overriden. Use the
CouchbaseOperations.save(java.lang.Object) method for this task.
insert in interface CouchbaseOperationsobjectToInsert - the object to add to the bucket.persistTo - the persistence constraint setting.replicateTo - the replication constraint setting.public void insert(Collection<?> batchToInsert)
CouchbaseOperationsWhen one of the documents already exists (specified by its unique id), then it will not be overriden. Use the
CouchbaseOperations.save(java.lang.Object) method for this.
insert in interface CouchbaseOperationsbatchToInsert - the list of objects to add to the bucket.public void insert(Collection<?> batchToInsert, com.couchbase.client.java.PersistTo persistTo, com.couchbase.client.java.ReplicateTo replicateTo)
CouchbaseOperationsWhen one of the documents already exists (specified by its unique id), then it will not be overriden. Use the
CouchbaseOperations.save(java.lang.Object) method for this.
insert in interface CouchbaseOperationsbatchToInsert - the list of objects to add to the bucket.persistTo - the persistence constraint setting.replicateTo - the replication constraint setting.public void update(Object objectToUpdate)
CouchbaseOperationsWhen the document does not exist (specified by its unique id) it will not be created. Use the
CouchbaseOperations.save(java.lang.Object) method for this.
update in interface CouchbaseOperationsobjectToUpdate - the object to add to the bucket.public void update(Object objectToUpdate, com.couchbase.client.java.PersistTo persistTo, com.couchbase.client.java.ReplicateTo replicateTo)
CouchbaseOperationsWhen the document does not exist (specified by its unique id) it will not be created. Use the
CouchbaseOperations.save(java.lang.Object) method for this.
update in interface CouchbaseOperationsobjectToUpdate - the object to add to the bucket.persistTo - the persistence constraint setting.replicateTo - the replication constraint setting.public void update(Collection<?> batchToUpdate)
CouchbaseOperationsIf one of the documents does not exist (specified by its unique id), then it will not be created. Use the
CouchbaseOperations.save(java.lang.Object) method for this.
update in interface CouchbaseOperationsbatchToUpdate - the list of objects to add to the bucket.public void update(Collection<?> batchToUpdate, com.couchbase.client.java.PersistTo persistTo, com.couchbase.client.java.ReplicateTo replicateTo)
CouchbaseOperationsIf one of the documents does not exist (specified by its unique id), then it will not be created. Use the
CouchbaseOperations.save(java.lang.Object) method for this.
update in interface CouchbaseOperationsbatchToUpdate - the list of objects to add to the bucket.persistTo - the persistence constraint setting.replicateTo - the replication constraint setting.public <T> T findById(String id, Class<T> entityClass)
CouchbaseOperationsfindById in interface CouchbaseOperationsid - the unique ID of the document.entityClass - the entity to map to.public <T> List<T> findByView(com.couchbase.client.java.view.ViewQuery query, Class<T> entityClass)
CouchbaseOperationsThere is no need to set includeDocs explicitly, since this method will
manage the retrieval of documents internally. It is valid to pass in a empty constructed ViewQuery object.
Weak consistency in the query (stale(Stale.TRUE)) can lead to some documents being unreachable due
to their deletion not having been indexed. These deleted null documents are eliminated from the result of this
method.
This method does not work with reduced views, because they by design do not contain references to original
objects. Use the provided CouchbaseOperations.queryView(com.couchbase.client.java.view.ViewQuery) method for more flexibility and direct access.
findByView in interface CouchbaseOperationsquery - the Query object (also specifying view design document and view name).entityClass - the entity to map to.public com.couchbase.client.java.view.ViewResult queryView(com.couchbase.client.java.view.ViewQuery query)
CouchbaseOperationsViewResult.
This method is available to ease the working with views by still wrapping exceptions into the Spring infrastructure.
It is especially needed if you want to run reduced viewName queries, because they can't be mapped onto entities directly.
queryView in interface CouchbaseOperationsquery - the Query object (also specifying view design document and view name).public <T> List<T> findBySpatialView(com.couchbase.client.java.view.SpatialViewQuery query, Class<T> entityClass)
CouchbaseOperationsThere is no need to set includeDocs explicitly, since this method
will manage the retrieval of documents internally. It is valid to pass in a empty constructed SpatialViewQuery object.
Weak consistency in the query (stale(Stale.TRUE)) can lead to some documents being unreachable due
to their deletion not having been indexed. These deleted null documents are eliminated from the result of this
method.
findBySpatialView in interface CouchbaseOperationsquery - the SpatialViewQuery object (also specifying view design document and view name).entityClass - the entity to map to.public com.couchbase.client.java.view.SpatialViewResult querySpatialView(com.couchbase.client.java.view.SpatialViewQuery query)
CouchbaseOperationsSpatialViewResult.
This method is available to ease the working with spatial views by still wrapping exceptions into the Spring infrastructure.
querySpatialView in interface CouchbaseOperationsquery - the SpatialViewQuery object (also specifying view design document and view name).public <T> List<T> findByN1QL(com.couchbase.client.java.query.N1qlQuery n1ql, Class<T> entityClass)
CouchbaseOperationsThis is done via a N1qlQuery that contains a Statement and possibly
additional query parameters (N1qlParams) and placeholder values if the
statement contains placeholders.
Use N1qlQuery's factory methods to construct such a Query.
Weak consistency in the query (eg. ScanConsistency.NOT_BOUND) can lead to some documents being
unreachable due to their deletion not having been indexed. These deleted null documents are eliminated from the
result of this method.
findByN1QL in interface CouchbaseOperationsT - the entity classn1ql - the N1QL query.entityClass - the target class for the returned entities.public <T> List<T> findByN1QLProjection(com.couchbase.client.java.query.N1qlQuery n1ql, Class<T> entityClass)
CouchbaseOperationsstraightforward decoding
(no document, metadata like id nor cas) to map to a "fragment class".
This is done via a N1qlQuery that contains a Statement and possibly
additional query parameters (N1qlParams) and placeholder values if the
statement contains placeholders.
Use N1qlQuery's factory methods to construct such a Query.
Weak consistency in the query (eg. ScanConsistency.NOT_BOUND) can lead to some documents being
unreachable due to their deletion not having been indexed. These deleted null documents are eliminated from the
result of this method.
findByN1QLProjection in interface CouchbaseOperationsT - the fragment classn1ql - the N1QL query.entityClass - the target class for the returned fragments.public com.couchbase.client.java.query.N1qlQueryResult queryN1QL(com.couchbase.client.java.query.N1qlQuery query)
CouchbaseOperationsN1qlQueryResult.
This is done via a N1qlQuery that can
contain a Statement, additional query parameters (N1qlParams)
and placeholder values if the statement contains placeholders.
Use N1qlQuery's factory methods to construct this.
queryN1QL in interface CouchbaseOperationsquery - the N1QL query.N1qlQueryResult containing the results of the n1ql query.public boolean exists(String id)
CouchbaseOperationsexists in interface CouchbaseOperationsid - the unique ID of the document.public void remove(Object objectToRemove)
CouchbaseOperationsremove in interface CouchbaseOperationsobjectToRemove - the Object to remove.public void remove(Object objectToRemove, com.couchbase.client.java.PersistTo persistTo, com.couchbase.client.java.ReplicateTo replicateTo)
CouchbaseOperationsremove in interface CouchbaseOperationsobjectToRemove - the Object to remove.persistTo - the persistence constraint setting.replicateTo - the replication constraint setting.public void remove(Collection<?> batchToRemove)
CouchbaseOperationsremove in interface CouchbaseOperationsbatchToRemove - the list of Objects to remove.public void remove(Collection<?> batchToRemove, com.couchbase.client.java.PersistTo persistTo, com.couchbase.client.java.ReplicateTo replicateTo)
CouchbaseOperationsremove in interface CouchbaseOperationsbatchToRemove - the list of Objects to remove.persistTo - the persistence constraint setting.replicateTo - the replication constraint setting.public <T> T execute(BucketCallback<T> action)
CouchbaseOperationsexecute in interface CouchbaseOperationsT - the return type.action - the action to execute in the callback.public <T> rx.Observable<T> executeAsync(rx.Observable<T> asyncAction)
public com.couchbase.client.java.Bucket getCouchbaseBucket()
CouchbaseOperationsBucket to this template.getCouchbaseBucket in interface CouchbaseOperationspublic com.couchbase.client.java.cluster.ClusterInfo getCouchbaseClusterInfo()
CouchbaseOperationsClusterInfo about the cluster linked to this template.getCouchbaseClusterInfo in interface CouchbaseOperationspublic CouchbaseConverter getConverter()
CouchbaseOperationsCouchbaseConverter.getConverter in interface CouchbaseOperationspublic Consistency getDefaultConsistency()
CouchbaseOperationsconsistency parameter to be used by default for generated queries (views and N1QL)
in repositories. Defaults to Consistency.DEFAULT_CONSISTENCY.getDefaultConsistency in interface CouchbaseOperationspublic void setDefaultConsistency(Consistency consistency)
public void keySettings(KeySettings settings)
CouchbaseOperationsUnsupportedOperationException if KeySettings is already set. It becomes immutable.keySettings in interface CouchbaseOperationssettings - KeySettingspublic KeySettings keySettings()
CouchbaseOperationskeySettings in interface CouchbaseOperationsKeySettingspublic String getGeneratedId(Object entity)
CouchbaseOperationsKeySettings
** NOTE: UNIQUE strategy will generate different ids each time ***getGeneratedId in interface CouchbaseOperationsentity - the entity object.Copyright © 2011–2019 Pivotal Software, Inc.. All rights reserved.