public class RiakIndexes extends Object implements Iterable<RiakIndex<?>>
RiakIndex
objects to be used with a RiakObject
.
This container manages and allows for an arbitrary number and types of RiakIndex
s to
be used with a RiakObject
.
Data in Riak, including secondary indexes, is stored as raw bytes. The conversion
to and from bytes is handled by the concrete RiakIndex
implementations
and all indexes are managed by this container.
Each concrete RiakIndex
includes a hybrid builder class named Name
.
The methods of this class take an instance of that builder as an
argument to allow for proper type inference and construction of RiakIndex
objects to expose.
getIndex()
will either return a reference to
the existing RiakIndex
or atomically add and return a new one. The
returned reference is of the type provided by the Name
and is the
mutable index; changes are made directly to it.
LongIntIndex myIndex = riakIndexes.getIndex(LongIntIndex.named("number_on_hand")); myIndex.removeAll(); myIndex.add(6L);
Calls can be chained, allowing for easy addition or removal of values from an index.
riakIndexes.getIndex(StringBinIndex.named("colors")).remove("blue").add("red");
RiakIndex
is uniquely identified by its textual name and IndexType
regardless of the concrete RiakIndex
implementation being used to view
or update it. This container enforces this uniqueness by being the source of
all RiakIndex
instances and managing them in a thread-safe way with
atomic operations.
What this means is that any RiakIndex
having the same name and Indextype
will refer to the same index. This is only important to note if you are mixing
access to the indexes using RawIndex
. The test case copied below demonstrates
the relation.
public void wrapping() { // creates or fetches the BIN (_bin) index named "foo", adds a value to it RawIndex index = indexes.getIndex(RawIndex.named("foo", IndexType.BIN)); BinaryValue baw = BinaryValue.unsafeCreate("value".getBytes()); index.add(baw); // fetches the previously created index as a StringBinIndex StringBinIndex wrapper = indexes.getIndex(StringBinIndex.named("foo")); // The references are to different objects assertNotSame(index, wrapper); // The two objects are equal ( index.equals(wrapper) == true ) assertEquals(index, wrapper); // The value exists assertTrue(wrapper.hasValue("value")); // Removing the value via the StringBinIndex is reflected in the RawIndex wrapper.remove("value"); assertFalse(index.hasValue(baw)); }
RiakObject.getIndexes()
Constructor and Description |
---|
RiakIndexes()
Instantiates a new RiakIndexes object containing no RiakIndex objects
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
<V extends RiakIndex<?>,T extends RiakIndex.Name<V>> |
getIndex(T name)
Get the named RiakIndex
|
int |
hashCode() |
<T extends RiakIndex<?>> |
hasIndex(RiakIndex.Name<T> name)
Returns whether a specific RiakIndex is present
|
boolean |
isEmpty()
Returns whether any
RiakIndex objects are present |
Iterator<RiakIndex<?>> |
iterator() |
void |
removeAllIndexes()
Remove all indexes.
|
<V,T extends RiakIndex<V>> |
removeIndex(RiakIndex.Name<T> name)
Remove the named RiakIndex
|
int |
size()
Return the number of indexes present
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public RiakIndexes()
public int size()
public boolean isEmpty()
RiakIndex
objects are presenttrue
if there are indexes, false
otherwisepublic <T extends RiakIndex<?>> boolean hasIndex(RiakIndex.Name<T> name)
name
- the RiakIndex.Name
representing the index to check fortrue
if the index is present, false
otherwisepublic <V extends RiakIndex<?>,T extends RiakIndex.Name<V>> V getIndex(T name)
If the named index does not exist it is created and added to the container before being returned.
Scala Users: to chain RiakIndex method calls off of this method please include explicit type parameters for the getIndex() call. e.g.
riakIndexes.getIndex[StringBinIndex,StringBinIndex.Name](StringBinIndex.named("myindex")).add("myvalue")
name
- The RiakIndex.Name
of the index to retrieve.public <V,T extends RiakIndex<V>> T removeIndex(RiakIndex.Name<T> name)
name
- the RiakIndex.Name
representing the index to removeRiakIndex
(typed accordingly) if the index was present,
null
otherwisepublic void removeAllIndexes()
Copyright © 2016. All rights reserved.