From 920af6454eab3afa71c93e882af4d7e18c30181a Mon Sep 17 00:00:00 2001 From: JackieTien97 Date: Fri, 18 Aug 2023 15:01:04 +0800 Subject: [PATCH] Make View Portable --- .../mtree/loader/MNodeFactoryLoader.java | 21 ++++++++++++++++--- .../schema/node/utils/MNodeFactory.java | 7 +++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/loader/MNodeFactoryLoader.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/loader/MNodeFactoryLoader.java index 4c492aa860..bad8700b39 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/loader/MNodeFactoryLoader.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/loader/MNodeFactoryLoader.java @@ -87,27 +87,42 @@ public class MNodeFactoryLoader { new Reflections( new ConfigurationBuilder().forPackages(scanPackages.toArray(new String[0]))); Set> nodeFactorySet = reflections.getTypesAnnotatedWith(MNodeFactory.class); + IMNodeFactory res = null; + int priority = Integer.MIN_VALUE; for (Class nodeFactory : nodeFactorySet) { if (isGenericMatch(nodeFactory, nodeType) && isEnvMatch(nodeFactory, env)) { try { - return (IMNodeFactory) nodeFactory.getDeclaredConstructor().newInstance(); + MNodeFactory annotationInfo = nodeFactory.getAnnotation(MNodeFactory.class); + if (annotationInfo.priority() > priority) { + res = (IMNodeFactory) nodeFactory.getDeclaredConstructor().newInstance(); + } } catch (Exception e) { throw new SchemaExecutionException(e); } } } + if (res != null) { + return res; + } // if no satisfied MNodeFactory in customer env found, use default env for (Class nodeFactory : nodeFactorySet) { if (isGenericMatch(nodeFactory, nodeType) && isEnvMatch(nodeFactory, SchemaConstant.DEFAULT_MNODE_FACTORY_ENV)) { try { - return (IMNodeFactory) nodeFactory.getDeclaredConstructor().newInstance(); + MNodeFactory annotationInfo = nodeFactory.getAnnotation(MNodeFactory.class); + if (annotationInfo.priority() > priority) { + res = (IMNodeFactory) nodeFactory.getDeclaredConstructor().newInstance(); + } } catch (Exception e) { throw new SchemaExecutionException(e); } } } - throw new SchemaExecutionException("No satisfied MNodeFactory found"); + if (res != null) { + return res; + } else { + throw new SchemaExecutionException("No satisfied MNodeFactory found"); + } } public boolean isGenericMatch(Class factory, Class targetType) { diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/node/utils/MNodeFactory.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/node/utils/MNodeFactory.java index 7da691a05a..8b9674d42b 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/node/utils/MNodeFactory.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/node/utils/MNodeFactory.java @@ -28,4 +28,11 @@ import java.lang.annotation.Target; @Target(ElementType.TYPE) public @interface MNodeFactory { String env() default "IoTDB"; + + /** + * The higher the number, the higher the priority. + * + * @return the priority of this class. + */ + int priority() default 0; } -- GitLab