001package com.hammurapi.store;
002
003import java.util.Comparator;
004
005import com.hammurapi.extract.Extractor;
006import com.hammurapi.extract.Predicate;
007
008/**
009 * Store.addIndex() returns object which implements one or 
010 * more of Index sub-interfaces. Index instances are used
011 * to directly leverage index functionality without going through
012 * Store.get() methods.
013 * @author Pavel Vlasov
014 *
015 * This interface extends Iterable. Iterator returned by index
016 * iterates over objects in the store which match index predicate 
017 * and in the order, if the index is ordered. Iteration over indices shall be 
018 * performed within store's read lock.
019 * @param <T>
020 */
021public interface Index<ST,T extends ST,PK,V,S extends Store<ST,PK,S>> extends Iterable<T> {
022        
023        enum Type {
024                /**
025                 * Unique index is evaluated as part of insert/update (synchronously). 
026                 * If uniqueness is violated, exception is thrown and insert/update is
027                 * not executed.
028                 */
029                UNIQUE,
030                /**
031                 * Synchronous indices as evaluated as part of insert/update (by writer).
032                 * If index extractor throws an exception, this exception is propagated
033                 * to the caller and insert/update operation doesn't get executed.
034                 */
035                SYNCHRONOUS,
036                /**
037                 * Asynchronous index modifications get evaluated in a separate task.
038                 * If reader accesses the index before the index update task goes to
039                 * execution, index update is performed as part of the access operation (by reader). 
040                 * If index extractor throws exception, then index gets marked as 
041                 * corrupted and is removed from the store. If the reader
042                 * accesses the index directly through one of index interfaces, 
043                 * then the exception is propagated to the caller code.
044                 * All operations on a corrupted index result in exception.
045                 */
046                ASYNCHRONOUS,
047                /**
048                 * Lazy index modifications get queued and are evaluated
049                 * as part of the access operation (by reader). If index 
050                 * extractor throws exception, then index gets marked as 
051                 * corrupted and is removed from the store. If the reader
052                 * accesses the index directly through one of index interfaces, 
053                 * then the exception is propagated to the caller code.
054                 * All operations on a corrupted index result in exception.
055                 */
056                LAZY
057                
058        }       
059
060        /**
061         * @return Back-link to the store.
062         */
063        S getStore();
064        
065        Predicate<ST,S> getPredicate();
066        
067        Extractor<T, V, S> getExtractor();
068        
069        boolean isUnique();
070        
071        boolean isOrdered();
072        
073        Comparator<V> getComparator();    
074}