allow remove with both string id and object.

This commit is contained in:
Michael Nitschinger
2013-05-29 12:34:52 +02:00
parent e44e01559e
commit 74e9a86f82
2 changed files with 13 additions and 0 deletions

View File

@@ -127,6 +127,9 @@ public 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.
*
* @param object the Object to remove.
*/
void remove(Object object);

View File

@@ -163,6 +163,16 @@ public class CouchbaseTemplate implements CouchbaseOperations {
public void remove(final Object objectToRemove) {
ensureNotIterable(objectToRemove);
if (objectToRemove instanceof String) {
execute(new BucketCallback<OperationFuture<Boolean>>() {
@Override
public OperationFuture<Boolean> doInBucket() {
return client.delete((String) objectToRemove);
}
});
return;
}
final ConvertedCouchbaseDocument converted = new ConvertedCouchbaseDocument();
couchbaseConverter.write(objectToRemove, converted);