com.basho.riak.client.bucket
Class DomainBucket<T>

java.lang.Object
  extended by com.basho.riak.client.bucket.DomainBucket<T>

public class DomainBucket<T>
extends Object

A domain bucket is a wrapper around a Bucket that is strongly typed and uses a preset ConflictResolver, MutationProducer, Converter, r, w, dw, rw, Retrier, returnBody etc

If you are working with one specific type of data only it can be simpler to create a DomainBucket around your bucket. It reduces the amount of code since the Converter, Mutation, Retrier and ConflictResolver are likely to be the same for each operation.

Example:

 final Bucket b = client.createBucket(bucketName).allowSiblings(true).nVal(3).execute();
 
 final DomainBucket carts = DomainBucket.builder(b, ShoppingCart.class)
          .withResolver(new MergeCartResolver())
          .returnBody(true)
          .retrier(DefaultRetrier.attempts(3))
          .w(1)
          .dw(1)
          .r(1)
          .rw(1)
          .build();
 
  final ShoppingCart cart = new ShoppingCart(userId);
 
  cart.addItem("coffee");
  cart.addItem("fixie");
  cart.addItem("moleskine");
 
  final ShoppingCart storedCart = carts.store(cart);
  ShoppinCart cart2 = carts.fetch("userX");
  cart.addItem("toaster");
  carts.store(cart2);
  //etc
 

Author:
russell
See Also:
RiakBucket, DomainBucketBuilder

Constructor Summary
DomainBucket(Bucket bucket, ConflictResolver<T> resolver, Converter<T> converter, MutationProducer<T> mutationProducer, StoreMeta storeMeta, FetchMeta fetchMeta, DeleteMeta deleteMeta, Class<T> clazz, Retrier retrier)
          Create a new DomainBucket for clazz Class objects wrapped around bucket It is recommended to use the DomainBucketBuilder rather than this constructor.
 
Method Summary
static
<T> DomainBucketBuilder<T>
builder(Bucket b, Class<T> clazz)
          Factory method to create a new DomainBucketBuilder for the given Bucket and Class.
 void delete(String key)
          Delete the key/value stored at the key
 void delete(T o)
          Delete the key/value stored at the key extracted from o's RiakKey annotated field.
 T fetch(String key)
          Fetch data stored at key in this bucket as an instance of T.
 T fetch(T o)
          Fetch data stored at the key extracted from o's RiakKey annotated field as an instance of T.
 T store(T o)
          Store o in Riak.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomainBucket

public DomainBucket(Bucket bucket,
                    ConflictResolver<T> resolver,
                    Converter<T> converter,
                    MutationProducer<T> mutationProducer,
                    StoreMeta storeMeta,
                    FetchMeta fetchMeta,
                    DeleteMeta deleteMeta,
                    Class<T> clazz,
                    Retrier retrier)
Create a new DomainBucket for clazz Class objects wrapped around bucket It is recommended to use the DomainBucketBuilder rather than this constructor.

Parameters:
bucket - The bucket to wrap.
resolver - the ConflictResolver
converter - the Converter to use
mutationProducer - the MutationProducer to use
storeMeta - the set of store parameters
fetchMeta - the set of fetch parameters
deleteMeta - the set of delete parameters
clazz - the Class type of the DomainBucket
retrier - the Retrier to use for each operation
Method Detail

store

public T store(T o)
        throws RiakException
Store o in Riak. T must have a field annotated with RiakKey.

This is equivalent to creating and executing a StoreObject operation with the Converter, ConflictResolver, Retrier, and a Mutation (from calling MutationProducer.produce(Object) on o), r, w, dw etc. passed when the DomainBucket was constructed.

Parameters:
o - instance of to store.
Returns:
stored instance of T
Throws:
RiakException

fetch

public T fetch(String key)
        throws RiakException
Fetch data stored at key in this bucket as an instance of T.

This is equivalent to creating and executing a FetchObject configured with the Converter, ConflictResolver, Retrier and r value specified in the constructor.

Parameters:
key -
Returns:
Throws:
RiakException

fetch

public T fetch(T o)
        throws RiakException
Fetch data stored at the key extracted from o's RiakKey annotated field as an instance of T.

This is equivalent to creating and executing a FetchObject configured with the Converter, ConflictResolver, Retrier and r value specified in the constructor.

Parameters:
key -
Returns:
Throws:
RiakException

delete

public void delete(T o)
            throws RiakException
Delete the key/value stored at the key extracted from o's RiakKey annotated field.

This is equivalent to creating and executing a DeleteObject configured with the Retrier and r value specified in the constructor.

Parameters:
key -
Throws:
RiakException

delete

public void delete(String key)
            throws RiakException
Delete the key/value stored at the key

This is equivalent to creating and executing a DeleteObject configured with the Retrier and r value specified in the constructor.

Parameters:
key -
Throws:
RiakException

builder

public static <T> DomainBucketBuilder<T> builder(Bucket b,
                                                 Class<T> clazz)
Factory method to create a new DomainBucketBuilder for the given Bucket and Class.

Parameters:
b - the Bucket to wrap
clazz - the type of object to store/fetch with the new DomainBucket
Returns:
a DomainBucketBuilder for the wrapped bucket


Copyright © 2012. All Rights Reserved.