From 5b8570fe7fc46682c4c8012d41e94b2d53714c51 Mon Sep 17 00:00:00 2001 From: Thespica Date: Wed, 2 Oct 2024 16:03:51 +0800 Subject: [PATCH] not delay link of soruce label and target label to avoid null links --- .../hugegraph/structure/schema/EdgeLabel.java | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java b/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java index 9d07f47bc..d29b21583 100644 --- a/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java +++ b/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/EdgeLabel.java @@ -61,6 +61,7 @@ public class EdgeLabel extends SchemaLabel { public EdgeLabel(@JsonProperty("name") String name) { super(name); this.frequency = Frequency.DEFAULT; + this.links = new HashSet<>(); this.sortKeys = new CopyOnWriteArrayList<>(); this.ttl = 0L; this.ttlStartTime = null; @@ -112,7 +113,7 @@ public Set> links() { } public boolean linkedVertexLabel(String vertexLabel) { - if (this.edgeLabelType.parent() || this.links == null) { + if (this.edgeLabelType.parent() || this.links == null || this.links.isEmpty()) { return false; } @@ -214,7 +215,6 @@ public EdgeLabel build() { @Override public EdgeLabel create() { - this.checkThenLinkSourceAndTarget(); return this.manager.addEdgeLabel(this.edgeLabel); } @@ -259,11 +259,6 @@ public Builder nullableKeys(String... keys) { @Override public Builder link(String sourceLabel, String targetLabel) { - if (this.edgeLabel.links == null) { - this.edgeLabel.links = new HashSet<>(); - this.sourceLabel = sourceLabel; - this.targetLabel = targetLabel; - } HashMap map = new HashMap<>(); map.put(sourceLabel, targetLabel); this.edgeLabel.links.add(map); @@ -292,8 +287,7 @@ public Builder asGeneral() { @Override public Builder sourceLabel(String label) { - E.checkArgument(this.edgeLabel.links == null || - this.edgeLabel.links.isEmpty(), + E.checkArgument(this.edgeLabel.links.isEmpty(), "Not allowed add source label to an edge label which " + "already has links"); this.sourceLabel = label; @@ -302,14 +296,14 @@ public Builder sourceLabel(String label) { @Override public Builder targetLabel(String label) { - E.checkArgument(this.edgeLabel.links == null || - this.edgeLabel.links.isEmpty(), + E.checkArgument(this.edgeLabel.links.isEmpty(), "Not allowed add source label to an edge label which " + "already has links"); E.checkArgument(this.sourceLabel != null, "Not allowed add target label to an edge label which " + "not has source label yet"); this.targetLabel = label; + link(this.sourceLabel, this.targetLabel); return this; } @@ -372,14 +366,6 @@ private void checkFrequency() { "Not allowed to change frequency for " + "edge label '%s'", this.edgeLabel.name); } - - private void checkThenLinkSourceAndTarget() { - E.checkArgument((this.sourceLabel != null && this.targetLabel != null) || - (this.sourceLabel == null && this.targetLabel == null), - "Not allowed to add edge label with only one " + - "source/target label"); - this.link(this.sourceLabel, this.targetLabel); - } } public static class EdgeLabelV53 extends SchemaLabel {