Content-Length: 47364 | pFad | http://github.com/RedisGraph/JRedisGraph/pull/105.patch
thub.com
From b4ea3926cdadbef64e75798272e48a53d23476e5 Mon Sep 17 00:00:00 2001
From: filipecosta90
Date: Thu, 21 Jan 2021 22:43:23 +0000
Subject: [PATCH 1/8] Add support for graph.RO_QUERY command
---
.../com/redislabs/redisgraph/RedisGraph.java | 48 +++++++++++
.../impl/api/AbstractRedisGraph.java | 79 +++++++++++++++++++
.../impl/api/ContextedRedisGraph.java | 44 +++++++++++
.../redisgraph/impl/api/RedisGraph.java | 31 ++++++++
.../impl/api/RedisGraphCommand.java | 1 +
.../redisgraph/RedisGraphAPITest.java | 44 +++++++++++
6 files changed, 247 insertions(+)
diff --git a/src/main/java/com/redislabs/redisgraph/RedisGraph.java b/src/main/java/com/redislabs/redisgraph/RedisGraph.java
index 3a2ae19..187ca3c 100644
--- a/src/main/java/com/redislabs/redisgraph/RedisGraph.java
+++ b/src/main/java/com/redislabs/redisgraph/RedisGraph.java
@@ -14,6 +14,14 @@ public interface RedisGraph extends Closeable {
*/
ResultSet query(String graphId, String query);
+ /**
+ * Execute a Cypher read-only query.
+ * @param graphId a graph to perform the query on
+ * @param query Cypher query
+ * @return a result set
+ */
+ ResultSet queryReadOnly(String graphId, String query);
+
/**
* Execute a Cypher query with timeout.
* @param graphId a graph to perform the query on
@@ -23,6 +31,16 @@ public interface RedisGraph extends Closeable {
*/
ResultSet query(String graphId, String query, long timeout);
+ /**
+ * Execute a Cypher read-only query with timeout.
+ * @param graphId a graph to perform the query on
+ * @param query Cypher query
+ * @param timeout
+ * @return a result set
+ */
+ ResultSet queryReadOnly(String graphId, String query, long timeout);
+
+
/**
* Execute a Cypher query with arguments
* @param graphId a graph to perform the query on
@@ -34,6 +52,17 @@ public interface RedisGraph extends Closeable {
@Deprecated
ResultSet query(String graphId, String query, Object ...args);
+ /**
+ * Execute a Cypher read-only query with arguments
+ * @param graphId a graph to perform the query on
+ * @param query Cypher query
+ * @param args
+ * @return a result set
+ * @deprecated use {@link #query(String, String, Map)} instead.
+ */
+ @Deprecated
+ ResultSet queryReadOnly(String graphId, String query, Object ...args);
+
/**
* Executes a cypher query with parameters.
* @param graphId a graph to perform the query on.
@@ -43,6 +72,15 @@ public interface RedisGraph extends Closeable {
*/
ResultSet query(String graphId, String query, Map params);
+ /**
+ * Executes a cypher read-only query with parameters.
+ * @param graphId a graph to perform the query on.
+ * @param query Cypher query.
+ * @param params parameters map.
+ * @return a result set.
+ */
+ ResultSet queryReadOnly(String graphId, String query, Map params);
+
/**
* Executes a cypher query with parameters and timeout.
* @param graphId a graph to perform the query on.
@@ -53,6 +91,16 @@ public interface RedisGraph extends Closeable {
*/
ResultSet query(String graphId, String query, Map params, long timeout);
+ /**
+ * Executes a cypher read-only query with parameters and timeout.
+ * @param graphId a graph to perform the query on.
+ * @param query Cypher query.
+ * @param params parameters map.
+ * @param timeout
+ * @return a result set.
+ */
+ ResultSet queryReadOnly(String graphId, String query, Map params, long timeout);
+
/**
* Invokes stored procedures without arguments
* @param graphId a graph to perform the query on
diff --git a/src/main/java/com/redislabs/redisgraph/impl/api/AbstractRedisGraph.java b/src/main/java/com/redislabs/redisgraph/impl/api/AbstractRedisGraph.java
index e1149e0..973297f 100644
--- a/src/main/java/com/redislabs/redisgraph/impl/api/AbstractRedisGraph.java
+++ b/src/main/java/com/redislabs/redisgraph/impl/api/AbstractRedisGraph.java
@@ -27,6 +27,14 @@ public abstract class AbstractRedisGraph implements RedisGraph {
*/
protected abstract ResultSet sendQuery(String graphId, String preparedQuery);
+ /**
+ * Sends a read-only query to the redis graph. Implementation and context dependent
+ * @param graphId graph to be queried
+ * @param preparedQuery prepared query
+ * @return Result set
+ */
+ protected abstract ResultSet sendReadOnlyQuery(String graphId, String preparedQuery);
+
/**
* Sends a query to the redis graph.Implementation and context dependent
* @param graphId graph to be queried
@@ -36,6 +44,15 @@ public abstract class AbstractRedisGraph implements RedisGraph {
*/
protected abstract ResultSet sendQuery(String graphId, String preparedQuery, long timeout);
+ /**
+ * Sends a read-query to the redis graph.Implementation and context dependent
+ * @param graphId graph to be queried
+ * @param preparedQuery prepared query
+ * @param timeout
+ * @return Result set
+ */
+ protected abstract ResultSet sendReadOnlyQuery(String graphId, String preparedQuery, long timeout);
+
/**
* Execute a Cypher query.
* @param graphId a graph to perform the query on
@@ -46,6 +63,16 @@ public ResultSet query(String graphId, String query) {
return sendQuery(graphId, query);
}
+ /**
+ * Execute a Cypher read-only query.
+ * @param graphId a graph to perform the query on
+ * @param query Cypher query
+ * @return a result set
+ */
+ public ResultSet queryReadOnly(String graphId, String query) {
+ return sendReadOnlyQuery(graphId, query);
+ }
+
/**
* Execute a Cypher query with timeout.
* @param graphId a graph to perform the query on
@@ -58,6 +85,18 @@ public ResultSet query(String graphId, String query, long timeout) {
return sendQuery(graphId, query, timeout);
}
+ /**
+ * Execute a Cypher read-only query with timeout.
+ * @param graphId a graph to perform the query on
+ * @param timeout
+ * @param query Cypher query
+ * @return a result set
+ */
+ @Override
+ public ResultSet queryReadOnly(String graphId, String query, long timeout) {
+ return sendReadOnlyQuery(graphId, query, timeout);
+ }
+
/**
* Execute a Cypher query with arguments
* @param graphId a graph to perform the query on
@@ -72,6 +111,20 @@ public ResultSet query(String graphId, String query, Object ...args) {
return sendQuery(graphId, preparedQuery);
}
+ /**
+ * Execute a Cypher read-only query with arguments
+ * @param graphId a graph to perform the query on
+ * @param query Cypher query
+ * @param args
+ * @return a result set
+ * @deprecated use {@link #query(String, String, Map)} instead.
+ */
+ @Deprecated
+ public ResultSet queryReadOnly(String graphId, String query, Object ...args) {
+ String preparedQuery = Utils.prepareQuery(query, args);
+ return sendReadOnlyQuery(graphId, preparedQuery);
+ }
+
/**
* Executes a cypher query with parameters.
* @param graphId a graph to perform the query on.
@@ -84,6 +137,18 @@ public ResultSet query(String graphId, String query, Map params)
return sendQuery(graphId, preparedQuery);
}
+ /**
+ * Executes a cypher read-only query with parameters.
+ * @param graphId a graph to perform the query on.
+ * @param query Cypher query.
+ * @param params parameters map.
+ * @return a result set.
+ */
+ public ResultSet queryReadOnly(String graphId, String query, Map params) {
+ String preparedQuery = Utils.prepareQuery(query, params);
+ return sendReadOnlyQuery(graphId, preparedQuery);
+ }
+
/**
* Executes a cypher query with parameters and timeout.
* @param graphId a graph to perform the query on.
@@ -98,6 +163,20 @@ public ResultSet query(String graphId, String query, Map params,
return sendQuery(graphId, preparedQuery, timeout);
}
+ /**
+ * Executes a cypher read-only query with parameters and timeout.
+ * @param graphId a graph to perform the query on.
+ * @param timeout
+ * @param query Cypher query.
+ * @param params parameters map.
+ * @return a result set.
+ */
+ @Override
+ public ResultSet queryReadOnly(String graphId, String query, Map params, long timeout) {
+ String preparedQuery = Utils.prepareQuery(query, params);
+ return sendReadOnlyQuery(graphId, preparedQuery, timeout);
+ }
+
public ResultSet callProcedure(String graphId, String procedure){
return callProcedure(graphId, procedure, Utils.DUMMY_LIST, Utils.DUMMY_MAP);
}
diff --git a/src/main/java/com/redislabs/redisgraph/impl/api/ContextedRedisGraph.java b/src/main/java/com/redislabs/redisgraph/impl/api/ContextedRedisGraph.java
index fb9fce9..01eed6c 100644
--- a/src/main/java/com/redislabs/redisgraph/impl/api/ContextedRedisGraph.java
+++ b/src/main/java/com/redislabs/redisgraph/impl/api/ContextedRedisGraph.java
@@ -60,6 +60,27 @@ protected ResultSet sendQuery(String graphId, String preparedQuery) {
}
}
+ /**
+ * Sends the read-only query over the instance only connection
+ * @param graphId graph to be queried
+ * @param preparedQuery prepared query
+ * @return Result set with the query answer
+ */
+ @Override
+ protected ResultSet sendReadOnlyQuery(String graphId, String preparedQuery) {
+ Jedis conn = getConnection();
+ try {
+ List