Gigamap custom type indexers? #442
-
|
Gigamap provides built-in indexers for: UUID , Long , etc. But how do I implement a custom indexer for a type like TSID (compact replacement of UUID)? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
The quick version would be this one. The Tsid consists of a single long and is probably of high cardinality, so a binary indexer would be the optimal solution. final static BinaryIndexer<MyEntity> tsidIndex = new BinaryIndexer.Abstract<>()
{
@Override
public long indexBinary(final MyEntity entity)
{
return entity.getTsid().toLong();
}
}; |
Beta Was this translation helpful? Give feedback.
-
|
If you want a nice reusable, typed indexer for Tsids, this is the implementation: public abstract class TsidIndexer<E> extends BinaryIndexer.Abstract<E>
{
@Override
public final long indexBinary(final E entity)
{
return this.getTsid(entity).toLong();
}
protected abstract Tsid getTsid(E entity);
public <S extends E> Condition<S> is(final Tsid id)
{
return super.is(id.toLong());
}
}and this the usage final static TsidIndexer<MyEntity> tsidIndex = new TsidIndexer<>()
{
@Override
protected Tsid getTsid(final MyEntity entity)
{
return entity.getTsid();
}
}; |
Beta Was this translation helpful? Give feedback.
-
|
@fh-ms what if I have a value of NULL? A binary indexer will not be able to handle this? If I map the NULL Tsid to 0L (long value), the indexer will throw an exception as it expects long values>0 ? My current workaround is to map it to Long.MAX_VALUE, but would prefer 0L. |
Beta Was this translation helpful? Give feedback.
If you want a nice reusable, typed indexer for Tsids, this is the implementation:
and this the usage