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
Transformerimplementation, types for which aTransformerhas been explicitly registered through KeyTransformationHandler.registerTransformer() or through the indexing configuration (IndexingConfigurationBuilder.addKeyTransformer(java.lang.Class<?>, java.lang.Class<?>)).- 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 StringkeyToString(Object key)Stringify a key so Lucene can use it as document id.voidregisterTransformer(Class<?> keyClass, Class<? extends Transformer> transformerClass)Registers aTransformerfor the supplied key class.ObjectstringToKey(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 ornullif 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 aTransformerfor 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
-
-