Package org.infinispan.query.backend
Class KeyTransformationHandler
- java.lang.Object
-
- org.infinispan.query.backend.KeyTransformationHandler
-
public final class KeyTransformationHandler extends Object
This transforms arbitrary keys to a String which can be used by Lucene as a document identifier, and vice versa.There are 2 approaches to doing so; one for simple keys: Java primitives (and their object wrappers), byte[], Strings and UUID, and one for custom, user-defined types that could be used as keys.
For simple keys, users don't need to do anything, these keys are automatically transformed by this class.
For user-defined keys, three options are supported. Types annotated with @Transformable, and declaring an appropriate
Transformer
implementation, types for which aTransformer
has been explicitly registered through KeyTransformationHandler.registerTransformer().- Since:
- 4.0
- Author:
- Manik Surtani, Marko Luksa
- See Also:
Transformable
,Transformer
-
-
Constructor Summary
Constructors Constructor Description KeyTransformationHandler(ClassLoader classLoader)
Constructs a KeyTransformationHandler for an indexed Cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
keyToString(Object key)
Stringify a key so Lucene can use it as document id.void
registerTransformer(Class<?> keyClass, Class<? extends Transformer> transformerClass)
Registers aTransformer
for the supplied key class.Object
stringToKey(String s)
Converts a Lucene document id from string form back to the original object.
-
-
-
Constructor Detail
-
KeyTransformationHandler
public KeyTransformationHandler(ClassLoader classLoader)
Constructs a KeyTransformationHandler for an indexed Cache.- Parameters:
classLoader
- the classloader of the cache that owns this KeyTransformationHandler ornull
if the thread context classloader is to be used (acceptable for testing only!)
-
-
Method Detail
-
stringToKey
public Object stringToKey(String s)
Converts a Lucene document id from string form back to the original object.- Parameters:
s
- the string form of the key- Returns:
- the key object
-
keyToString
public String keyToString(Object key)
Stringify a key so Lucene can use it as document id.- Parameters:
key
- the key- Returns:
- a string form of the key
-
registerTransformer
public void registerTransformer(Class<?> keyClass, Class<? extends Transformer> transformerClass)
Registers aTransformer
for the supplied key class.- Parameters:
keyClass
- the key class for which the supplied transformerClass should be usedtransformerClass
- the transformer class to use for the supplied key class
-
-