public class HollowPrimaryKeyIndex extends java.lang.Object implements HollowTypeStateListener
A primary key index can be used to index and query a type by a PrimaryKey
. The provided PrimaryKey
does
not have to be the same as declared as the default in the data model.
This class is not safe to use with object longevity if the index is not being updated for each delta. The internal
implementation of this class uses the type state retrieved through the schema. That resutls in certain operations
always being performed against the current version. As such, this class is only valid for up to 2 updates.
If you need an index that will survive 2 or more deltas (without being updated), then use HollowUniqueKeyIndex
or HollowHashIndex
.
Constructor and Description |
---|
HollowPrimaryKeyIndex(HollowReadStateEngine stateEngine,
ArraySegmentRecycler memoryRecycler,
java.lang.String type,
java.lang.String... fieldPaths) |
HollowPrimaryKeyIndex(HollowReadStateEngine stateEngine,
PrimaryKey primaryKey) |
HollowPrimaryKeyIndex(HollowReadStateEngine stateEngine,
PrimaryKey primaryKey,
ArraySegmentRecycler memoryRecycler) |
HollowPrimaryKeyIndex(HollowReadStateEngine stateEngine,
PrimaryKey primaryKey,
ArraySegmentRecycler memoryRecycler,
java.util.BitSet specificOrdinalsToIndex)
This initializer can be used to create a HollowPrimaryKeyIndex which will only index a subset of the records in the specified type.
|
HollowPrimaryKeyIndex(HollowReadStateEngine stateEngine,
java.lang.String type,
java.lang.String... fieldPaths) |
Modifier and Type | Method and Description |
---|---|
void |
addedOrdinal(int ordinal)
Called once for each record which is added to the registered type.
|
void |
beginUpdate()
Called immediately before a delta update is applied to the state engine
|
boolean |
containsDuplicates() |
void |
destroy() |
void |
detachFromDeltaUpdates()
Once called, this HollowPrimaryKeyIndex will no longer be kept up-to-date when deltas are applied to the indexed state engine.
|
void |
endUpdate()
Called immediately after a delta update is applied to the state engine.
|
java.util.Collection<java.lang.Object[]> |
getDuplicateKeys() |
java.util.List<HollowObjectSchema.FieldType> |
getFieldTypes() |
int |
getMatchingOrdinal(java.lang.Object... keys)
Query an index with four or more specified fields.
|
int |
getMatchingOrdinal(java.lang.Object key)
Query an index with a single specified field.
|
int |
getMatchingOrdinal(java.lang.Object key1,
java.lang.Object key2)
Query an index with two specified fields.
|
int |
getMatchingOrdinal(java.lang.Object key1,
java.lang.Object key2,
java.lang.Object key3)
Query an index with three specified fields.
|
PrimaryKey |
getPrimaryKey() |
java.lang.Object[] |
getRecordKey(int ordinal) |
HollowObjectTypeReadState |
getTypeState() |
void |
listenForDeltaUpdates()
Once called, this HollowPrimaryKeyIndex will be kept up-to-date when deltas are applied to the indexed state engine.
|
void |
removedOrdinal(int ordinal)
Called once for each record which is removed from the registered type.
|
public HollowPrimaryKeyIndex(HollowReadStateEngine stateEngine, java.lang.String type, java.lang.String... fieldPaths)
public HollowPrimaryKeyIndex(HollowReadStateEngine stateEngine, PrimaryKey primaryKey)
public HollowPrimaryKeyIndex(HollowReadStateEngine stateEngine, ArraySegmentRecycler memoryRecycler, java.lang.String type, java.lang.String... fieldPaths)
public HollowPrimaryKeyIndex(HollowReadStateEngine stateEngine, PrimaryKey primaryKey, ArraySegmentRecycler memoryRecycler)
public HollowPrimaryKeyIndex(HollowReadStateEngine stateEngine, PrimaryKey primaryKey, ArraySegmentRecycler memoryRecycler, java.util.BitSet specificOrdinalsToIndex)
stateEngine
- the read state engineprimaryKey
- the primary keymemoryRecycler
- the memory recyclerspecificOrdinalsToIndex
- the bit setpublic void listenForDeltaUpdates()
This method should be called before any subsequent deltas occur after the index is created.
In order to prevent memory leaks, if this method is called and the index is no longer needed, call detachFromDeltaUpdates() before discarding the index.
Note that this index does not listen on snapshot update. If a snapshot update occurs this index will NOT return the latest data in the consumer. Callers must detach this index instance and initialize a new one on snapshot update, or disable double snapshot update for the consumer altogether.
public void detachFromDeltaUpdates()
Call this method before discarding indexes which are currently listening for delta updates.
public HollowObjectTypeReadState getTypeState()
public PrimaryKey getPrimaryKey()
public java.util.List<HollowObjectSchema.FieldType> getFieldTypes()
public int getMatchingOrdinal(java.lang.Object key)
Use a generated API or the Generic Object API to use the returned ordinal.
key
- the field keypublic int getMatchingOrdinal(java.lang.Object key1, java.lang.Object key2)
Use a generated API or the Generic Object API to use the returned ordinal.
key1
- the first field keykey2
- the second field keypublic int getMatchingOrdinal(java.lang.Object key1, java.lang.Object key2, java.lang.Object key3)
Use a generated API or the Generic Object API to use the returned ordinal.
key1
- the first field keykey2
- the second field keykey3
- the third field keypublic int getMatchingOrdinal(java.lang.Object... keys)
Use a generated API or the Generic Object API to use the returned ordinal.
keys
- the field keyspublic boolean containsDuplicates()
public java.util.Collection<java.lang.Object[]> getDuplicateKeys()
public void beginUpdate()
HollowTypeStateListener
beginUpdate
in interface HollowTypeStateListener
public void addedOrdinal(int ordinal)
HollowTypeStateListener
addedOrdinal
in interface HollowTypeStateListener
ordinal
- the ordinal of an object that was addedpublic void removedOrdinal(int ordinal)
HollowTypeStateListener
removedOrdinal
in interface HollowTypeStateListener
ordinal
- the ordinal of an object that was removedpublic void endUpdate()
HollowTypeStateListener
endUpdate
in interface HollowTypeStateListener
public void destroy()
public java.lang.Object[] getRecordKey(int ordinal)