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 a Transformer has 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:
  • Constructor Details

    • KeyTransformationHandler

      public KeyTransformationHandler(ClassLoader classLoader)
      Constructs a KeyTransformationHandler for an indexed Cache.
      Parameters:
      classLoader - the classloader of the cache that owns this KeyTransformationHandler or null if the thread context classloader is to be used (acceptable for testing only!)
  • Method Details

    • 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 a Transformer for the supplied key class.
      Parameters:
      keyClass - the key class for which the supplied transformerClass should be used
      transformerClass - the transformer class to use for the supplied key class