Skip to content

Commit da285ac

Browse files
Fix(client): fixed GraphAPI & wrong logic of setting GS in RestClient
1 parent 9101077 commit da285ac

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ public Map<String, String> reload() {
198198
}
199199

200200
public void mode(String graph, GraphMode mode) {
201-
// NOTE: Must provide id for PUT. If you use "graph/mode", "/" will
202-
// be encoded to "%2F". So use "mode" here, although inaccurate.
203-
this.client.put(joinPath(this.path(), graph, MODE), null, mode);
201+
mode(null, graph, mode);
204202
}
205203

206204
public void mode(String graphSpace, String graph, GraphMode mode) {
@@ -213,6 +211,11 @@ public void mode(String graphSpace, String graph, GraphMode mode) {
213211
this.client.put(joinPath(this.path(), graphSpace, graph, MODE), null, mode);
214212
}
215213

214+
public void readMode(String graph, GraphReadMode readMode) {
215+
readMode(null, graph, readMode);
216+
}
217+
218+
216219
public void readMode(String graphSpace, String graph, GraphReadMode readMode) {
217220
this.client.checkApiVersion("0.59", "graph read mode");
218221
// NOTE: Must provide id for PUT. If you use "graph/graph_read_mode", "/"
@@ -225,15 +228,16 @@ public void readMode(String graphSpace, String graph, GraphReadMode readMode) {
225228
this.client.put(joinPath(this.path(), graphSpace, graph, GRAPH_READ_MODE), null, readMode);
226229
}
227230

228-
public void readMode(String graph, GraphReadMode readMode) {
229-
this.client.checkApiVersion("0.59", "graph read mode");
230-
// NOTE: Must provide id for PUT. If you use "graph/graph_read_mode", "/"
231-
// will be encoded to "%2F". So use "graph_read_mode" here, although
232-
// inaccurate.
233-
this.client.put(joinPath(this.path(), graph, GRAPH_READ_MODE), null, readMode);
234-
}
235-
236-
private <T extends Enum<T>> T getEnumMode(String graphSpace, String graph,
231+
/**
232+
* Get graph mode value from server response
233+
*
234+
* @param graphSpace the graph space name, null for non-graphspace mode
235+
* @param graph the graph name
236+
* @param modeKey the mode key in response (MODE or GRAPH_READ_MODE)
237+
* @param enumClass the enum class type
238+
* @return the mode enum value
239+
*/
240+
private <T extends Enum<T>> T getModeValue(String graphSpace, String graph,
237241
String modeKey, Class<T> enumClass) {
238242
String path = (graphSpace != null)
239243
? joinPath(this.path(), graphSpace, graph)
@@ -257,21 +261,20 @@ private <T extends Enum<T>> T getEnumMode(String graphSpace, String graph,
257261
}
258262

259263
public GraphMode mode(String graphSpace, String graph) {
260-
return getEnumMode(graphSpace, graph, MODE, GraphMode.class);
264+
return getModeValue(graphSpace, graph, MODE, GraphMode.class);
261265
}
262266

263267
public GraphMode mode(String graph) {
264-
return getEnumMode(null, graph, MODE, GraphMode.class);
268+
return mode(null, graph);
265269
}
266270

267271
public GraphReadMode readMode(String graphSpace, String graph) {
268272
this.client.checkApiVersion("0.59", "graph read mode");
269-
return getEnumMode(graphSpace, graph, GRAPH_READ_MODE, GraphReadMode.class);
273+
return getModeValue(graphSpace, graph, GRAPH_READ_MODE, GraphReadMode.class);
270274
}
271275

272276
public GraphReadMode readMode(String graph) {
273-
this.client.checkApiVersion("0.59", "graph read mode");
274-
return getEnumMode(null, graph, GRAPH_READ_MODE, GraphReadMode.class);
277+
return readMode(null, graph);
275278
}
276279

277280
public String clone(String graph, Map<String, Object> body) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
public class RestClient extends AbstractRestClient {
4141

4242
private static final int SECOND = 1000;
43-
private final String version = new VersionManager(this).getCoreVersion();;
43+
private String version;
44+
@Setter
45+
private boolean supportGs;
4446

4547
static {
4648
SimpleModule module = new SimpleModule();
@@ -49,9 +51,6 @@ public class RestClient extends AbstractRestClient {
4951
}
5052

5153
private Version apiVersion = null;
52-
@Setter
53-
@Getter
54-
private boolean supportGs = VersionUtil.gte(version, "1.7.0");
5554

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

0 commit comments

Comments
 (0)