public class DefaultRiakObject extends Object implements IRiakObject
IRiakObject
Is as immutable as possible. Value
, content-type
, links
and user meta data
are all mutable.
It is safe to use the instances of this class from multiple threads.
Due to the large number of arguments to the constructor the *best* way to create instances is with a RiakObjectBuilder
.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_CONTENT_TYPE
The default content type assigned when persisted in Riak if non is provided.
|
Constructor and Description |
---|
DefaultRiakObject(String bucket,
String key,
VClock vclock,
String vtag,
Date lastModified,
String contentType,
byte[] value,
Collection<RiakLink> links,
Map<String,String> userMeta,
RiakIndexes indexes,
boolean isDeleted)
Large number of arguments due to largely immutable nature.
|
Modifier and Type | Method and Description |
---|---|
IRiakObject |
addIndex(String index,
long value)
Add an int index to this objects indexes.
|
IRiakObject |
addIndex(String index,
String value)
Add a String index to this objects indexes.
|
IRiakObject |
addLink(RiakLink link)
Add link to this RiakObject's links.
|
IRiakObject |
addUsermeta(String key,
String value)
Adds the key, value to the collection of user meta data for this object.
|
Map<BinIndex,Set<String>> |
allBinIndexes()
Secondary indexes for this object.
|
Map<IntIndex,Set<Integer>> |
allIntIndexes()
Deprecated.
|
Map<IntIndex,Set<Long>> |
allIntIndexesV2()
Secondary indexes for this object.
|
Set<String> |
getBinIndex(String name)
Get a copy of the values for the given bin index
|
String |
getBucket()
The name of this objects bucket
|
String |
getContentType()
The content-type of this object's value.
|
Set<Integer> |
getIntIndex(String name)
Deprecated.
|
Set<Long> |
getIntIndexV2(String name)
Get a copy of the values for the given int_ index
|
String |
getKey()
The object's key.
|
Date |
getLastModified()
The last modified date as held by Riak.
|
List<RiakLink> |
getLinks()
A List of
RiakLink s from this object. |
Map<String,String> |
getMeta()
NOTE: a copy is returned.
|
String |
getUsermeta(String key)
Get the user meta data item for that key.
|
byte[] |
getValue()
The value.
|
String |
getValueAsString()
Convenience method.
|
VClock |
getVClock()
This objects Vector Clock.
|
String |
getVClockAsString()
String copy of this object's vector clock.
|
String |
getVtag()
If this object has a version tag (if it is one of a set of siblings)
|
boolean |
hasLink(RiakLink riakLink)
Does this object have that link?
|
boolean |
hasLinks()
Does this object link to any others?
|
boolean |
hasUsermeta()
Does this object have any user meta data?
|
boolean |
hasUsermeta(String key)
Does this object have a meta data item for that key?
|
boolean |
isDeleted()
Check to see if this object is a tombstone (deleted)
Note: The request has to have been made specifying tombstones
(deleted vclocks) are to be returned.
|
Iterator<RiakLink> |
iterator()
an
UnmodifiableIterator view on the RiakLinks |
int |
numLinks()
How many
RiakLink s does this object have. |
IRiakObject |
removeBinIndex(String index)
Remove a
BinIndex from this RiakObject. |
IRiakObject |
removeIntIndex(String index)
Remove a
IntIndex from this RiakObject. |
IRiakObject |
removeLink(RiakLink link)
Remove a
RiakLink from this RiakObject. |
IRiakObject |
removeUsermeta(String key)
Remove that item of user meta data.
|
void |
setContentType(String contentType)
Set the content-type of this object's payload.
|
void |
setValue(byte[] value)
Note: Copies the value.
|
void |
setValue(String value)
Convenience method that will result in value being turned into a byte[]
array using charset utf-8 and also will result in charset=utf-8 being
appended to the content-type for this object
|
Iterable<Map.Entry<String,String>> |
userMetaEntries()
return an unmodifiable view of the user meta entries.
|
public static String DEFAULT_CONTENT_TYPE
public DefaultRiakObject(String bucket, String key, VClock vclock, String vtag, Date lastModified, String contentType, byte[] value, Collection<RiakLink> links, Map<String,String> userMeta, RiakIndexes indexes, boolean isDeleted)
RiakObjectBuilder
to create instances.bucket
- the bucket the object is stored inkey
- the key it is stored undervclock
- the vclock, if availablevtag
- the version tag, if relevantlastModified
- the last modified date from Riak (if relevant)contentType
- the content-type of the valuevalue
- a byte[] of the data payload to store in Riak. Note: this is cloned on construction of this instance.links
- the List of RiakLink
s from this object. Note: this is copied.userMeta
- the Map
of user meta data to store/stored with this object. Note: this is copied.indexes
- the RiakIndexes
for this object. These will be copied to a new RiakIndexes
public String getBucket()
IRiakObject
getBucket
in interface IRiakObject
public VClock getVClock()
IRiakObject
getVClock
in interface IRiakObject
VClock
for this object.public String getKey()
IRiakObject
getKey
in interface IRiakObject
public String getVtag()
IRiakObject
getVtag
in interface IRiakObject
public Date getLastModified()
IRiakObject
getLastModified
in interface IRiakObject
public String getContentType()
IRiakObject
getContentType
in interface IRiakObject
DEFAULT_CONTENT_TYPE
public Map<String,String> getMeta()
getMeta
in interface IRiakObject
Map
of meta data for this object.IRiakObject.getMeta()
public byte[] getValue()
IRiakObject
getValue
in interface IRiakObject
IRiakObject.getValue()
public void setValue(byte[] value)
setValue
in interface IRiakObject
a
- byte[] to store in Riak.public void setValue(String value)
IRiakObject
setValue
in interface IRiakObject
value
- the String valuepublic void setContentType(String contentType)
IRiakObject
setContentType
in interface IRiakObject
contentType
- the content-type of this object's value (EG
text/plain;charset=utf-8)public Iterator<RiakLink> iterator()
UnmodifiableIterator
view on the RiakLinkspublic IRiakObject addLink(RiakLink link)
IRiakObject
addLink
in interface IRiakObject
link
- a RiakLink
to add.public IRiakObject removeLink(RiakLink link)
IRiakObject
RiakLink
from this RiakObject.removeLink
in interface IRiakObject
link
- the RiakLink
to removepublic boolean hasLinks()
IRiakObject
hasLinks
in interface IRiakObject
public int numLinks()
IRiakObject
RiakLink
s does this object have.numLinks
in interface IRiakObject
public List<RiakLink> getLinks()
IRiakObject
RiakLink
s from this object. See also Link Walking on the basho
site.getLinks
in interface IRiakObject
RiakLink
,
LinkWalk
public boolean hasLink(RiakLink riakLink)
IRiakObject
hasLink
in interface IRiakObject
riakLink
- a RiakLink
RiakLink
, false otherwise.public IRiakObject addUsermeta(String key, String value)
IRiakObject
addUsermeta
in interface IRiakObject
public boolean hasUsermeta()
IRiakObject
hasUsermeta
in interface IRiakObject
public boolean hasUsermeta(String key)
IRiakObject
hasUsermeta
in interface IRiakObject
public String getUsermeta(String key)
IRiakObject
getUsermeta
in interface IRiakObject
key
- the name of the user meta data itempublic IRiakObject removeUsermeta(String key)
IRiakObject
removeUsermeta
in interface IRiakObject
key
- the key of the item to removepublic Iterable<Map.Entry<String,String>> userMetaEntries()
userMetaEntries
in interface IRiakObject
Map.Entry
public String getVClockAsString()
IRiakObject
getVClockAsString
in interface IRiakObject
public String getValueAsString()
IRiakObject
getValueAsString
in interface IRiakObject
public Map<BinIndex,Set<String>> allBinIndexes()
IRiakObject
allBinIndexes
in interface IRiakObject
public Set<String> getBinIndex(String name)
IRiakObject
getBinIndex
in interface IRiakObject
name
- the index name@Deprecated public Map<IntIndex,Set<Integer>> allIntIndexes()
allIntIndexes
in interface IRiakObject
IRiakObject.allIntIndexesV2()
public Map<IntIndex,Set<Long>> allIntIndexesV2()
IRiakObject
allIntIndexesV2
in interface IRiakObject
@Deprecated public Set<Integer> getIntIndex(String name)
getIntIndex
in interface IRiakObject
IRiakObject.getIntIndexV2(java.lang.String)
public Set<Long> getIntIndexV2(String name)
IRiakObject
getIntIndexV2
in interface IRiakObject
name
- the index namepublic IRiakObject addIndex(String index, String value)
IRiakObject
addIndex
in interface IRiakObject
index
- index namevalue
- index valuepublic IRiakObject addIndex(String index, long value)
IRiakObject
addIndex
in interface IRiakObject
index
- index namevalue
- index valuepublic IRiakObject removeBinIndex(String index)
IRiakObject
BinIndex
from this RiakObject.removeBinIndex
in interface IRiakObject
index
- the name of the bin index to removepublic IRiakObject removeIntIndex(String index)
IRiakObject
IntIndex
from this RiakObject.removeIntIndex
in interface IRiakObject
index
- the name of the int index to removepublic boolean isDeleted()
IRiakObject
isDeleted
in interface IRiakObject
com.basho.riak.client.operations.FetchObject#returnDeletedVClock(boolean)
,
com.basho.riak.client.operations.StoreObject#returnDeletedVClock(boolean)
Copyright © 2013. All Rights Reserved.