Package org.infinispan.query

Examples of org.infinispan.query.Transformer


         case 'T':
            // this is a custom transformable.
            int indexOfSecondDelimiter = s.indexOf(":", 2);
            String keyClassName = s.substring(2, indexOfSecondDelimiter);
            String keyAsString = s.substring(indexOfSecondDelimiter + 1);
            Transformer t = getCustomTransformer(keyClassName, classLoader);
            if (t == null) throw new CacheException("Cannot find an appropriate Transformer for key type " + keyClassName);
            return t.fromString(keyAsString);
      }
      throw new CacheException("Unknown type metadata " + type);
   }
View Full Code Here


      }
      throw new CacheException("Unknown type metadata " + type);
   }

   private Transformer getCustomTransformer(final String keyClassName, final ClassLoader classLoader) {
      Transformer t = null;
      // try and locate class
      Class<?> keyClass = null;
      try {
         keyClass = Util.loadClassStrict(keyClassName, classLoader);
      } catch (ClassNotFoundException e) {
View Full Code Here

      char prefix = ' ';

      // First going to check if the key is a primitive or a String. Otherwise, check if it's a transformable.
      // If none of those conditions are satisfied, we'll throw an Exception.

      Transformer tf;

      if (isStringOrPrimitive(key)) {
         // Using 'X' for Shorts and 'Y' for Bytes because 'S' is used for Strings and 'B' is being used for Booleans.

         if (key instanceof byte[])
            return "A:" + Base64.encodeBytes((byte[])key)//todo [anistor] need to profile this and check performance of base64 against raw sequence of byte values
         if (key instanceof String)
            prefix = 'S';
         else if (key instanceof Integer)
            prefix = 'I';
         else if (key instanceof Boolean)
            prefix = 'B';
         else if (key instanceof Long)
            prefix = 'L';
         else if (key instanceof Float)
            prefix = 'F';
         else if (key instanceof Double)
            prefix = 'D';
         else if (key instanceof Short)
            prefix = 'X';
         else if (key instanceof Byte)
            prefix = 'Y';
         else if (key instanceof Character)
            prefix = 'C';
         else if (key instanceof UUID)
            prefix = 'U';
         return prefix + ":" + key;

      } else if ((tf = getTransformer(key.getClass())) != null) {
         // There is a bit more work to do for this case.
         return "T:" + key.getClass().getName() + ":" + tf.toString(key);
      } else
         throw new IllegalArgumentException("Indexing only works with entries keyed on Strings, primitives " +
               "and classes that have the @Transformable annotation - you passed in a " + key.getClass().toString() +
               ". Alternatively, see org.infinispan.query.SearchManager#registerKeyTransformer");
   }
View Full Code Here

         case 'T':
            // this is a custom transformable.
            int indexOfSecondDelimiter = s.indexOf(":", 2);
            String keyClassName = s.substring(2, indexOfSecondDelimiter);
            String keyAsString = s.substring(indexOfSecondDelimiter + 1);
            Transformer t;
            // try and locate class
            Class keyClass = null;
            try {
               keyClass = Thread.currentThread().getContextClassLoader().loadClass(keyClassName);
            } catch (ClassNotFoundException e) {
               log.error("Could not locate class " + keyClass, e);
            }
            t = getTransformer(keyClass);
            if (t == null) throw new CacheException("Cannot find an appropriate Transformer for key type " + keyClass);
            return t.fromString(keyAsString);
      }
      throw new CacheException("Unknown type metadata " + type);
   }
View Full Code Here

      char prefix = ' ';

      // First going to check if the key is a primitive or a String. Otherwise, check if it's a transformable.
      // If none of those conditions are satisfied, we'll throw an Exception.

      Transformer tf = null;

      if (isStringOrPrimitive(key)) {
         // Using 'X' for Shorts and 'Y' for Bytes because 'S' is used for Strings and 'B' is being used for Booleans.


         if (key instanceof String)
            prefix = 'S';
         else if (key instanceof Integer)
            prefix = 'I';
         else if (key instanceof Boolean)
            prefix = 'B';
         else if (key instanceof Long)
            prefix = 'L';
         else if (key instanceof Float)
            prefix = 'F';
         else if (key instanceof Double)
            prefix = 'D';
         else if (key instanceof Short)
            prefix = 'X';
         else if (key instanceof Byte)
            prefix = 'Y';
         else if (key instanceof Character)
            prefix = 'C';

         return prefix + ":" + key;

      } else if ((tf = getTransformer(key.getClass())) != null) {
         // There is a bit more work to do for this case.
         return "T:" + key.getClass().getName() + ":" + tf.toString(key);
      } else
         throw new IllegalArgumentException("Indexing only works with entries keyed on Strings, primitives " +
               "and classes that have the @Transformable annotation - you passed in a " + key.getClass().toString());
   }
View Full Code Here

    * @throws IllegalAccessException if a Transformer instance cannot be created vai reflection.
    * @throws InstantiationException if a Transformer instance cannot be created vai reflection.
    */
   private static Transformer getTransformer(Class<?> keyClass) {
      Transformable t = keyClass.getAnnotation(Transformable.class);
      Transformer tf = null;
      if (t != null) try {
         tf = t.transformer().newInstance();
      } catch (Exception e) {
         log.error("Cannot instantiate an instance of Transformer class " + t.transformer() + "!", e);
      }
View Full Code Here

         case 'T':
            // this is a custom transformable.
            int indexOfSecondDelimiter = s.indexOf(":", 2);
            String keyClassName = s.substring(2, indexOfSecondDelimiter);
            String keyAsString = s.substring(indexOfSecondDelimiter + 1);
            Transformer t = getCustomTransformer(keyClassName, classLoader);
            if (t == null) throw new CacheException("Cannot find an appropriate Transformer for key type " + keyClassName);
            return t.fromString(keyAsString);
      }
      throw new CacheException("Unknown type metadata " + type);
   }
View Full Code Here

      }
      throw new CacheException("Unknown type metadata " + type);
   }

   private Transformer getCustomTransformer(final String keyClassName, final ClassLoader classLoader) {
      Transformer t = null;
      // try and locate class
      Class<?> keyClass = null;
      try {
         keyClass = Util.loadClassStrict(keyClassName, classLoader);
      } catch (ClassNotFoundException e) {
View Full Code Here

      char prefix = ' ';

      // First going to check if the key is a primitive or a String. Otherwise, check if it's a transformable.
      // If none of those conditions are satisfied, we'll throw an Exception.

      Transformer tf;

      if (isStringOrPrimitive(key)) {
         // Using 'X' for Shorts and 'Y' for Bytes because 'S' is used for Strings and 'B' is being used for Booleans.

         if (key instanceof byte[])
            return "A:" + Base64.encodeBytes((byte[])key)//todo [anistor] need to profile this and check performance of base64 against raw sequence of byte values
         if (key instanceof String)
            prefix = 'S';
         else if (key instanceof Integer)
            prefix = 'I';
         else if (key instanceof Boolean)
            prefix = 'B';
         else if (key instanceof Long)
            prefix = 'L';
         else if (key instanceof Float)
            prefix = 'F';
         else if (key instanceof Double)
            prefix = 'D';
         else if (key instanceof Short)
            prefix = 'X';
         else if (key instanceof Byte)
            prefix = 'Y';
         else if (key instanceof Character)
            prefix = 'C';
         else if (key instanceof UUID)
            prefix = 'U';
         return prefix + ":" + key;

      } else if ((tf = getTransformer(key.getClass())) != null) {
         // There is a bit more work to do for this case.
         return "T:" + key.getClass().getName() + ":" + tf.toString(key);
      } else
         throw new IllegalArgumentException("Indexing only works with entries keyed on Strings, primitives " +
               "and classes that have the @Transformable annotation - you passed in a " + key.getClass().toString() +
               ". Alternatively, see org.infinispan.query.SearchManager#registerKeyTransformer");
   }
View Full Code Here

         case 'T':
            // this is a custom transformable.
            int indexOfSecondDelimiter = s.indexOf(":", 2);
            String keyClassName = s.substring(2, indexOfSecondDelimiter);
            String keyAsString = s.substring(indexOfSecondDelimiter + 1);
            Transformer t;
            // try and locate class
            Class keyClass = null;
            try {
               keyClass = Thread.currentThread().getContextClassLoader().loadClass(keyClassName);
            } catch (ClassNotFoundException e) {
               log.error("Could not locate class " + keyClass, e);
            }
            t = getTransformer(keyClass);
            if (t == null) throw new CacheException("Cannot find an appropriate Transformer for key type " + keyClass);
            return t.fromString(keyAsString);
      }
      throw new CacheException("Unknown type metadata " + type);
   }
View Full Code Here

TOP

Related Classes of org.infinispan.query.Transformer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.