Spring Data Couchbase

org.springframework.data.couchbase.core
Class CouchbaseTemplate

java.lang.Object
  extended by org.springframework.data.couchbase.core.CouchbaseTemplate
All Implemented Interfaces:
Aware, ApplicationEventPublisherAware, CouchbaseOperations

public class CouchbaseTemplate
extends Object
implements CouchbaseOperations, ApplicationEventPublisherAware

Author:
Michael Nitschinger, Oliver Gierke

Field Summary
protected  MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> mappingContext
           
 
Constructor Summary
CouchbaseTemplate(com.couchbase.client.CouchbaseClient client)
           
CouchbaseTemplate(com.couchbase.client.CouchbaseClient client, CouchbaseConverter couchbaseConverter, TranslationService translationService)
           
CouchbaseTemplate(com.couchbase.client.CouchbaseClient client, TranslationService translationService)
           
 
Method Summary
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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mappingContext

protected final MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> mappingContext
Constructor Detail

CouchbaseTemplate

public CouchbaseTemplate(com.couchbase.client.CouchbaseClient client)

CouchbaseTemplate

public CouchbaseTemplate(com.couchbase.client.CouchbaseClient client,
                         TranslationService translationService)

CouchbaseTemplate

public CouchbaseTemplate(com.couchbase.client.CouchbaseClient client,
                         CouchbaseConverter couchbaseConverter,
                         TranslationService translationService)
Method Detail

setWriteResultChecking

public void setWriteResultChecking(WriteResultChecking resultChecking)

setApplicationEventPublisher

public void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher)
Specified by:
setApplicationEventPublisher in interface ApplicationEventPublisherAware

insert

public final void insert(Object objectToInsert)
Description copied from interface: CouchbaseOperations
Insert the given object.

When 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.

Specified by:
insert in interface CouchbaseOperations
Parameters:
objectToInsert - the object to add to the bucket.

insert

public final void insert(Collection<?> batchToInsert)
Description copied from interface: CouchbaseOperations
Insert a list of objects.

When 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.

Specified by:
insert in interface CouchbaseOperations
Parameters:
batchToInsert - the list of objects to add to the bucket.

save

public void save(Object objectToSave)
Description copied from interface: CouchbaseOperations
Save the given object.

When the document already exists (specified by its unique id), then it will be overriden. Otherwise it will be created.

Specified by:
save in interface CouchbaseOperations
Parameters:
objectToSave - the object to store in the bucket.

save

public void save(Collection<?> batchToSave)
Description copied from interface: CouchbaseOperations
Save a list of objects.

When one of the documents already exists (specified by its unique id), then it will be overriden. Otherwise it will be created.

Specified by:
save in interface CouchbaseOperations
Parameters:
batchToSave - the list of objects to store in the bucket.

update

public void update(Object objectToUpdate)
Description copied from interface: CouchbaseOperations
Update the given object.

When 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.

Specified by:
update in interface CouchbaseOperations
Parameters:
objectToUpdate - the object to add to the bucket.

update

public void update(Collection<?> batchToUpdate)
Description copied from interface: CouchbaseOperations
Insert a list of objects.

If 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.

Specified by:
update in interface CouchbaseOperations
Parameters:
batchToUpdate - the list of objects to add to the bucket.

findById

public final <T> T findById(String id,
                            Class<T> entityClass)
Description copied from interface: CouchbaseOperations
Find an object by its given Id and map it to the corresponding entity.

Specified by:
findById in interface CouchbaseOperations
Parameters:
id - the unique ID of the document.
entityClass - the entity to map to.
Returns:
returns the found object or null otherwise.

findByView

public <T> List<T> findByView(String designName,
                              String viewName,
                              com.couchbase.client.protocol.views.Query query,
                              Class<T> entityClass)
Description copied from interface: CouchbaseOperations
Query a View for a list of documents of type T.

There 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.

Specified by:
findByView in interface CouchbaseOperations
Parameters:
designName - 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.
Returns:
the converted collection

queryView

public com.couchbase.client.protocol.views.ViewResponse queryView(String designName,
                                                                  String viewName,
                                                                  com.couchbase.client.protocol.views.Query query)
Description copied from interface: CouchbaseOperations
Query a View with direct access to the ViewResponse.

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.

Specified by:
queryView in interface CouchbaseOperations
Parameters:
designName - the name of the designDocument document.
viewName - the name of the viewName.
query - the Query object to customize the viewName query.
Returns:
ViewResponse containing the results of the query.

remove

public void remove(Object objectToRemove)
Description copied from interface: CouchbaseOperations
Remove the given object from the bucket by id.

If the object is a String, it will be treated as the document key directly.

Specified by:
remove in interface CouchbaseOperations
Parameters:
objectToRemove - the Object to remove.

remove

public void remove(Collection<?> batchToRemove)
Description copied from interface: CouchbaseOperations
Remove a list of objects from the bucket by id.

Specified by:
remove in interface CouchbaseOperations
Parameters:
batchToRemove - the list of Objects to remove.

execute

public <T> T execute(BucketCallback<T> action)
Description copied from interface: CouchbaseOperations
Executes a BucketCallback translating any exceptions as necessary.

Allows for returning a result object, that is a domain object or a collection of domain objects.

Specified by:
execute in interface CouchbaseOperations
Type Parameters:
T - the return type.
Parameters:
action - the action to execute in the callback.
Returns:
the return type.

exists

public boolean exists(String id)
Description copied from interface: CouchbaseOperations
Checks if the given document exists.

Specified by:
exists in interface CouchbaseOperations
Parameters:
id - the unique ID of the document.
Returns:
whether the document could be found or not.

ensureNotIterable

protected static void ensureNotIterable(Object o)
Make sure the given object is not a iterable.

Parameters:
o - the object to verify.

getConverter

public CouchbaseConverter getConverter()
Description copied from interface: CouchbaseOperations
Returns the underlying CouchbaseConverter.

Specified by:
getConverter in interface CouchbaseOperations
Returns:
CouchbaseConverter.

save

public void save(Object objectToSave,
                 net.spy.memcached.PersistTo persistTo,
                 net.spy.memcached.ReplicateTo replicateTo)
Description copied from interface: CouchbaseOperations
Save the given object.

When the document already exists (specified by its unique id), then it will be overriden. Otherwise it will be created.

Specified by:
save in interface CouchbaseOperations
Parameters:
objectToSave - the object to store in the bucket.

save

public void save(Collection<?> batchToSave,
                 net.spy.memcached.PersistTo persistTo,
                 net.spy.memcached.ReplicateTo replicateTo)
Description copied from interface: CouchbaseOperations
Save a list of objects.

When one of the documents already exists (specified by its unique id), then it will be overriden. Otherwise it will be created.

Specified by:
save in interface CouchbaseOperations
Parameters:
batchToSave - the list of objects to store in the bucket.
persistTo - the persistence constraint setting.
replicateTo - the replication constraint setting.

insert

public void insert(Object objectToInsert,
                   net.spy.memcached.PersistTo persistTo,
                   net.spy.memcached.ReplicateTo replicateTo)
Description copied from interface: CouchbaseOperations
Insert the given object.

When 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.

Specified by:
insert in interface CouchbaseOperations
Parameters:
objectToInsert - the object to add to the bucket.
persistTo - the persistence constraint setting.
replicateTo - the replication constraint setting.

insert

public void insert(Collection<?> batchToInsert,
                   net.spy.memcached.PersistTo persistTo,
                   net.spy.memcached.ReplicateTo replicateTo)
Description copied from interface: CouchbaseOperations
Insert a list of objects.

When 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.

Specified by:
insert in interface CouchbaseOperations
Parameters:
batchToInsert - the list of objects to add to the bucket.
persistTo - the persistence constraint setting.
replicateTo - the replication constraint setting.

update

public void update(Object objectToUpdate,
                   net.spy.memcached.PersistTo persistTo,
                   net.spy.memcached.ReplicateTo replicateTo)
Description copied from interface: CouchbaseOperations
Update the given object.

When 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.

Specified by:
update in interface CouchbaseOperations
Parameters:
objectToUpdate - the object to add to the bucket.
persistTo - the persistence constraint setting.
replicateTo - the replication constraint setting.

update

public void update(Collection<?> batchToUpdate,
                   net.spy.memcached.PersistTo persistTo,
                   net.spy.memcached.ReplicateTo replicateTo)
Description copied from interface: CouchbaseOperations
Insert a list of objects.

If 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.

Specified by:
update in interface CouchbaseOperations
Parameters:
batchToUpdate - the list of objects to add to the bucket.
persistTo - the persistence constraint setting.
replicateTo - the replication constraint setting.

remove

public void remove(Object objectToRemove,
                   net.spy.memcached.PersistTo persistTo,
                   net.spy.memcached.ReplicateTo replicateTo)
Description copied from interface: CouchbaseOperations
Remove the given object from the bucket by id.

If the object is a String, it will be treated as the document key directly.

Specified by:
remove in interface CouchbaseOperations
Parameters:
objectToRemove - the Object to remove.
persistTo - the persistence constraint setting.
replicateTo - the replication constraint setting.

remove

public void remove(Collection<?> batchToRemove,
                   net.spy.memcached.PersistTo persistTo,
                   net.spy.memcached.ReplicateTo replicateTo)
Description copied from interface: CouchbaseOperations
Remove a list of objects from the bucket by id.

Specified by:
remove in interface CouchbaseOperations
Parameters:
batchToRemove - the list of Objects to remove.
persistTo - the persistence constraint setting.
replicateTo - the replication constraint setting.

maybeEmitEvent

protected <T> void maybeEmitEvent(CouchbaseMappingEvent<T> event)
Helper method to publish an event if the event publisher is set.

Type Parameters:
T - the enclosed type.
Parameters:
event - the event to emit.

Spring Data Couchbase

Copyright © 2011-2014–2014 Pivotal Software, Inc.. All rights reserved.