com.basho.riak.client.bucket
Class DefaultBucket

java.lang.Object
  extended by com.basho.riak.client.bucket.DefaultBucket
All Implemented Interfaces:
Bucket, BucketProperties

public class DefaultBucket
extends Object
implements Bucket

Default implementation of Bucket for creating RiakOperations on k/v data and accessing BucketProperties.

Obtain a DefaultBucket from FetchBucket or WriteBucket operations from DefaultRiakClient.fetchBucket(String), DefaultRiakClient.createBucket(String)

   final String bucketName = UUID.randomUUID().toString();
   
   Bucket b = client.createBucket(bucketName).execute();
   //store something
   IRiakObject o = b.store("k", "v").execute();
   //fetch it back
   IRiakObject fetched = b.fetch("k").execute();
   // now update that riak object
   b.store("k", "my new value").execute();
   //fetch it back again
   fetched = b.fetch("k").execute();
   //delete it
   b.delete("k").execute();
 

All operations created by instances of this class are configured with the Retrier and RawClient passed at construction.

Author:
russell
See Also:
DomainBucket, RiakBucket

Constructor Summary
protected DefaultBucket(String name, BucketProperties properties, RawClient client, Retrier retrier)
          All RiakOperations created by this instance will use the RawClient and Retrier provided here.
 
Method Summary
 DeleteObject delete(String key)
          Creates a DeleteObject operation that will delete the data at key on execute().
<T> DeleteObject
delete(T o)
          Creates a DeleteObject operation that will delete the data at o's RiakKey annotated field value on execute().
 FetchObject<IRiakObject> fetch(String key)
          Creates a FetchObject that returns the data at key as an IRiakObject on execute().
<T> FetchObject<T>
fetch(String key, Class<T> type)
          Creates a FetchObject operation that returns the data at key as an instance of type T on execute().
<T> FetchObject<T>
fetch(T o)
          Creates a FetchObject operation that returns the data at o's annotated RiakKey field as an instance of type T on execute().
<T> FetchIndex<T>
fetchIndex(RiakIndex<T> index)
          Creates a FetchIndex operation for the given index name and type
 Boolean getAllowSiblings()
          The allow_mult value for the bucket.
 String getBackend()
          The backend used by this bucket.
 Boolean getBasicQuorum()
          Should a read request return early in some failure cases? E.g.
 Integer getBigVClock()
          the big_vclock property for this bucket.
 NamedErlangFunction getChashKeyFunction()
          The chash_keyfun for this bucket.
 Quorum getDW()
          The default dw quorum for this bucket.
 Boolean getLastWriteWins()
          The last_write_wins value for the bucket.
 NamedErlangFunction getLinkWalkFunction()
          The linkwalk_fun for this bucket.
 String getName()
          Get this Buckets name.
 Boolean getNotFoundOK()
          True if a vnode returning notfound for a key increments the r tally.
 Integer getNVal()
          This bucket's n_val.
 Long getOldVClock()
          the old_vclock property for this bucket.
 Collection<NamedErlangFunction> getPostcommitHooks()
          The set of postcommit hooks for this bucket.
 Quorum getPR()
          The default pr quorum for this bucket.
 Collection<NamedFunction> getPrecommitHooks()
          The set of precommit_hooks for this bucket.
 Quorum getPW()
          The default pw quorum for this bucket.
 Quorum getR()
          The default r quorum for this bucket.
 Quorum getRW()
          The default rw quorum for this bucket.
 Boolean getSearch()
          The search property
 Integer getSmallVClock()
          the small_vclock property for this bucket.
 Quorum getW()
          The default w quorum for this bucket.
 Long getYoungVClock()
          The young_vclcok property for this bucket.
 boolean isSearchEnabled()
          Is search enabled on this bucket
 Iterable<String> keys()
          Iterate over the keys for this bucket (Expensive, are you sure?) Beware: at present all RawClient.listKeys(String) operations return a stream of keys.
 StoreObject<IRiakObject> store(String key, byte[] value)
          Convenience method to create a RiakObject with a payload of application/octect-stream
 StoreObject<IRiakObject> store(String key, String value)
          Convenience methods will create an IRiakObject with value as the data payload and text/plain:charset=utf-8 as the contentType
<T> StoreObject<T>
store(String key, T o)
          Store an instance of T in Riak.
<T> StoreObject<T>
store(T o)
          Store an instance of T in Riak.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultBucket

protected DefaultBucket(String name,
                        BucketProperties properties,
                        RawClient client,
                        Retrier retrier)
All RiakOperations created by this instance will use the RawClient and Retrier provided here.

Parameters:
name - this bucket's name
properties - the BucketProperties for this bucket
client - a RawClient to use for all RiakOperations
retrier - a Retrier to use for all RiakOperations
Method Detail

getName

public String getName()
Description copied from interface: Bucket
Get this Buckets name.

Specified by:
getName in interface Bucket
Returns:
the name of the bucket

getAllowSiblings

public Boolean getAllowSiblings()
Description copied from interface: BucketProperties
The allow_mult value for the bucket.

Specified by:
getAllowSiblings in interface BucketProperties
Returns:
the allowSiblings if set, or null if not

getLastWriteWins

public Boolean getLastWriteWins()
Description copied from interface: BucketProperties
The last_write_wins value for the bucket.

Specified by:
getLastWriteWins in interface BucketProperties
Returns:
the lastWriteWins if set or null if not

getNVal

public Integer getNVal()
Description copied from interface: BucketProperties
This bucket's n_val.

Specified by:
getNVal in interface BucketProperties
Returns:
the nVal if set or null if not

getBackend

public String getBackend()
Description copied from interface: BucketProperties
The backend used by this bucket.

Specified by:
getBackend in interface BucketProperties
Returns:
the backend if set, or null.

getSmallVClock

public Integer getSmallVClock()
Description copied from interface: BucketProperties
the small_vclock property for this bucket. See controlling vector clock growth for details.

Specified by:
getSmallVClock in interface BucketProperties
Returns:
the small vector clock pruning property if set, or null.

getBigVClock

public Integer getBigVClock()
Description copied from interface: BucketProperties
the big_vclock property for this bucket. See controlling vector clock growth for details.

Specified by:
getBigVClock in interface BucketProperties
Returns:
the big vclock pruning size property if set, or null.

getYoungVClock

public Long getYoungVClock()
Description copied from interface: BucketProperties
The young_vclcok property for this bucket. See controlling vector clock growth for details.

Specified by:
getYoungVClock in interface BucketProperties
Returns:
the young vclock prune property if set, or null.

getOldVClock

public Long getOldVClock()
Description copied from interface: BucketProperties
the old_vclock property for this bucket. See controlling vector clock growth for details.

Specified by:
getOldVClock in interface BucketProperties
Returns:
the old vclock prune property if set, or null

getPrecommitHooks

public Collection<NamedFunction> getPrecommitHooks()
Description copied from interface: BucketProperties
The set of precommit_hooks for this bucket. See pre and post commit hooks for more details.

Specified by:
getPrecommitHooks in interface BucketProperties
Returns:
the precommit hooks, if any, or null

getPostcommitHooks

public Collection<NamedErlangFunction> getPostcommitHooks()
Description copied from interface: BucketProperties
The set of postcommit hooks for this bucket. See pre and post commit hooks for more details.

Specified by:
getPostcommitHooks in interface BucketProperties
Returns:
the post commit hooks, if any, or null

getR

public Quorum getR()
Description copied from interface: BucketProperties
The default r quorum for this bucket.

Specified by:
getR in interface BucketProperties
Returns:
the default CAP read quorum for this bucket, or null.

getW

public Quorum getW()
Description copied from interface: BucketProperties
The default w quorum for this bucket.

Specified by:
getW in interface BucketProperties
Returns:
the default CAP write quorum for this bucket, or null.

getRW

public Quorum getRW()
Description copied from interface: BucketProperties
The default rw quorum for this bucket.

Specified by:
getRW in interface BucketProperties
Returns:
the default CAP RW (delete) quorum for this bucket, or null.

getDW

public Quorum getDW()
Description copied from interface: BucketProperties
The default dw quorum for this bucket.

Specified by:
getDW in interface BucketProperties
Returns:
the default CAP durable write quorum for this bucket, or null.

getPR

public Quorum getPR()
Description copied from interface: BucketProperties
The default pr quorum for this bucket.

Specified by:
getPR in interface BucketProperties
Returns:
the default number of partitions in the primary preference list that must return from read request, for this bucket, or null.

getPW

public Quorum getPW()
Description copied from interface: BucketProperties
The default pw quorum for this bucket.

Specified by:
getPW in interface BucketProperties
Returns:
the default number of partitions in the primary preference list that must return from a write request, for this bucket, or null.

getBasicQuorum

public Boolean getBasicQuorum()
Description copied from interface: BucketProperties
Should a read request return early in some failure cases? E.g. If a quorum of nodes has already returned notfound/error, don't wait around for the rest.

Specified by:
getBasicQuorum in interface BucketProperties
Returns:
the default basic_quorum value for this bucket, or null.

getNotFoundOK

public Boolean getNotFoundOK()
Description copied from interface: BucketProperties
True if a vnode returning notfound for a key increments the r tally. False is higher consistency, true is higher availability.

Specified by:
getNotFoundOK in interface BucketProperties
Returns:
the default notfound_ok value for the bucket, or null.

getChashKeyFunction

public NamedErlangFunction getChashKeyFunction()
Description copied from interface: BucketProperties
The chash_keyfun for this bucket.

Specified by:
getChashKeyFunction in interface BucketProperties
Returns:
the key hashing function for the bucket, or null.

getLinkWalkFunction

public NamedErlangFunction getLinkWalkFunction()
Description copied from interface: BucketProperties
The linkwalk_fun for this bucket.

Specified by:
getLinkWalkFunction in interface BucketProperties
Returns:
the link walking function for the bucket, or null.

getSearch

public Boolean getSearch()
Description copied from interface: BucketProperties
The search property

Specified by:
getSearch in interface BucketProperties
Returns:
true/false/null

isSearchEnabled

public boolean isSearchEnabled()
Description copied from interface: BucketProperties
Is search enabled on this bucket

Specified by:
isSearchEnabled in interface BucketProperties
Returns:
true/false

keys

public Iterable<String> keys()
                      throws RiakException
Iterate over the keys for this bucket (Expensive, are you sure?) Beware: at present all RawClient.listKeys(String) operations return a stream of keys. The stream is closed automatically when the iteratore is weakly reachable. Do not retain a reference to this Iterable after you have used it.

Specified by:
keys in interface Bucket
Returns:
an Iterable of Strings.
Throws:
RiakException
See Also:
RawClient.listKeys(String)

store

public StoreObject<IRiakObject> store(String key,
                                      byte[] value)
Convenience method to create a RiakObject with a payload of application/octect-stream

For example, to get a new IRiakObject into Riak.

 IRiakObject myNewObject = bucket.store("k", myByteArray)
                              .w(2)  // tunable CAP write quorum
                              .returnBody(true) // return the IRiakObject from the store
                              .execute(); // perform the operation.
 

Creates a StoreObject operation configured with a Mutation that copies value and DefaultRiakObject.DEFAULT_CONTENT_TYPE over the any existing value at key or creates a new DefaultRiakObject with value and DefaultRiakObject.DEFAULT_CONTENT_TYPE.

The StoreObject is configured with the DefaultResolver which means the presence of siblings triggers a UnresolvedConflictException

The StoreObject is configured with a Converter that simply returns what it is given (IE does no conversion).

Specified by:
store in interface Bucket
Parameters:
key - the key to store the object under.
value - a byte[] of the objects value.
Returns:
a StoreObject configured to store value at key on execute().
See Also:
StoreObject

store

public StoreObject<IRiakObject> store(String key,
                                      String value)
Convenience methods will create an IRiakObject with value as the data payload and text/plain:charset=utf-8 as the contentType

For example, to get a new IRiakObject into Riak.

 IRiakObject myNewObject = bucket.store("k", "myValue")
                              .w(2)  // tunable CAP write quorum
                              .returnBody(true) // return the IRiakObject from the store
                              .execute(); // perform the operation.
 

Creates a StoreObject operation configured with a Mutation that copies value and Constants.CTYPE_TEXT_UTF8 over the any existing value at key or creates a new DefaultRiakObject with value and Constants.CTYPE_TEXT_UTF8.

The StoreObject is configured with the DefaultResolver which means the presence of siblings triggers a UnresolvedConflictException

The StoreObject is configured with a Converter that simply returns what it is given (IE does no conversion).

Specified by:
store in interface Bucket
Parameters:
key - the key to store the object under.
value - a String of the data to store
Returns:
a StoreObject configured to store value at key on execute().
See Also:
StoreObject

store

public <T> StoreObject<T> store(T o)
Store an instance of T in Riak. Depends on the Converter provided to StoreObject to convert o from T to IRiakObject.

T must have a field annotated with RiakKey as the Key to store this data under.

Creates a StoreObject operation configured with the JSONConverter the ClobberMutation and DefaultResolver.

Specified by:
store in interface Bucket
Type Parameters:
T - the Type of o
Parameters:
o - the data to store
Returns:
a StoreObject configured to store o at the RiakKey annotated key on execute().
See Also:
StoreObject, DomainBucket

store

public <T> StoreObject<T> store(String key,
                                T o)
Store an instance of T in Riak. Depends on the Converter provided to StoreObject to convert o from T to IRiakObject.

Creates a StoreObject operation configured with the JSONConverter the ClobberMutation and DefaultResolver.

Specified by:
store in interface Bucket
Type Parameters:
T - the Type of o
Parameters:
o - the data to store
key - the key
Returns:
a StoreObject configured to store o at the RiakKey annotated key on execute().
See Also:
StoreObject, DomainBucket

fetch

public <T> FetchObject<T> fetch(T o)
Creates a FetchObject operation that returns the data at o's annotated RiakKey field as an instance of type T on execute().

Creates a FetchObject operation configured with the JSONConverter and DefaultResolver.

Specified by:
fetch in interface Bucket
Type Parameters:
T - the Type to return
Parameters:
o - an instance ot T that has the key annotated with RiakKey
Returns:
a FetchObject
See Also:
FetchObject

fetch

public <T> FetchObject<T> fetch(String key,
                                Class<T> type)
Creates a FetchObject operation that returns the data at key as an instance of type T on execute().

Creates a FetchObject operation configured with the JSONConverter and DefaultResolver.

Specified by:
fetch in interface Bucket
Type Parameters:
T - the Type to return
Parameters:
key - the key under which the data is stored
type - the Class of the type to return
Returns:
a FetchObject
See Also:
FetchObject

fetch

public FetchObject<IRiakObject> fetch(String key)
Creates a FetchObject that returns the data at key as an IRiakObject on execute().

Creates a FetchObject with the DefaultResolver and a Converter that does nothing to the IRiakObject.

Specified by:
fetch in interface Bucket
Parameters:
key - the key
Returns:
a FetchObject
See Also:
FetchObject

delete

public <T> DeleteObject delete(T o)
Description copied from interface: Bucket
Creates a DeleteObject operation that will delete the data at o's RiakKey annotated field value on execute().

Specified by:
delete in interface Bucket
Type Parameters:
T - the Type of o
Parameters:
o - an instance of T with a value for the key in the field annotated by RiakKey
Returns:
a DeleteObject
See Also:
DeleteObject

delete

public DeleteObject delete(String key)
Description copied from interface: Bucket
Creates a DeleteObject operation that will delete the data at key on execute().

Specified by:
delete in interface Bucket
Returns:
a DeleteObject
See Also:
DeleteObject

fetchIndex

public <T> FetchIndex<T> fetchIndex(RiakIndex<T> index)
Description copied from interface: Bucket
Creates a FetchIndex operation for the given index name and type

Specified by:
fetchIndex in interface Bucket
Type Parameters:
T - the index type (currently String or Integer)
Parameters:
index - an index
Returns:
a FetchIndex operation for further configuration and execution


Copyright © 2012. All Rights Reserved.