Package com.apple.foundationdb.subspace
Class Subspace
- java.lang.Object
-
- com.apple.foundationdb.subspace.Subspace
-
- Direct Known Subclasses:
DirectorySubspace
public class Subspace extends java.lang.ObjectSubspaceprovide a convenient way to useTuples to define namespaces for different categories of data. The namespace is specified by a prefixTuplewhich is prepended to allTuples packed by theSubspace. When unpacking a key with theSubspace, the prefixTuplewill be removed from the result.For general guidance on subspace usage, see the discussion in Developer Guide.
As a best practice, API clients should use at least one subspace for application data.
-
-
Constructor Summary
Constructors Constructor Description Subspace()Constructor for a subspace formed with an empty prefixTuple.Subspace(byte[] rawPrefix)Constructor for a subspace formed with the specified byte string, which will be prepended to all packed keys.Subspace(Tuple prefix)Constructor for a subspace formed with the specified prefixTuple.Subspace(Tuple prefix, byte[] rawPrefix)Constructor for a subspace formed with both a prefixTupleand a prefix byte string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(byte[] key)Tests whether the specified key starts with thisSubspace's prefix, indicating that theSubspacelogically contains key.booleanequals(java.lang.Object rhs)Returns true if thisSubspaceis equal torhs.Subspaceget(Tuple tuple)Subspaceget(java.lang.Object obj)Gets a new subspace which is equivalent to this subspace with its prefixTupleextended by the specifiedObject.byte[]getKey()Gets the key encoding the prefix used for thisSubspace.inthashCode()Returns a hash-table compatible hash of this subspace.byte[]pack()Gets the key encoding the prefix used for thisSubspace.byte[]pack(Tuple tuple)Gets the key encoding the specified tuple in thisSubspace.byte[]pack(java.lang.Object obj)Gets the key encoding the specifiedObjectin thisSubspace.byte[]packWithVersionstamp(Tuple tuple)Gets the key encoding the specified tuple in thisSubspacefor use withMutationType.SET_VERSIONSTAMPED_KEY.Rangerange()Gets aRangerepresenting all keys strictly in theSubspace.Rangerange(Tuple tuple)Subspacesubspace(Tuple tuple)java.lang.StringtoString()Create a human-readable string representation of this subspace.Tupleunpack(byte[] key)
-
-
-
Constructor Detail
-
Subspace
public Subspace()
Constructor for a subspace formed with an empty prefixTuple.
-
Subspace
public Subspace(Tuple prefix)
Constructor for a subspace formed with the specified prefixTuple. Note that theTupleprefixshould not contain any incompleteVersionstamps as any of its entries.- Parameters:
prefix- aTupleused to form the subspace- Throws:
java.lang.IllegalArgumentException- ifprefixcontains any incompleteVersionstamps
-
Subspace
public Subspace(byte[] rawPrefix)
Constructor for a subspace formed with the specified byte string, which will be prepended to all packed keys.- Parameters:
rawPrefix- a byte array used as the prefix for all packed keys
-
Subspace
public Subspace(Tuple prefix, byte[] rawPrefix)
Constructor for a subspace formed with both a prefixTupleand a prefix byte string. The prefixTuplewill be prepended to allTuplespacked by theSubspace, and the byte string prefix will be prepended to the packed result. Note that theTupleprefixshould not contain any incompleteVersionstamps as any of its entries.- Parameters:
prefix- aTupleused to form the subspacerawPrefix- a byte array used as the prefix for all packed keys- Throws:
java.lang.IllegalArgumentException- ifprefixcontains any incompleteVersionstamps
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object rhs)
Returns true if thisSubspaceis equal torhs. TwoSubspaces are equal if they have the same prefix.- Overrides:
equalsin classjava.lang.Object- Parameters:
rhs- the object to check for equality- Returns:
trueif thisSubspaceandrhshave equal prefixes
-
toString
public java.lang.String toString()
Create a human-readable string representation of this subspace. This is really only useful for debugging purposes, but it includes information on what raw prefix the subspace is using.- Overrides:
toStringin classjava.lang.Object- Returns:
- a printable representation of the subspace
-
hashCode
public int hashCode()
Returns a hash-table compatible hash of this subspace. This is based off of the hash of the underlying byte-array prefix.- Overrides:
hashCodein classjava.lang.Object- Returns:
- a hash of this subspace
-
get
public Subspace get(java.lang.Object obj)
Gets a new subspace which is equivalent to this subspace with its prefixTupleextended by the specifiedObject. The object will be inserted into aTupleand passed toget(Tuple).- Parameters:
obj- anObjectcompatible withTuples- Returns:
- a new subspace formed by joining this
Subspace's prefix toobj
-
get
public Subspace get(Tuple tuple)
Gets a new subspace which is equivalent to this subspace with its prefixTupleextended by the specifiedTuple.- Parameters:
tuple- theTupleused to form the newSubspace- Returns:
- a new subspace formed by joining this
Subspace's prefix totuple
-
getKey
public byte[] getKey()
Gets the key encoding the prefix used for thisSubspace. This is equivalent topack()ing the emptyTuple.- Returns:
- the key encoding the prefix used for this
Subspace
-
pack
public byte[] pack()
Gets the key encoding the prefix used for thisSubspace.- Returns:
- the key encoding the prefix used for this
Subspace
-
pack
public byte[] pack(java.lang.Object obj)
Gets the key encoding the specifiedObjectin thisSubspace.objis inserted into aTupleand packed withpack(Tuple).- Parameters:
obj- anObjectto be packed that is compatible withTuples- Returns:
- the key encoding the tuple derived from
obj
-
pack
public byte[] pack(Tuple tuple)
Gets the key encoding the specified tuple in thisSubspace. For example, if you have aSubspacewith prefixTuple("users")and you use it to pack theTuple("Smith"), the result is the same as if you packed theTuple("users", "Smith").- Parameters:
tuple- theTupleto be packed- Returns:
- the key encoding the specified tuple in this
Subspace
-
packWithVersionstamp
public byte[] packWithVersionstamp(Tuple tuple)
Gets the key encoding the specified tuple in thisSubspacefor use withMutationType.SET_VERSIONSTAMPED_KEY. There must be exactly one incompleteVersionstampincluded in the givenTuple. It will create a key that is within thisSubspacethat can be provided as thekeyargument toTransaction.mutate()with theSET_VERSIONSTAMPED_KEYmutation. This will throw anIllegalArgumentExceptionif theTupledoes not contain an incompleteVersionstampor if it contains multiple.- Parameters:
tuple- theTupleto be packed- Returns:
- the key encoding the specified tuple in this
Subspace - Throws:
java.lang.IllegalArgumentException- iftupledoes not contain exactly one incompleteVersionstamp
-
unpack
public Tuple unpack(byte[] key)
- Parameters:
key- The key being decoded- Returns:
- the
Tupleencoded bykeywith the prefix removed
-
range
public Range range()
Gets aRangerepresenting all keys strictly in theSubspace.- Returns:
- the
Rangeof keyspace corresponding to thisSubspace
-
range
public Range range(Tuple tuple)
- Parameters:
tuple- theTuplewhose sub-keys we are searching for- Returns:
- the
Rangeof keyspace corresponding totuple
-
contains
public boolean contains(byte[] key)
Tests whether the specified key starts with thisSubspace's prefix, indicating that theSubspacelogically contains key.- Parameters:
key- the key to be tested- Returns:
trueifkeystarts withSubspace.key()
-
-