com.amazon.carbonado.qe
Class StorableIndexSet<S extends Storable>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by java.util.TreeSet<StorableIndex<S>>
              extended by com.amazon.carbonado.qe.StorableIndexSet<S>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<StorableIndex<S>>, Collection<StorableIndex<S>>, NavigableSet<StorableIndex<S>>, Set<StorableIndex<S>>, SortedSet<StorableIndex<S>>

public class StorableIndexSet<S extends Storable>
extends TreeSet<StorableIndex<S>>

Manages a set of StorableIndex objects, intended for reducing the set such that the minimal amount of physical indexes need to be defined for a specific type of Storable.

Author:
Brian S O'Neill
See Also:
Serialized Form

Constructor Summary
StorableIndexSet()
           
StorableIndexSet(StorableIndexSet<S> set)
          Copy constructor.
 
Method Summary
 void addAlternateKeys(StorableInfo<S> info)
          Adds all of the alternate keys of the given storable as indexes by calling addKey.
 void addIndexes(StorableInfo<S> info)
          Adds all the indexes of the given storable.
 void addIndexes(StorableInfo<S> info, Direction defaultDirection)
          Adds all the indexes of the given storable.
 void addKey(StorableKey<S> key)
          Adds the key as a unique index, preserving the property arrangement.
 void addPrimaryKey(StorableInfo<S> info)
          Adds the primary key of the given storable as indexes by calling addKey.
 StorableIndex<S> findKeyIndex(StorableKey<S> key)
          Finds the best index to represent the given key.
 StorableIndex<S> findPrimaryKeyIndex(StorableInfo<S> info)
          Finds the best index to represent the primary key.
 void markClustered(boolean clustered)
          Marks all indexes as clustered or non-clustered.
 void reduce()
          Reduces the size of the set by removing redundant indexes, and merges others together.
 void reduce(Direction defaultDirection)
          Reduces the size of the set by removing redundant indexes, and merges others together.
 void setDefaultDirection(Direction defaultDirection)
          Set the default direction for all index properties.
 void uniquify(StorableInfo<S> info)
          Augment non-unique indexes with primary key properties, thus making them unique.
 void uniquify(StorableKey<S> key)
          Augment non-unique indexes with key properties, thus making them unique.
 
Methods inherited from class java.util.TreeSet
add, addAll, ceiling, clear, clone, comparator, contains, descendingIterator, descendingSet, first, floor, headSet, headSet, higher, isEmpty, iterator, last, lower, pollFirst, pollLast, remove, size, subSet, subSet, tailSet, tailSet
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
containsAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Constructor Detail

StorableIndexSet

public StorableIndexSet()

StorableIndexSet

public StorableIndexSet(StorableIndexSet<S> set)
Copy constructor.

Method Detail

addIndexes

public void addIndexes(StorableInfo<S> info)
Adds all the indexes of the given storable.

Throws:
IllegalArgumentException - if info is null

addIndexes

public void addIndexes(StorableInfo<S> info,
                       Direction defaultDirection)
Adds all the indexes of the given storable.

Parameters:
defaultDirection - default ordering direction to apply to each index property
Throws:
IllegalArgumentException - if any argument is null

addAlternateKeys

public void addAlternateKeys(StorableInfo<S> info)
Adds all of the alternate keys of the given storable as indexes by calling addKey.

Throws:
IllegalArgumentException - if info is null

addPrimaryKey

public void addPrimaryKey(StorableInfo<S> info)
Adds the primary key of the given storable as indexes by calling addKey. This method should not be called if the primary key cannot be altered because persistent data is already stored against it. Instead, the primary key index should be added as a normal index.

After adding the primary key via this method and after reducing the set, call findPrimaryKeyIndex to get the best index to represent the primary key.

Throws:
IllegalArgumentException - if info is null

addKey

public void addKey(StorableKey<S> key)
Adds the key as a unique index, preserving the property arrangement.

Throws:
IllegalArgumentException - if key is null

reduce

public void reduce()
Reduces the size of the set by removing redundant indexes, and merges others together.


reduce

public void reduce(Direction defaultDirection)
Reduces the size of the set by removing redundant indexes, and merges others together.

Parameters:
defaultDirection - replace unspecified property directions with this

setDefaultDirection

public void setDefaultDirection(Direction defaultDirection)
Set the default direction for all index properties.

Parameters:
defaultDirection - replace unspecified property directions with this

markClustered

public void markClustered(boolean clustered)
Marks all indexes as clustered or non-clustered.

Parameters:
clustered - true to mark clustered; false to mark non-clustered
Since:
1.2
See Also:
StorableIndex.isClustered()

uniquify

public void uniquify(StorableInfo<S> info)
Augment non-unique indexes with primary key properties, thus making them unique.

Throws:
IllegalArgumentException - if info is null

uniquify

public void uniquify(StorableKey<S> key)
Augment non-unique indexes with key properties, thus making them unique.

Throws:
IllegalArgumentException - if key is null

findPrimaryKeyIndex

public StorableIndex<S> findPrimaryKeyIndex(StorableInfo<S> info)
Finds the best index to represent the primary key. Should be called after calling reduce. As long as the primary key was added via addPrimaryKey, this method should never return null.

Throws:
IllegalArgumentException - if info is null

findKeyIndex

public StorableIndex<S> findKeyIndex(StorableKey<S> key)
Finds the best index to represent the given key. Should be called after calling reduce. As long as the key was added via addKey, this method should never return null.

Throws:
IllegalArgumentException - if key is null


Copyright © 2006-2009 Amazon Technologies, Inc.. All Rights Reserved.