org.garret.perst
Interface GenericIndex

All Superinterfaces:
java.io.Externalizable, IPersistent, IResource, ITable, java.io.Serializable
All Known Subinterfaces:
FieldIndex, Index

public interface GenericIndex
extends IPersistent, IResource, ITable

Interface of object index. This is base interface for Index and FieldIndex, allowing to write generic algorithms working with both itype of indices.


Field Summary
static int ASCENT_ORDER
           
static int DESCENT_ORDER
           
 
Method Summary
 void clear()
          Remove all objects from the index
 java.util.Iterator entryIterator()
          Get iterator for traversing all entries in the index.
 java.util.Iterator entryIterator(Key from, Key till, int order)
          Get iterator for traversing index entries with key belonging to the specified range.
 IPersistent get(Key key)
          Get object by key (exact match)
 IPersistent[] get(Key from, Key till)
          Get objects which key value belongs to the specified range.
 IPersistent get(java.lang.String key)
          Get object by string key (exact match)
 java.lang.Class getKeyType()
          Get type of index key
 java.lang.Class[] getKeyTypes()
          Get types of index compound key components
 IPersistent[] getPrefix(java.lang.String prefix)
          Get objects with string key prefix
 java.util.Iterator iterator()
          Get iterator for traversing all objects in the index.
 java.util.Iterator iterator(Key from, Key till, int order)
          Get iterator for traversing objects in the index with key belonging to the specified range.
 java.util.Iterator prefixIterator(java.lang.String prefix)
          Get iterator for records which keys started with specified prefix Objects are iterated in the ascent key order.
 IPersistent[] prefixSearch(java.lang.String word)
          Locate all objects which key is prefix of specified word.
 int size()
          Get number of objects in the index
 IPersistent[] toPersistentArray()
          Get all objects in the index as array ordered by index key.
 IPersistent[] toPersistentArray(IPersistent[] arr)
          Get all objects in the index as array ordered by index key.
 
Methods inherited from interface org.garret.perst.IPersistent
assignOid, deallocate, getOid, getStorage, invalidate, isDeleted, isModified, isPersistent, isRaw, load, loadAndModify, makePersistent, modify, onLoad, onStore, recursiveLoading, store
 
Methods inherited from interface java.io.Externalizable
readExternal, writeExternal
 
Methods inherited from interface org.garret.perst.IResource
exclusiveLock, exclusiveLock, reset, sharedLock, sharedLock, unlock
 
Methods inherited from interface org.garret.perst.ITable
select
 

Field Detail

ASCENT_ORDER

public static final int ASCENT_ORDER
See Also:
Constant Field Values

DESCENT_ORDER

public static final int DESCENT_ORDER
See Also:
Constant Field Values
Method Detail

clear

public void clear()
Remove all objects from the index


entryIterator

public java.util.Iterator entryIterator()
Get iterator for traversing all entries in the index. Iterator next() method returns object implementing Map.Entry interface which allows to get entry key and value. Objects are iterated in the ascent key order. You should not update/remove or add members to the index during iteration This iterator doesn't support remove method. If you want to update/remove records during traversal, please use range iterator.

Returns:
index iterator

entryIterator

public java.util.Iterator entryIterator(Key from,
                                        Key till,
                                        int order)
Get iterator for traversing index entries with key belonging to the specified range. Iterator next() method returns object implementing Map.Entry interface This iterator supports remove() method. To make it possible to update, remove or add members to the index during iteration it is necessary to set "perst.concurrent.iterator" property (by default it is not supported because it cause extra overhead during iteration)

Parameters:
from - low boundary. If null then low boundary is not specified. Low boundary can be inclusive or exclusive.
till - high boundary. If null then high boundary is not specified. High boundary can be inclusive or exclusive.
order - ASCENT_ORDER or DESCENT_ORDER
Returns:
selection iterator

get

public IPersistent get(Key key)
Get object by key (exact match)

Parameters:
key - specified key. It should match with type of the index and should be inclusive.
Returns:
object with this value of the key or null if key not found
Throws:
StorageError(StorageError.KEY_NOT_UNIQUE) - exception if there are more than one objects in the index with specified value of the key.

get

public IPersistent[] get(Key from,
                         Key till)
Get objects which key value belongs to the specified range. Either from boundary, either till boundary either both of them can be null. In last case the method returns all objects from the index.

Parameters:
from - low boundary. If null then low boundary is not specified. Low boundary can be inclusive or exclusive.
till - high boundary. If null then high boundary is not specified. High boundary can be inclusive or exclusive.
Returns:
array of objects which keys belongs to the specified interval, ordered by key value

get

public IPersistent get(java.lang.String key)
Get object by string key (exact match)

Parameters:
key - string key
Returns:
object with this value of the key or null if key not[ found
Throws:
StorageError(StorageError.KEY_NOT_UNIQUE) - exception if there are more than one objects in the index with specified value of the key.

getKeyType

public java.lang.Class getKeyType()
Get type of index key

Returns:
type of index key

getKeyTypes

public java.lang.Class[] getKeyTypes()
Get types of index compound key components

Returns:
array of types of compound key components

getPrefix

public IPersistent[] getPrefix(java.lang.String prefix)
Get objects with string key prefix

Parameters:
prefix - string key prefix
Returns:
array of objects which key starts with this prefix

iterator

public java.util.Iterator iterator()
Get iterator for traversing all objects in the index. Objects are iterated in the ascent key order. You should not update/remove or add members to the index during iteration. This iterator doesn't support remove method. If you want to update/remove records during traversal, please use range iterator.

Specified by:
iterator in interface ITable
Returns:
index iterator

iterator

public java.util.Iterator iterator(Key from,
                                   Key till,
                                   int order)
Get iterator for traversing objects in the index with key belonging to the specified range. This iterator supports remove() method. To make it possible to update, remove or add members to the index during iteration it is necessary to set "perst.concurrent.iterator" property (by default it is not supported because it cause extra overhead during iteration)

Parameters:
from - low boundary. If null then low boundary is not specified. Low boundary can be inclusive or exclusive.
till - high boundary. If null then high boundary is not specified. High boundary can be inclusive or exclusive.
order - ASCENT_ORDER or DESCENT_ORDER
Returns:
selection iterator

prefixIterator

public java.util.Iterator prefixIterator(java.lang.String prefix)
Get iterator for records which keys started with specified prefix Objects are iterated in the ascent key order. This iterator supports remove() method. To make it possible to update, remove or add members to the index during iteration it is necessary to set "perst.concurrent.iterator" property (by default it is not supported because it cause extra overhead during iteration)

Parameters:
prefix - key prefix
Returns:
selection iterator

prefixSearch

public IPersistent[] prefixSearch(java.lang.String word)
Locate all objects which key is prefix of specified word.

Parameters:
word - string which prefixes are located in index
Returns:
array of objects which key is prefix of specified word, ordered by key value

size

public int size()
Get number of objects in the index

Specified by:
size in interface ITable
Returns:
number of objects in the index

toPersistentArray

public IPersistent[] toPersistentArray()
Get all objects in the index as array ordered by index key.

Returns:
array of objects in the index ordered by key value

toPersistentArray

public IPersistent[] toPersistentArray(IPersistent[] arr)
Get all objects in the index as array ordered by index key. The runtime type of the returned array is that of the specified array. If the index fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this index.

If this index fits in the specified array with room to spare (i.e., the array has more elements than this index), the element in the array immediately following the end of the index is set to null. This is useful in determining the length of this index only if the caller knows that this index does not contain any null elements.)

Parameters:
arr - specified array
Returns:
array of all objects in the index