1 | package com.hammurapi.store; |
2 | |
3 | import java.util.Comparator; |
4 | |
5 | import com.hammurapi.extract.Extractor; |
6 | import com.hammurapi.extract.Predicate; |
7 | |
8 | /** |
9 | * Store.addIndex() returns object which implements one or |
10 | * more of Index sub-interfaces. Index instances are used |
11 | * to directly leverage index functionality without going through |
12 | * Store.get() methods. |
13 | * @author Pavel Vlasov |
14 | * |
15 | * This interface extends Iterable. Iterator returned by index |
16 | * iterates over objects in the store which match index predicate |
17 | * and in the order, if the index is ordered. Iteration over indices shall be |
18 | * performed within store's read lock. |
19 | * @param <T> |
20 | */ |
21 | public interface Index<T,PK,V,S extends Store<T,PK,S>> extends Iterable<T> { |
22 | |
23 | enum Type { |
24 | /** |
25 | * Unique index is evaluated as part of insert/update (synchronously). |
26 | * If uniqueness is violated, exception is thrown and insert/update is |
27 | * not executed. |
28 | */ |
29 | UNIQUE, |
30 | /** |
31 | * Synchronous indices as evaluated as part of insert/update (by writer). |
32 | * If index extractor throws an exception, this exception is propagated |
33 | * to the caller and insert/update operation doesn't get executed. |
34 | */ |
35 | SYNCHRONOUS, |
36 | /** |
37 | * Asynchronous index modifications get evaluated in a separate task. |
38 | * If reader accesses the index before the index update task goes to |
39 | * execution, index update is performed as part of the access operation (by reader). |
40 | * If index extractor throws exception, then index gets marked as |
41 | * corrupted and is removed from the store. If the reader |
42 | * accesses the index directly through one of index interfaces, |
43 | * then the exception is propagated to the caller code. |
44 | * All operations on a corrupted index result in exception. |
45 | */ |
46 | ASYNCHRONOUS, |
47 | /** |
48 | * Lazy index modifications get queued and are evaluated |
49 | * as part of the access operation (by reader). If index |
50 | * extractor throws exception, then index gets marked as |
51 | * corrupted and is removed from the store. If the reader |
52 | * accesses the index directly through one of index interfaces, |
53 | * then the exception is propagated to the caller code. |
54 | * All operations on a corrupted index result in exception. |
55 | */ |
56 | LAZY |
57 | |
58 | } |
59 | |
60 | /** |
61 | * @return Back-link to the store. |
62 | */ |
63 | S getStore(); |
64 | |
65 | Predicate<T,S> getPredicate(); |
66 | |
67 | Extractor<T, V, S> getExtractor(); |
68 | |
69 | boolean isUnique(); |
70 | |
71 | boolean isOrdered(); |
72 | |
73 | Comparator<V> getComparator(); |
74 | } |