Skip to content

Commit 8998fa3

Browse files
refactor(client): adjust APIs to compatible with 1.7.0 server
1 parent 9696d78 commit 8998fa3

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

hugegraph-client/src/main/java/org/apache/hugegraph/api/graphs/GraphsAPI.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,28 @@ public void mode(String graph, GraphMode mode) {
203203
this.client.put(joinPath(this.path(), graph, MODE), null, mode);
204204
}
205205

206+
public void mode(String graph, String graphSpace, GraphMode mode) {
207+
// NOTE: Must provide id for PUT. If you use "graph/mode", "/" will
208+
// be encoded to "%2F". So use "mode" here, although inaccurate.
209+
this.client.put(joinPath(this.path(), graphSpace, graph, MODE), null, mode);
210+
}
211+
212+
public GraphMode mode(String graph, String graphSpace) {
213+
RestResult result = this.client.get(joinPath(this.path(), graphSpace, graph), MODE);
214+
@SuppressWarnings("unchecked")
215+
Map<String, String> mode = result.readObject(Map.class);
216+
String value = mode.get(MODE);
217+
if (value == null) {
218+
throw new InvalidResponseException("Invalid response, expect 'mode' in response");
219+
}
220+
try {
221+
return GraphMode.valueOf(value);
222+
} catch (IllegalArgumentException e) {
223+
throw new InvalidResponseException("Invalid GraphMode value '%s'", value);
224+
}
225+
}
226+
227+
206228
public GraphMode mode(String graph) {
207229
RestResult result = this.client.get(joinPath(this.path(), graph), MODE);
208230
@SuppressWarnings("unchecked")
@@ -218,6 +240,32 @@ public GraphMode mode(String graph) {
218240
}
219241
}
220242

243+
public void readMode(String graph, String graphSpace, GraphReadMode readMode) {
244+
this.client.checkApiVersion("0.59", "graph read mode");
245+
// NOTE: Must provide id for PUT. If you use "graph/graph_read_mode", "/"
246+
// will be encoded to "%2F". So use "graph_read_mode" here, although
247+
// inaccurate.
248+
this.client.put(joinPath(this.path(), graphSpace, graph, GRAPH_READ_MODE), null, readMode);
249+
}
250+
251+
public GraphReadMode readMode(String graph, String graphSpace) {
252+
this.client.checkApiVersion("0.59", "graph read mode");
253+
RestResult result = this.client.get(joinPath(this.path(), graphSpace, graph),
254+
GRAPH_READ_MODE);
255+
@SuppressWarnings("unchecked")
256+
Map<String, String> readMode = result.readObject(Map.class);
257+
String value = readMode.get(GRAPH_READ_MODE);
258+
if (value == null) {
259+
throw new InvalidResponseException("Invalid response, expect 'graph_read_mode' " +
260+
"in response");
261+
}
262+
try {
263+
return GraphReadMode.valueOf(value);
264+
} catch (IllegalArgumentException e) {
265+
throw new InvalidResponseException("Invalid GraphReadMode value '%s'", value);
266+
}
267+
}
268+
221269
public void readMode(String graph, GraphReadMode readMode) {
222270
this.client.checkApiVersion("0.59", "graph read mode");
223271
// NOTE: Must provide id for PUT. If you use "graph/graph_read_mode", "/"

hugegraph-client/src/main/java/org/apache/hugegraph/client/RestClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class RestClient extends AbstractRestClient {
4949
private Version apiVersion = null;
5050
@Setter
5151
@Getter
52-
private boolean supportGs = false;
52+
private boolean supportGs = true;
5353

5454
public RestClient(String url, String username, String password, int timeout) {
5555
super(url, username, password, timeout * SECOND);

hugegraph-client/src/main/java/org/apache/hugegraph/driver/GraphsManager.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,37 @@ public void mode(String graph, GraphMode mode) {
115115
this.graphsAPI.mode(graph, mode);
116116
}
117117

118+
public void mode(String graph, String graphSpace, GraphMode mode) {
119+
this.graphsAPI.mode(graph, graphSpace, mode);
120+
}
121+
118122
public GraphMode mode(String graph) {
119123
return this.graphsAPI.mode(graph);
120124
}
121125

126+
public GraphMode mode(String graph, String graphSpace) {
127+
return this.graphsAPI.mode(graph, graphSpace);
128+
}
129+
130+
public void readMode(String graph, String graphSpace, GraphReadMode readMode) {
131+
this.graphsAPI.readMode(graph, graphSpace, readMode);
132+
}
133+
122134
public void readMode(String graph, GraphReadMode readMode) {
123135
this.graphsAPI.readMode(graph, readMode);
124136
}
125137

138+
public GraphReadMode readMode(String graph, String graphSpace) {
139+
return this.graphsAPI.readMode(graph, graphSpace);
140+
}
141+
126142
public GraphReadMode readMode(String graph) {
127143
return this.graphsAPI.readMode(graph);
128144
}
129145

146+
130147
public String clone(String graph, Map<String, Object> body) {
131148
return this.graphsAPI.clone(graph, body);
132149
}
150+
133151
}

hugegraph-client/src/main/java/org/apache/hugegraph/driver/HugeClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private void checkServerApiVersion() {
173173
// 0.81 equals to the {latest_api_version} +10
174174
VersionUtil.check(apiVersion, "0.38", "0.81", "hugegraph-api in server");
175175
this.client.apiVersion(apiVersion);
176-
boolean supportGs = VersionUtil.gte(this.version.getCoreVersion(), "2.0");
176+
boolean supportGs = VersionUtil.gte(this.version.getCoreVersion(), "1.7");
177177
this.client.setSupportGs(supportGs);
178178
}
179179

0 commit comments

Comments
 (0)