Skip to content

Commit 5b7d416

Browse files
committed
code cleanup, remove duplicated code
1 parent a30ba55 commit 5b7d416

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

src/main/java/com/redislabs/redisgraph/RedisGraphAPI.java

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,33 +63,24 @@ public RedisGraphAPI(String graphId, Pool<Jedis> jedis) {
6363
}
6464

6565
/**
66-
* Execute a Cypher query
67-
*
68-
* @param query Cypher query
69-
* @return a result set
70-
*/
71-
public ResultSet query(String query) {
72-
try (Jedis conn = getConnection()) {
73-
return new ResultSetImpl(sendCommand(conn, Command.QUERY, graphId, query).getObjectMultiBulkReply());
74-
}
75-
}
76-
77-
/**
78-
* Execute a Cypher query
66+
* Execute a Cypher query with arguments
7967
*
8068
* @param query Cypher query
69+
* @param args
8170
* @return a result set
8271
*/
8372
public ResultSet query(String query, Object ...args) {
84-
for(int i=0; i<args.length; ++i) {
85-
if(args[i] instanceof String) {
86-
args[i] = "\'" + ESCAPE_CHYPER.translate((String)args[i]) + "\'";
73+
if(args.length > 0) {
74+
for(int i=0; i<args.length; ++i) {
75+
if(args[i] instanceof String) {
76+
args[i] = "\'" + ESCAPE_CHYPER.translate((String)args[i]) + "\'";
77+
}
8778
}
79+
query = String.format(query, args);
8880
}
89-
90-
query = String.format(query, args);
81+
9182
try (Jedis conn = getConnection()) {
92-
return new ResultSetImpl(sendCommand(conn, Command.QUERY, graphId, query).getObjectMultiBulkReply());
83+
return new ResultSetImpl(sendCommand(conn, Command.QUERY, graphId, query).getObjectMultiBulkReply());
9384
}
9485
}
9586

@@ -100,11 +91,10 @@ public ResultSet query(String query, Object ...args) {
10091
* @return delete running time statistics
10192
*/
10293
public String deleteGraph() {
103-
try (Jedis conn = getConnection()) {
104-
return sendCommand(conn, Command.DELETE, graphId).getBulkReply();
105-
}
106-
}
107-
94+
try (Jedis conn = getConnection()) {
95+
return sendCommand(conn, Command.DELETE, graphId).getBulkReply();
96+
}
97+
}
10898

10999
private BinaryClient sendCommand(Jedis conn, ProtocolCommand provider, String ...args) {
110100
BinaryClient binaryClient = conn.getClient();

0 commit comments

Comments
 (0)