org.helidb.util.bplus
Class FileBackedNodeRepositoryBuilder<K,V>

java.lang.Object
  extended by org.helidb.util.bplus.FileBackedNodeRepositoryBuilder<K,V>
Type Parameters:
K - The type of keys in the repository.
V - The type of values in the repository.
All Implemented Interfaces:
NodeRepositoryBuilder<K>
Direct Known Subclasses:
BPlusTreeIndexBackendFileBackedNodeRepositoryBuilder

public class FileBackedNodeRepositoryBuilder<K,V>
extends Object
implements NodeRepositoryBuilder<K>

Builder for FileBackedNodeRepository objects. The client using this object must set a key and a value Serializer. Otherwise, it contains default values for the rest of the properties.

Since:
1.0
Author:
Karl Gustafsson
See Also:
FileBackedNodeRepository
In_jar:
helidb-core

Field Summary
static int DEFAULT_BUFFER_SIZE
          The default size of internal buffers used by FileBackedNodeRepository.writeContentsTo(java.io.OutputStream) is 65536 bytes.
static int DEFAULT_INTERNAL_POINTER_SIZE
          The default size of internal pointers in the node repository is four bytes.
static boolean DEFAULT_LEAF_NODE_HAS_POINTERS_TO_ADJACENT_NODES
          By default, leaf nodes have pointers to their adjacent leaf nodes.
static NodeSizeStrategy DEFAULT_NODE_SIZE_STRATEGY
          The default NodeSizeStrategy is a FixedSizeNodeSizeStrategy with a node size of 4096 bytes.
 
Constructor Summary
FileBackedNodeRepositoryBuilder()
           
 
Method Summary
 NodeRepository<K> create(ReadWritableFile f, boolean readOnly)
          Create the node repository.
 FileBackedNodeRepositoryBuilder<K,V> setBufferSize(int size)
          Set the size of in-memory buffers used by FileBackedNodeRepository.writeContentsTo(java.io.OutputStream).
 FileBackedNodeRepositoryBuilder<K,V> setInternalPointerSize(int i)
          Set the size of internal pointers.
 FileBackedNodeRepositoryBuilder<K,V> setKeyComparator(Comparator<? super K> cmp)
          Set the Comparator used for comparing keys.
 FileBackedNodeRepositoryBuilder<K,V> setKeySerializer(Serializer<K> s)
          Set a key Serializer.
 FileBackedNodeRepositoryBuilder<K,V> setLeafNodeHasPointersToAdjacentNodes(boolean b)
          Set the flag determining if leaf node has pointers to adjacent leaf nodes.
 FileBackedNodeRepositoryBuilder<K,V> setLogAdapterHolder(LogAdapterHolder lah)
          Set a log adapter holder.
 FileBackedNodeRepositoryBuilder<K,V> setNodeSizeStrategy(NodeSizeStrategy nss)
          Set a NodeSizeStrategy.
 FileBackedNodeRepositoryBuilder<K,V> setStartPosOfData(long pos)
           
 FileBackedNodeRepositoryBuilder<K,V> setValueSerializer(Serializer<V> s)
          Set a value Serializer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NODE_SIZE_STRATEGY

public static final NodeSizeStrategy DEFAULT_NODE_SIZE_STRATEGY
The default NodeSizeStrategy is a FixedSizeNodeSizeStrategy with a node size of 4096 bytes.


DEFAULT_INTERNAL_POINTER_SIZE

public static final int DEFAULT_INTERNAL_POINTER_SIZE
The default size of internal pointers in the node repository is four bytes. It gives a maximum tree size of 2^(4*8) = 4294967296 bytes.

See Also:
Constant Field Values

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
The default size of internal buffers used by FileBackedNodeRepository.writeContentsTo(java.io.OutputStream) is 65536 bytes.

See Also:
Constant Field Values

DEFAULT_LEAF_NODE_HAS_POINTERS_TO_ADJACENT_NODES

public static final boolean DEFAULT_LEAF_NODE_HAS_POINTERS_TO_ADJACENT_NODES
By default, leaf nodes have pointers to their adjacent leaf nodes. This makes the tree Iterable, but uses more disk space.

See Also:
Constant Field Values
Constructor Detail

FileBackedNodeRepositoryBuilder

public FileBackedNodeRepositoryBuilder()
Method Detail

setNodeSizeStrategy

public FileBackedNodeRepositoryBuilder<K,V> setNodeSizeStrategy(NodeSizeStrategy nss)
Set a NodeSizeStrategy.

Parameters:
nss - A NodeSizeStrategy
Returns:
this

setLeafNodeHasPointersToAdjacentNodes

public FileBackedNodeRepositoryBuilder<K,V> setLeafNodeHasPointersToAdjacentNodes(boolean b)
Set the flag determining if leaf node has pointers to adjacent leaf nodes.

Parameters:
b - Do leaf nodes have pointers to adjacent leaf nodes?
Returns:
this.

setKeySerializer

public FileBackedNodeRepositoryBuilder<K,V> setKeySerializer(Serializer<K> s)
                                                      throws IllegalArgumentException
Set a key Serializer. It must support null values and produce byte arrays of a constant size.

Parameters:
s - The key serializer.
Returns:
this.
Throws:
IllegalArgumentException - If the serializer does not support null values or if it does not produce byte arrays of a constant size.

setValueSerializer

public FileBackedNodeRepositoryBuilder<K,V> setValueSerializer(Serializer<V> s)
                                                        throws IllegalArgumentException
Set a value Serializer. It must produce byte arrays of a constant size.

Parameters:
s - The value serializer.
Returns:
this.
Throws:
IllegalArgumentException - If the serializer does not produce byte arrays of a constant size.

setInternalPointerSize

public FileBackedNodeRepositoryBuilder<K,V> setInternalPointerSize(int i)
                                                            throws IllegalArgumentException
Set the size of internal pointers. The internal pointer size determines the maximum size of the B+ Tree. See FileBackedNodeRepository.

Parameters:
i - The size of internal pointers.
Returns:
this.
Throws:
IllegalArgumentException - If the pointer size is not in the range 1 <= i <= 8.

setLogAdapterHolder

public FileBackedNodeRepositoryBuilder<K,V> setLogAdapterHolder(LogAdapterHolder lah)
Set a log adapter holder.

Parameters:
lah - A log adapter holder.
Returns:
this.

setBufferSize

public FileBackedNodeRepositoryBuilder<K,V> setBufferSize(int size)
                                                   throws IllegalArgumentException
Set the size of in-memory buffers used by FileBackedNodeRepository.writeContentsTo(java.io.OutputStream).

Parameters:
size - The buffer size.
Returns:
this.
Throws:
IllegalArgumentException - If the buffer size is less than 1.

setKeyComparator

public FileBackedNodeRepositoryBuilder<K,V> setKeyComparator(Comparator<? super K> cmp)
Set the Comparator used for comparing keys. This can be set to null to use the keys' natural order if they are Comparable.

Parameters:
cmp - The key comparator.
Returns:
this.

setStartPosOfData

public FileBackedNodeRepositoryBuilder<K,V> setStartPosOfData(long pos)
                                                       throws IllegalArgumentException
Throws:
IllegalArgumentException

create

public NodeRepository<K> create(ReadWritableFile f,
                                boolean readOnly)
Description copied from interface: NodeRepositoryBuilder
Create the node repository.

Specified by:
create in interface NodeRepositoryBuilder<K>
Parameters:
f - The file containing the node repository data.
readOnly - Should the repository be read only?
Returns:
The created node repository.