imbajin commented on code in PR #685:
URL: 
https://github.com/apache/incubator-hugegraph-toolchain/pull/685#discussion_r2465624173


##########
hugegraph-client/src/main/java/org/apache/hugegraph/api/graphs/GraphsAPI.java:
##########
@@ -198,51 +198,85 @@ public Map<String, String> reload() {
     }
 
     public void mode(String graph, GraphMode mode) {
-        // NOTE: Must provide id for PUT. If you use "graph/mode", "/" will
-        // be encoded to "%2F". So use "mode" here, although inaccurate.
-        this.client.put(joinPath(this.path(), graph, MODE), null, mode);
+        mode(null, graph, mode);
     }
 
-    public GraphMode mode(String graph) {
-        RestResult result = this.client.get(joinPath(this.path(), graph), 
MODE);
-        @SuppressWarnings("unchecked")
-        Map<String, String> mode = result.readObject(Map.class);
-        String value = mode.get(MODE);
-        if (value == null) {
-            throw new InvalidResponseException("Invalid response, expect 
'mode' in response");
-        }
-        try {
-            return GraphMode.valueOf(value);
-        } catch (IllegalArgumentException e) {
-            throw new InvalidResponseException("Invalid GraphMode value '%s'", 
value);
+    public void mode(String graphSpace, String graph, GraphMode mode) {
+        // NOTE: Must provide id for PUT. If you use "graph/mode", "/" will
+        // be encoded to "%2F". So use "mode" here, although inaccurate.
+        if (graphSpace == null) {
+            this.client.put(joinPath(this.path(), graph, MODE), null, mode);
+            return;
         }
+        this.client.put(joinPath(this.path(), graphSpace, graph, MODE), null, 
mode);
     }
 
     public void readMode(String graph, GraphReadMode readMode) {
+        readMode(null, graph, readMode);
+    }
+
+
+    public void readMode(String graphSpace, String graph, GraphReadMode 
readMode) {
         this.client.checkApiVersion("0.59", "graph read mode");
         // NOTE: Must provide id for PUT. If you use "graph/graph_read_mode", 
"/"
         // will be encoded to "%2F". So use "graph_read_mode" here, although
         // inaccurate.
-        this.client.put(joinPath(this.path(), graph, GRAPH_READ_MODE), null, 
readMode);
+        if (graphSpace == null) {
+            this.client.put(joinPath(this.path(), graph, MODE), null, 
readMode);
+            return;
+        }
+        this.client.put(joinPath(this.path(), graphSpace, graph, 
GRAPH_READ_MODE), null, readMode);
     }
 
-    public GraphReadMode readMode(String graph) {
-        this.client.checkApiVersion("0.59", "graph read mode");
-        RestResult result = this.client.get(joinPath(this.path(), graph), 
GRAPH_READ_MODE);
+    /**
+     * Get graph mode value from server response
+     *
+     * @param graphSpace the graph space name, null for non-graphspace mode
+     * @param graph the graph name
+     * @param modeKey the mode key in response (MODE or GRAPH_READ_MODE)
+     * @param enumClass the enum class type
+     * @return the mode enum value
+     */
+    private <T extends Enum<T>> T getModeValue(String graphSpace, String graph,

Review Comment:
   ⚠️ **代码可读性和可维护性**
   
   建议将 `getModeValue` 方法的可见性提升并添加更详细的 
JavaDoc。虽然这是一个很好的重构来消除代码重复,但作为私有方法,它的泛型签名可能会让后续维护者感到困惑。
   
   **可选改进:**
   - 可以考虑将三元运算符提取为单独的语句以提高可读性
   - 添加使用示例到 JavaDoc 中



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to