org.garret.perst
Interface FieldIndex<T extends IPersistent>

All Superinterfaces:
java.util.Collection<T>, java.io.Externalizable, GenericIndex<T>, IPersistent, IResource, ITable<T>, java.lang.Iterable<T>, java.io.Serializable

public interface FieldIndex<T extends IPersistent>
extends GenericIndex<T>

Interface of indexed field. Index is used to provide fast access to the object by the value of indexed field. Objects in the index are stored ordered by the value of indexed field. It is possible to select object using exact value of the key or select set of objects which key belongs to the specified interval (each boundary can be specified or unspecified and can be inclusive or exclusive) Key should be of scalar, String, java.util.Date or peristent object type.


Field Summary
 
Fields inherited from interface org.garret.perst.GenericIndex
ASCENT_ORDER, DESCENT_ORDER
 
Method Summary
 void append(T obj)
          Assign to the integer indexed field unique autoicremented value and insert object in the index.
 boolean contains(T obj)
          Check if index contains object which is equal to the specified object.
 boolean containsObject(T obj)
          Check if index contains specified object instance.
 java.lang.Class getIndexedClass()
          Get class obejct objects which can be inserted in this index
 java.lang.reflect.Field[] getKeyFields()
          Get fields used as a key
 boolean isCaseInsensitive()
          Check if field index is case insensitive
 boolean put(T obj)
          Put new object in the index.
 IterableIterator<T> queryByExample(T obj)
          Locate objects with the same value of the key as specified object
 T remove(Key key)
          Remove object with specified key from the unique index
 void remove(T obj)
          Remove object from the index
 T removeKey(java.lang.Object key)
          Remove object with specified key from the unique index
 IterableIterator<T> select(java.lang.String predicate)
          Select members of the collection using search predicate This iterator doesn't support remove() method.
 T set(T obj)
          Associate new object with the key specified by object field value.
 
Methods inherited from interface org.garret.perst.GenericIndex
clear, entryIterator, entryIterator, entryIterator, entryIterator, get, get, get, get, getAt, getKeyType, getKeyTypes, getList, getList, getPrefix, getPrefixList, isUnique, iterator, iterator, iterator, prefixIterator, prefixSearch, prefixSearchList, size, toPersistentArray
 
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
 
Methods inherited from interface java.util.Collection
add, addAll, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Method Detail

append

void append(T obj)
Assign to the integer indexed field unique autoicremented value and insert object in the index.

Parameters:
obj - object to be inserted in index. Object should contain indexed field of integer (int or long) type. This field is assigned unique value (which will not be reused while this index exists) and object is marked as modified. Object can be not yet peristent, in this case its forced to become persistent by assigning OID to it.
Throws:
StorageError(StorageError.INCOMPATIBLE_KEY_TYPE) - when indexed field has type other than int or long

contains

boolean contains(T obj)
Check if index contains object which is equal to the specified object. More formally, returns true if and only if this collection contains at least one element e such that (obj==null ? e==null : obj.equals(e)).

Parameters:
obj - object to be searched in the index. Object should contain indexed field.
Returns:
true if collection contains object equals to the specified

containsObject

boolean containsObject(T obj)
Check if index contains specified object instance.

Parameters:
obj - object to be searched in the index. Object should contain indexed field.
Returns:
true if object is present in the index, false otherwise

getIndexedClass

java.lang.Class getIndexedClass()
Get class obejct objects which can be inserted in this index

Returns:
class specified in Storage.createFielIndex method

getKeyFields

java.lang.reflect.Field[] getKeyFields()
Get fields used as a key

Returns:
array of index key fields

isCaseInsensitive

boolean isCaseInsensitive()
Check if field index is case insensitive

Returns:
true if index ignore case of string keys

put

boolean put(T obj)
Put new object in the index.

Parameters:
obj - object to be inserted in index. Object should contain indexed field. Object can be not yet peristent, in this case its forced to become persistent by assigning OID to it.
Returns:
true if object is successfully inserted in the index, false if index was declared as unique and there is already object with such value of the key in the index.

queryByExample

IterableIterator<T> queryByExample(T obj)
Locate objects with the same value of the key as specified object

Parameters:
obj - object specifying search key value
Returns:
selection iterator

remove

T remove(Key key)
Remove object with specified key from the unique index

Parameters:
key - value of removed key
Returns:
removed object
Throws:
StorageError(StorageError.KEY_NOT_FOUND) - exception if there is no such key in the index, or StorageError(StorageError.KEY_NOT_UNIQUE) if index is not unique.

remove

void remove(T obj)
Remove object from the index

Parameters:
obj - object removed from the index. Object should contain indexed field.
Throws:
StorageError(StorageError.KEY_NOT_FOUND) - exception if there is no such key in the index

removeKey

T removeKey(java.lang.Object key)
Remove object with specified key from the unique index

Parameters:
key - value of removed key
Returns:
removed object
Throws:
StorageError(StorageError.KEY_NOT_FOUND) - exception if there is no such key in the index, or StorageError(StorageError.KEY_NOT_UNIQUE) if index is not unique.

select

IterableIterator<T> select(java.lang.String predicate)
Select members of the collection using search predicate This iterator doesn't support 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:
predicate - JSQL condition
Returns:
iterator through members of the collection matching search condition

set

T set(T obj)
Associate new object with the key specified by object field value. If there is already object with such key in the index, then it will be removed from the index and new value associated with this key.

Parameters:
obj - object to be inserted in index. Object should contain indexed field. Object can be not yet peristent, in this case its forced to become persistent by assigning OID to it.
Returns:
object previously associated with this key, null if there was no such object