public class DefaultBucket extends Object implements Bucket
Bucket
for creating RiakOperation
s
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 RiakOperation
sretrier
- a Retrier
to use for all RiakOperation
spublic Boolean getAllowSiblings()
BucketProperties
getAllowSiblings
in interface BucketProperties
public Boolean getLastWriteWins()
BucketProperties
getLastWriteWins
in interface BucketProperties
public Integer getNVal()
BucketProperties
getNVal
in interface BucketProperties
public String getBackend()
BucketProperties
getBackend
in interface BucketProperties
public Integer getSmallVClock()
BucketProperties
getSmallVClock
in interface BucketProperties
public Integer getBigVClock()
BucketProperties
getBigVClock
in interface BucketProperties
public Long getYoungVClock()
BucketProperties
getYoungVClock
in interface BucketProperties
public Long getOldVClock()
BucketProperties
getOldVClock
in interface BucketProperties
public Collection<NamedFunction> getPrecommitHooks()
BucketProperties
getPrecommitHooks
in interface BucketProperties
public Collection<NamedErlangFunction> getPostcommitHooks()
BucketProperties
getPostcommitHooks
in interface BucketProperties
public Quorum getR()
BucketProperties
r
quorum for this bucket.getR
in interface BucketProperties
public Quorum getW()
BucketProperties
w
quorum for this bucket.getW
in interface BucketProperties
public Quorum getRW()
BucketProperties
rw
quorum for this bucket.getRW
in interface BucketProperties
public Quorum getDW()
BucketProperties
dw
quorum for this bucket.getDW
in interface BucketProperties
public Quorum getPR()
BucketProperties
pr
quorum for this bucket.getPR
in interface BucketProperties
public Quorum getPW()
BucketProperties
pw
quorum for this bucket.getPW
in interface BucketProperties
public Boolean getBasicQuorum()
BucketProperties
getBasicQuorum
in interface BucketProperties
public Boolean getNotFoundOK()
BucketProperties
getNotFoundOK
in interface BucketProperties
public NamedErlangFunction getChashKeyFunction()
BucketProperties
getChashKeyFunction
in interface BucketProperties
public NamedErlangFunction getLinkWalkFunction()
BucketProperties
getLinkWalkFunction
in interface BucketProperties
public Boolean getSearch()
BucketProperties
getSearch
in interface BucketProperties
public boolean isSearchEnabled()
BucketProperties
isSearchEnabled
in interface BucketProperties
public 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 Bucket
Iterable
of Strings.RiakException
RawClient.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 Bucket
key
- the key to store the object under.value
- a byte[] of the objects value.StoreObject
configured to store value
at
key
on execute()
.StoreObject
public 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 Bucket
key
- the key to store the object under.value
- a String of the data to storeStoreObject
configured to store value
at
key
on execute()
.StoreObject
public <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 Bucket
T
- the Type of o
o
- the data to storeStoreObject
configured to store o
at the
RiakKey
annotated key
on
execute()
.StoreObject
,
DomainBucket
public <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 Bucket
T
- the Type of o
o
- the data to storekey
- the keyStoreObject
configured to store o
at the
RiakKey
annotated key
on
execute()
.StoreObject
,
DomainBucket
public <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 Bucket
T
- the Type to returno
- an instance ot T
that has the key annotated with
RiakKey
FetchObject
FetchObject
public <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 Bucket
T
- the Type to returnkey
- the key under which the data is storedtype
- the Class of the type to returnFetchObject
FetchObject
public 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 Bucket
key
- the keyFetchObject
FetchObject
public <T> DeleteObject delete(T o)
Bucket
DeleteObject
operation that will delete the data at
o
's RiakKey
annotated field value on
execute()
.delete
in interface Bucket
T
- the Type of o
o
- an instance of T
with a value for the key in the
field annotated by RiakKey
DeleteObject
DeleteObject
public DeleteObject delete(String key)
Bucket
delete
in interface Bucket
DeleteObject
DeleteObject
public <T> FetchIndex<T> fetchIndex(RiakIndex<T> index)
Bucket
FetchIndex
operation for the given index name and typefetchIndex
in interface Bucket
T
- the index type (currently String or Long)index
- an indexFetchIndex
operation for further configuration and
executionpublic MultiFetchObject<IRiakObject> multiFetch(String[] keys)
multiFetch
in interface Bucket
keys
- the keysMultiFetchObject
Bucket.multiFetch(java.lang.String[])
public <T> MultiFetchObject<T> multiFetch(List<String> keys, Class<T> type)
multiFetch
in interface Bucket
T
- the Type to returnkeys
- the list of keys under which the data is storedtype
- the Class of the type to returnMultiFetchObject
Bucket.multiFetch(java.util.List, java.lang.Class)
public <T> MultiFetchObject<T> multiFetch(List<T> objs)
multiFetch
in interface Bucket
T
- the Type to returnobjs
- a List of T
that has the keys annotated with
RiakKey
MultiFetchObject
Bucket.multiFetch(java.util.List)
public CounterObject counter(String counter)
Bucket
CounterObject
operationcounter
in interface Bucket
counter
- the name (key) for the counterCounterObject
Copyright © 2013. All Rights Reserved.