[infinispan-commits] Infinispan SVN: r1222 - trunk/query/src/main/java/org/infinispan/query.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Wed Nov 25 11:36:27 EST 2009
Author: manik.surtani at jboss.com
Date: 2009-11-25 11:36:26 -0500 (Wed, 25 Nov 2009)
New Revision: 1222
Modified:
trunk/query/src/main/java/org/infinispan/query/KeyTransformationHandler.java
Log:
handling custom types
Modified: trunk/query/src/main/java/org/infinispan/query/KeyTransformationHandler.java
===================================================================
--- trunk/query/src/main/java/org/infinispan/query/KeyTransformationHandler.java 2009-11-25 16:09:06 UTC (rev 1221)
+++ trunk/query/src/main/java/org/infinispan/query/KeyTransformationHandler.java 2009-11-25 16:36:26 UTC (rev 1222)
@@ -4,10 +4,20 @@
import org.infinispan.CacheException;
/**
- * // TODO: Manik: Document this
+ * This transforms arbitrary keys to a String which can be used by Lucene as a document identifier, and vice versa.
+ * <p />
+ * There are 2 approaches to doing so; one for SimpleKeys: Java primitives (and their object wrappers) and Strings,
+ * and one for custom, user-defined types that could be used as keys.
+ * <p />
+ * For SimpleKeys, users don't need to do anything, these keys are automatically transformed by this class.
+ * <p />
+ * For user-defined keys, only types annotated with @Transformable, and declaring an appropriate {@link org.infinispan.query.Transformer}
+ * implementation, are supported.
*
* @author Manik Surtani
* @since 4.0
+ * @see org.infinispan.query.Transformable
+ * @see org.infinispan.query.Transformer
*/
public class KeyTransformationHandler {
public static Object stringToKey(String s) {
@@ -49,9 +59,16 @@
// "B:f"
// "T:com.myorg.MyTransformer:STRING_GENERATED_BY_MY_TRANSFORMER"
+ char prefix = ' ';
+ if (key instanceof String)
+ prefix = 'S';
+ else if (key instanceof Integer)
+ prefix = 'I';
+ else if (key instanceof Boolean)
+ prefix = 'B';
+ /// etc etc etc
- // for now just support Strings!!
- return "S:" + key.toString();
+ return prefix + ":" + key;
}
else
throw new IllegalArgumentException("Indexing only works with entries keyed on Strings - you passed in a " + key.getClass().toString());
@@ -69,7 +86,8 @@
key instanceof Double ||
key instanceof Boolean ||
key instanceof Short ||
- key instanceof Byte
+ key instanceof Byte ||
+ key instanceof Character
)
return true;
if (key.getClass().isAnnotationPresent(Transformable.class))
More information about the infinispan-commits
mailing list