You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by al...@apache.org on 2022/06/14 13:14:01 UTC
[ignite] branch master updated: IGNITE-17138 Register custom index types in IndexKeyFactory - Fixes #10089.
This is an automated email from the ASF dual-hosted git repository.
alexpl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new af68c9f311b IGNITE-17138 Register custom index types in IndexKeyFactory - Fixes #10089.
af68c9f311b is described below
commit af68c9f311b359fcaf216cae192b10f66c4b3006
Author: Aleksey Plekhanov <pl...@gmail.com>
AuthorDate: Tue Jun 14 18:11:16 2022 +0500
IGNITE-17138 Register custom index types in IndexKeyFactory - Fixes #10089.
Signed-off-by: Aleksey Plekhanov <pl...@gmail.com>
---
.../cache/query/index/sorted/keys/IndexKeyFactory.java | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/IndexKeyFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/IndexKeyFactory.java
index c5e7b694bb2..9b02716f88d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/IndexKeyFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/IndexKeyFactory.java
@@ -18,7 +18,10 @@
package org.apache.ignite.internal.cache.query.index.sorted.keys;
import java.math.BigDecimal;
+import java.util.Map;
import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
import org.apache.ignite.IgniteException;
import org.apache.ignite.internal.binary.BinaryObjectImpl;
import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings;
@@ -30,6 +33,14 @@ import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
* Factory for creating IndexKey objects.
*/
public class IndexKeyFactory {
+ /** Registry for non-default key types factory methods (e.g., Geometry). */
+ private static final Map<Integer, Function<Object, IndexKey>> registry = new ConcurrentHashMap<>();
+
+ /** Register wrapper for custom IndexKey type. Used by Ignite extensions. */
+ public static void register(int keyType, Function<Object, IndexKey> wrapper) {
+ registry.put(keyType, wrapper);
+ }
+
/** Wraps user object to {@code IndexKey} object. */
public static IndexKey wrap(Object o, int keyType, CacheObjectValueContext coctx, IndexKeyTypeSettings keyTypeSettings) {
if (o == null || keyType == IndexKeyTypes.NULL)
@@ -72,6 +83,9 @@ public class IndexKeyFactory {
return new TimestampIndexKey(o);
}
+ if (registry.containsKey(keyType))
+ return registry.get(keyType).apply(o);
+
throw new IgniteException("Failed to wrap value[type=" + keyType + ", value=" + o + "]");
}
}