Make View Portable
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 4c492aa..bad8700 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 @@ new Reflections( new ConfigurationBuilder().forPackages(scanPackages.toArray(new String[0]))); Set<Class<?>> 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 7da691a..8b9674d 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 @@ @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; }