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.CouchbaseClient client) |
CouchbaseTemplate(com.couchbase.client.CouchbaseClient client,
CouchbaseConverter couchbaseConverter,
TranslationService translationService) |
CouchbaseTemplate(com.couchbase.client.CouchbaseClient 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.
|
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> |
findByView(String designName,
String viewName,
com.couchbase.client.protocol.views.Query query,
Class<T> entityClass)
Query a View for a list of documents of type T.
|
CouchbaseConverter |
getConverter()
Returns the underlying
CouchbaseConverter. |
com.couchbase.client.CouchbaseClient |
getCouchbaseClient()
Returns the linked
CouchbaseClient to this template. |
void |
insert(Collection<?> batchToInsert)
Insert a list of objects.
|
void |
insert(Collection<?> batchToInsert,
net.spy.memcached.PersistTo persistTo,
net.spy.memcached.ReplicateTo replicateTo)
Insert a list of objects.
|
void |
insert(Object objectToInsert)
Insert the given object.
|
void |
insert(Object objectToInsert,
net.spy.memcached.PersistTo persistTo,
net.spy.memcached.ReplicateTo replicateTo)
Insert the given object.
|
protected <T> void |
maybeEmitEvent(CouchbaseMappingEvent<T> event)
Helper method to publish an event if the event publisher is set.
|
com.couchbase.client.protocol.views.ViewResponse |
queryView(String designName,
String viewName,
com.couchbase.client.protocol.views.Query query)
Query a View with direct access to the
ViewResponse. |
void |
remove(Collection<?> batchToRemove)
Remove a list of objects from the bucket by id.
|
void |
remove(Collection<?> batchToRemove,
net.spy.memcached.PersistTo persistTo,
net.spy.memcached.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,
net.spy.memcached.PersistTo persistTo,
net.spy.memcached.ReplicateTo replicateTo)
Remove the given object from the bucket by id.
|
void |
save(Collection<?> batchToSave)
Save a list of objects.
|
void |
save(Collection<?> batchToSave,
net.spy.memcached.PersistTo persistTo,
net.spy.memcached.ReplicateTo replicateTo)
Save a list of objects.
|
void |
save(Object objectToSave)
Save the given object.
|
void |
save(Object objectToSave,
net.spy.memcached.PersistTo persistTo,
net.spy.memcached.ReplicateTo replicateTo)
Save the given object.
|
void |
setApplicationEventPublisher(ApplicationEventPublisher eventPublisher) |
void |
setWriteResultChecking(WriteResultChecking resultChecking) |
void |
update(Collection<?> batchToUpdate)
Insert a list of objects.
|
void |
update(Collection<?> batchToUpdate,
net.spy.memcached.PersistTo persistTo,
net.spy.memcached.ReplicateTo replicateTo)
Insert a list of objects.
|
void |
update(Object objectToUpdate)
Update the given object.
|
void |
update(Object objectToUpdate,
net.spy.memcached.PersistTo persistTo,
net.spy.memcached.ReplicateTo replicateTo)
Update the given object.
|
protected final MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> mappingContext
public CouchbaseTemplate(com.couchbase.client.CouchbaseClient client)
public CouchbaseTemplate(com.couchbase.client.CouchbaseClient client,
TranslationService translationService)
public CouchbaseTemplate(com.couchbase.client.CouchbaseClient client,
CouchbaseConverter couchbaseConverter,
TranslationService translationService)
public void setWriteResultChecking(WriteResultChecking resultChecking)
public void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher)
setApplicationEventPublisher in interface ApplicationEventPublisherAwarepublic final 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 final 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 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(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 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(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 final <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(String designName, String viewName, com.couchbase.client.protocol.views.Query query, Class<T> entityClass)
CouchbaseOperationsThere is no need to Query.setIncludeDocs(boolean) explicitely, because it will be set to true all the
time. It is valid to pass in a empty constructed Query object.
This method does not work with reduced views, because they by design do not contain references to original
objects. Use the provided CouchbaseOperations.queryView(java.lang.String, java.lang.String, com.couchbase.client.protocol.views.Query) method for more flexibility and direct access.
findByView in interface CouchbaseOperationsdesignName - the name of the design document.viewName - the name of the viewName.query - the Query object to customize the viewName query.entityClass - the entity to map to.public com.couchbase.client.protocol.views.ViewResponse queryView(String designName, String viewName, com.couchbase.client.protocol.views.Query query)
CouchbaseOperationsViewResponse.
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 CouchbaseOperationsdesignName - the name of the designDocument document.viewName - the name of the viewName.query - the Query object to customize the viewName query.public void remove(Object objectToRemove)
CouchbaseOperationsremove in interface CouchbaseOperationsobjectToRemove - the Object to remove.public void remove(Collection<?> batchToRemove)
CouchbaseOperationsremove in interface CouchbaseOperationsbatchToRemove - the list of Objects to remove.public <T> T execute(BucketCallback<T> action)
CouchbaseOperationsexecute in interface CouchbaseOperationsT - the return type.action - the action to execute in the callback.public boolean exists(String id)
CouchbaseOperationsexists in interface CouchbaseOperationsid - the unique ID of the document.protected static void ensureNotIterable(Object o)
o - the object to verify.public CouchbaseConverter getConverter()
CouchbaseOperationsCouchbaseConverter.getConverter in interface CouchbaseOperationspublic void save(Object objectToSave, net.spy.memcached.PersistTo persistTo, net.spy.memcached.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, net.spy.memcached.PersistTo persistTo, net.spy.memcached.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, net.spy.memcached.PersistTo persistTo, net.spy.memcached.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, net.spy.memcached.PersistTo persistTo, net.spy.memcached.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, net.spy.memcached.PersistTo persistTo, net.spy.memcached.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, net.spy.memcached.PersistTo persistTo, net.spy.memcached.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 void remove(Object objectToRemove, net.spy.memcached.PersistTo persistTo, net.spy.memcached.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, net.spy.memcached.PersistTo persistTo, net.spy.memcached.ReplicateTo replicateTo)
CouchbaseOperationsremove in interface CouchbaseOperationsbatchToRemove - the list of Objects to remove.persistTo - the persistence constraint setting.replicateTo - the replication constraint setting.protected <T> void maybeEmitEvent(CouchbaseMappingEvent<T> event)
T - the enclosed type.event - the event to emit.public com.couchbase.client.CouchbaseClient getCouchbaseClient()
CouchbaseOperationsCouchbaseClient to this template.getCouchbaseClient in interface CouchbaseOperationsCopyright © 2011-2015–2016 Pivotal Software, Inc.. All rights reserved.