From ca570d853be290da187296899e472a09680dbdef Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Fri, 22 Jan 2021 17:31:39 +0800 Subject: [PATCH] vertex/edge get api use queryVertex/queryEdge instead of iterator also improve some code Change-Id: I0048c45c9a00bdc81a1b55129a6589043733ef9d --- .../baidu/hugegraph/api/graph/EdgeAPI.java | 2 +- .../baidu/hugegraph/api/graph/VertexAPI.java | 2 +- .../baidu/hugegraph/StandardHugeGraph.java | 20 +++++++++---------- .../schema/builder/AbstractBuilder.java | 1 - .../MultiNodeShortestPathTraverser.java | 8 +++----- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java index 4e2c45e11d..0d2031f9cc 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/EdgeAPI.java @@ -241,7 +241,7 @@ public String update(@Context GraphManager manager, boolean append = checkAndParseAction(action); HugeGraph g = graph(manager, graph); - HugeEdge edge = (HugeEdge) g.edges(id).next(); + HugeEdge edge = (HugeEdge) g.edge(id); EdgeLabel edgeLabel = edge.schemaLabel(); for (String key : jsonEdge.properties.keySet()) { diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/VertexAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/VertexAPI.java index e811287ccc..dbf492581b 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/VertexAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/VertexAPI.java @@ -201,7 +201,7 @@ public String update(@Context GraphManager manager, boolean append = checkAndParseAction(action); HugeGraph g = graph(manager, graph); - HugeVertex vertex = (HugeVertex) g.vertices(id).next(); + HugeVertex vertex = (HugeVertex) g.vertex(id); VertexLabel vertexLabel = vertex.schemaLabel(); for (String key : jsonVertex.properties.keySet()) { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java index d2de38457c..dbb4ac055b 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java @@ -107,16 +107,16 @@ public class StandardHugeGraph implements HugeGraph { StandardHugeGraph.SysTransaction.class }; - public static final Set ALLOWED_CONFIGS = ImmutableSet.of( - CoreOptions.TASK_WAIT_TIMEOUT, - CoreOptions.TASK_SYNC_DELETION, - CoreOptions.TASK_TTL_DELETE_BATCH, - CoreOptions.TASK_INPUT_SIZE_LIMIT, - CoreOptions.TASK_RESULT_SIZE_LIMIT, - CoreOptions.OLTP_CONCURRENT_THREADS, - CoreOptions.OLTP_CONCURRENT_DEPTH, - CoreOptions.VERTEX_DEFAULT_LABEL, - CoreOptions.VERTEX_ENCODE_PK_NUMBER + public static final Set> ALLOWED_CONFIGS = ImmutableSet.of( + CoreOptions.TASK_WAIT_TIMEOUT, + CoreOptions.TASK_SYNC_DELETION, + CoreOptions.TASK_TTL_DELETE_BATCH, + CoreOptions.TASK_INPUT_SIZE_LIMIT, + CoreOptions.TASK_RESULT_SIZE_LIMIT, + CoreOptions.OLTP_CONCURRENT_THREADS, + CoreOptions.OLTP_CONCURRENT_DEPTH, + CoreOptions.VERTEX_DEFAULT_LABEL, + CoreOptions.VERTEX_ENCODE_PK_NUMBER ); private static final Logger LOG = Log.logger(HugeGraph.class); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/AbstractBuilder.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/AbstractBuilder.java index 61f7e8fe7b..152f6584dd 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/AbstractBuilder.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/AbstractBuilder.java @@ -26,7 +26,6 @@ import com.baidu.hugegraph.backend.id.Id; import com.baidu.hugegraph.backend.id.IdGenerator; import com.baidu.hugegraph.backend.tx.SchemaTransaction; -import com.baidu.hugegraph.config.CoreOptions; import com.baidu.hugegraph.exception.ExistedException; import com.baidu.hugegraph.schema.EdgeLabel; import com.baidu.hugegraph.schema.IndexLabel; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/MultiNodeShortestPathTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/MultiNodeShortestPathTraverser.java index c4978f3c3c..de047284c3 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/MultiNodeShortestPathTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/MultiNodeShortestPathTraverser.java @@ -36,8 +36,6 @@ import com.baidu.hugegraph.type.define.Directions; import com.baidu.hugegraph.util.E; -import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path.EMPTY_PATH; - public class MultiNodeShortestPathTraverser extends OltpTraverser { public MultiNodeShortestPathTraverser(HugeGraph graph) { @@ -82,7 +80,7 @@ public List multiNodeShortestPathConcurrent(List> pairs, this.traversePairs(pairs.iterator(), pair -> { Path path = traverser.shortestPath(pair.getLeft(), pair.getRight(), step, maxDepth, capacity); - if (!EMPTY_PATH.equals(path)) { + if (!Path.EMPTY_PATH.equals(path)) { results.add(path); } }); @@ -99,7 +97,7 @@ public List multiNodeShortestPathSingle(List> pairs, for (Pair pair : pairs) { Path path = traverser.shortestPath(pair.getLeft(), pair.getRight(), step, maxDepth, capacity); - if (!EMPTY_PATH.equals(path)) { + if (!Path.EMPTY_PATH.equals(path)) { results.add(path); } } @@ -109,7 +107,7 @@ public List multiNodeShortestPathSingle(List> pairs, private static void cmn(List all, int m, int n, int current, List result, Consumer> consumer) { assert m <= all.size(); - assert current < all.size(); + assert current <= all.size(); if (result == null) { result = new ArrayList<>(n); }