public abstract class RiakIndex<T> extends Object implements Iterable<T>
Secondary Indexing (2i) in Riak gives developers the ability, at write time, to tag an object stored in Riak with one or more queryable values. Since the KV data is completely opaque to 2i, the user must tell 2i exactly what attribute to index on and what its index value should be, via key/value metadata. This is different from Search, which parses the data and builds indexes based on a schema. Riak 2i currently requires the LevelDB or Memory backend.
A RiakIndex
is made up of the index name, a type,
then one or more queryable index values.
RiakIndex
instances are created and managed via the RiakIndexes
container.
RiakIndexes
,
Using Secondary
Indexes in RiakThis class is designed to be thread safe. |
Modifier and Type | Class and Description |
---|---|
static class |
RiakIndex.Name<T extends RiakIndex>
Abstract base class used to encapsulate a
RiakIndex name and type. |
Modifier | Constructor and Description |
---|---|
protected |
RiakIndex(RiakIndex.Name<?> name)
Constructs a RiakIndex from the supplied RiakIndex.Name
|
Modifier and Type | Method and Description |
---|---|
RiakIndex<T> |
add(Collection<T> values)
Add a asSet of values to this secondary index.
|
RiakIndex<T> |
add(T value)
Add a value to this secondary index.
|
protected abstract T |
convert(BinaryValue value)
Convert bytes to a value type.
|
protected abstract BinaryValue |
convert(T value)
Convert a value to a BinaryValue.
|
boolean |
equals(Object obj)
Indicates whether this RiakIndex is "equal to" another RiakIndex.
|
String |
getFullname()
Get the fully qualified name of this index
|
String |
getName()
Get the index's name.
|
IndexType |
getType()
Get the type of this index.
|
int |
hashCode()
Returns a hash code value for the object.
|
boolean |
hasValue(T value)
Determine if this index contains a value
|
boolean |
isEmpty()
Determine if this index has any values.
|
Iterator<T> |
iterator()
Returns an iterator over the asSet of values in this index.
|
Set<BinaryValue> |
rawValues()
Return the values in this index as raw bytes.
|
RiakIndex<T> |
remove(Collection<T> values)
Remove a asSet of values from this index
|
RiakIndex<T> |
remove(T value)
Remove a value from this index.
|
RiakIndex<T> |
removeAll()
Remove all values from this index
|
int |
size()
Return the number of values in this index.
|
String |
toString() |
Set<T> |
values()
Return the values in this index.
|
protected RiakIndex(RiakIndex.Name<?> name)
name
- A RiakIndex.Name
to build this RiakIndex from.public final RiakIndex<T> add(T value)
value
- the value to addpublic final RiakIndex<T> add(Collection<T> values)
values
- a collection of values to addpublic final boolean hasValue(T value)
value
- the value to check fortrue
if this index contains the value, false
otherwise.public final RiakIndex<T> remove(T value)
value
- the value to removepublic final RiakIndex<T> remove(Collection<T> values)
values
- a collection of values to removepublic final RiakIndex<T> removeAll()
public final Iterator<T> iterator()
ConcurrentModificationException
, and guarantees to traverse elements
as they existed upon construction of the iterator, and may (but is not guaranteed to)
reflect any modifications subsequent to construction.public final int size()
public final boolean isEmpty()
true
if this index has no values, false
otherwise.public final Set<BinaryValue> rawValues()
public final Set<T> values()
Set
is unmodifiable.public final IndexType getType()
public final String getName()
public final String getFullname()
protected abstract BinaryValue convert(T value)
Index values are stored internally as bytes. Concrete classes implement this method to convert values to bytes.
value
- the value to convertprotected abstract T convert(BinaryValue value)
Index values are stored internally as bytes. Concrete classes implement this method to convert bytes to values.
value
- the value to convertpublic final int hashCode()
hashCode
in class Object
RiakIndex.equals(java.lang.Object)
public final boolean equals(Object obj)
Only the name and index type of the RiakIndex are used to determine equality.
Copyright © 2014. All rights reserved.