diff --git a/fuse-core/pom.xml b/fuse-core/pom.xml
index bca0a2cb0..0c61a55f4 100644
--- a/fuse-core/pom.xml
+++ b/fuse-core/pom.xml
@@ -47,6 +47,10 @@
org.elasticsearch.client
transport
+
+ org.reflections
+ reflections
+
diff --git a/fuse-core/src/main/java/com/yangdb/fuse/dispatcher/cursor/CursorFactory.java b/fuse-core/src/main/java/com/yangdb/fuse/dispatcher/cursor/CursorFactory.java
index 0597af3ae..893a14447 100644
--- a/fuse-core/src/main/java/com/yangdb/fuse/dispatcher/cursor/CursorFactory.java
+++ b/fuse-core/src/main/java/com/yangdb/fuse/dispatcher/cursor/CursorFactory.java
@@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,7 +21,15 @@
*/
import com.yangdb.fuse.dispatcher.resource.QueryResource;
+import com.yangdb.fuse.model.transport.CreatePageRequest;
import com.yangdb.fuse.model.transport.cursor.CreateCursorRequest;
+import com.yangdb.fuse.model.transport.cursor.LogicalGraphCursorRequest;
+import org.reflections.Reflections;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Optional;
+import java.util.Set;
/**
* Created by Roman on 02/04/2017.
@@ -29,9 +37,10 @@
public interface CursorFactory {
interface Context {
QueryResource getQueryResource();
+
CreateCursorRequest getCursorRequest();
- class Impl implements Context{
+ class Impl implements Context {
//region Constructors
public Impl(QueryResource queryResource, CreateCursorRequest cursorRequest) {
this.queryResource = queryResource;
@@ -57,4 +66,37 @@ public CreateCursorRequest getCursorRequest() {
}
Cursor createCursor(Context context);
+
+ /**
+ * resolve cursor request class name by CursorType value
+ * @param cursorTypeName
+ * @return
+ */
+ static Class extends CreateCursorRequest> resolve(String cursorTypeName) {
+ Reflections reflections = new Reflections("com.yangdb.fuse");
+ Set> allClasses = reflections.getSubTypesOf(CreateCursorRequest.class);
+ Optional> cursorType = allClasses.stream().filter(clazz -> {
+ try {
+ //get value of static field member
+ return clazz.getField("CursorType").get(null).equals(cursorTypeName);
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }).findFirst();
+
+ return cursorType.isPresent() ? cursorType.get() : LogicalGraphCursorRequest.class;
+ }
+
+ /**
+ * generate cursor request based on given params
+ * @param cursorTypeName
+ * @return
+ */
+ static CreateCursorRequest request(String cursorTypeName, CreatePageRequest pageRequest) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
+ Class extends CreateCursorRequest> cursor = resolve(cursorTypeName);
+ Constructor extends CreateCursorRequest> constructor = cursor.getConstructor(pageRequest.getClass());
+ return constructor.newInstance(pageRequest);
+ }
+
}
diff --git a/fuse-core/src/main/java/com/yangdb/fuse/dispatcher/driver/QueryDriver.java b/fuse-core/src/main/java/com/yangdb/fuse/dispatcher/driver/QueryDriver.java
index 9af2b10e4..dc6be9b35 100644
--- a/fuse-core/src/main/java/com/yangdb/fuse/dispatcher/driver/QueryDriver.java
+++ b/fuse-core/src/main/java/com/yangdb/fuse/dispatcher/driver/QueryDriver.java
@@ -51,7 +51,7 @@ public interface QueryDriver {
Optional createAndFetch(CreateQueryRequest queryRequest);
- Optional