public class DefaultBucket extends Object implements Bucket
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.
DomainBucket,
RiakBucket| Modifier | Constructor and Description |
|---|---|
protected |
DefaultBucket(String name,
BucketProperties properties,
RawClient client,
Retrier retrier)
|
| Modifier and Type | Method and Description |
|---|---|
CounterObject |
counter(String counter)
Creates a
CounterObject operation |
DeleteObject |
delete(String key)
|
<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)
|
<T> FetchObject<T> |
fetch(String key,
Class<T> type)
|
<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
|
StreamingOperation<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. |
<T> MultiFetchObject<T> |
multiFetch(List<String> keys,
Class<T> type)
(non-Javadoc)
|
<T> MultiFetchObject<T> |
multiFetch(List<T> objs)
(non-Javadoc)
|
MultiFetchObject<IRiakObject> |
multiFetch(String[] keys)
(non-Javadoc)
|
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. |
protected DefaultBucket(String name, BucketProperties properties, RawClient client, Retrier retrier)
name - this bucket's nameproperties - the BucketProperties for this bucketclient - a RawClient to use for all RiakOperationsretrier - a Retrier to use for all RiakOperationspublic Boolean getAllowSiblings()
BucketPropertiesgetAllowSiblings in interface BucketPropertiespublic Boolean getLastWriteWins()
BucketPropertiesgetLastWriteWins in interface BucketPropertiespublic Integer getNVal()
BucketPropertiesgetNVal in interface BucketPropertiespublic String getBackend()
BucketPropertiesgetBackend in interface BucketPropertiespublic Integer getSmallVClock()
BucketPropertiesgetSmallVClock in interface BucketPropertiespublic Integer getBigVClock()
BucketPropertiesgetBigVClock in interface BucketPropertiespublic Long getYoungVClock()
BucketPropertiesgetYoungVClock in interface BucketPropertiespublic Long getOldVClock()
BucketPropertiesgetOldVClock in interface BucketPropertiespublic Collection<NamedFunction> getPrecommitHooks()
BucketPropertiesgetPrecommitHooks in interface BucketPropertiespublic Collection<NamedErlangFunction> getPostcommitHooks()
BucketPropertiesgetPostcommitHooks in interface BucketPropertiespublic Quorum getR()
BucketPropertiesr quorum for this bucket.getR in interface BucketPropertiespublic Quorum getW()
BucketPropertiesw quorum for this bucket.getW in interface BucketPropertiespublic Quorum getRW()
BucketPropertiesrw quorum for this bucket.getRW in interface BucketPropertiespublic Quorum getDW()
BucketPropertiesdw quorum for this bucket.getDW in interface BucketPropertiespublic Quorum getPR()
BucketPropertiespr quorum for this bucket.getPR in interface BucketPropertiespublic Quorum getPW()
BucketPropertiespw quorum for this bucket.getPW in interface BucketPropertiespublic Boolean getBasicQuorum()
BucketPropertiesgetBasicQuorum in interface BucketPropertiespublic Boolean getNotFoundOK()
BucketPropertiesgetNotFoundOK in interface BucketPropertiespublic NamedErlangFunction getChashKeyFunction()
BucketPropertiesgetChashKeyFunction in interface BucketPropertiespublic NamedErlangFunction getLinkWalkFunction()
BucketPropertiesgetLinkWalkFunction in interface BucketPropertiespublic Boolean getSearch()
BucketPropertiesgetSearch in interface BucketPropertiespublic boolean isSearchEnabled()
BucketPropertiesisSearchEnabled in interface BucketPropertiespublic StreamingOperation<String> keys() throws RiakException
RawClient.listKeys(String) operations return a
stream of keys.
You *must* call StreamingOperation.cancel() on the returned
StreamingOperation if you do not iterate through the entire set.
As a safeguard the stream is closed automatically when the iterator is
weakly reachable but due to the nature of the GC it is inadvisable to
rely on this to close the iterator. Do not retain a reference to this Iterable
after you have used it.keys in interface BucketIterable of Strings.RiakExceptionRawClient.listKeys(String)public StoreObject<IRiakObject> store(String key, byte[] value)
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).
store in interface Bucketkey - the key to store the object under.value - a byte[] of the objects value.StoreObject configured to store value at
key on execute().StoreObjectpublic StoreObject<IRiakObject> store(String key, String value)
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).
store in interface Bucketkey - the key to store the object under.value - a String of the data to storeStoreObject configured to store value at
key on execute().StoreObjectpublic <T> StoreObject<T> store(T o)
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.
store in interface BucketT - the Type of oo - the data to storeStoreObject configured to store o at the
RiakKey annotated key on
execute().StoreObject,
DomainBucketpublic <T> StoreObject<T> store(String key, T o)
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.
store in interface BucketT - the Type of oo - the data to storekey - the keyStoreObject configured to store o at the
RiakKey annotated key on
execute().StoreObject,
DomainBucketpublic <T> FetchObject<T> fetch(T o)
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.
fetch in interface BucketT - the Type to returno - an instance ot T that has the key annotated with
RiakKeyFetchObjectFetchObjectpublic <T> FetchObject<T> fetch(String key, Class<T> type)
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.
fetch in interface BucketT - the Type to returnkey - the key under which the data is storedtype - the Class of the type to returnFetchObjectFetchObjectpublic FetchObject<IRiakObject> fetch(String key)
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.
fetch in interface Bucketkey - the keyFetchObjectFetchObjectpublic <T> DeleteObject delete(T o)
BucketDeleteObject operation that will delete the data at
o's RiakKey annotated field value on
execute().delete in interface BucketT - the Type of oo - an instance of T with a value for the key in the
field annotated by RiakKeyDeleteObjectDeleteObjectpublic DeleteObject delete(String key)
Bucketdelete in interface BucketDeleteObjectDeleteObjectpublic <T> FetchIndex<T> fetchIndex(RiakIndex<T> index)
BucketFetchIndex operation for the given index name and typefetchIndex in interface BucketT - the index type (currently String or Long)index - an indexFetchIndex operation for further configuration and
executionpublic MultiFetchObject<IRiakObject> multiFetch(String[] keys)
multiFetch in interface Bucketkeys - the keysMultiFetchObjectBucket.multiFetch(java.lang.String[])public <T> MultiFetchObject<T> multiFetch(List<String> keys, Class<T> type)
multiFetch in interface BucketT - the Type to returnkeys - the list of keys under which the data is storedtype - the Class of the type to returnMultiFetchObjectBucket.multiFetch(java.util.List, java.lang.Class)public <T> MultiFetchObject<T> multiFetch(List<T> objs)
multiFetch in interface BucketT - the Type to returnobjs - a List of T that has the keys annotated with
RiakKeyMultiFetchObjectBucket.multiFetch(java.util.List)public CounterObject counter(String counter)
BucketCounterObject operationcounter in interface Bucketcounter - the name (key) for the counterCounterObjectCopyright © 2014. All Rights Reserved.