Content-Length: 27253 | pFad | http://github.com/RedisGraph/JRedisGraph/pull/105.diff
thub.com
diff --git a/src/main/java/com/redislabs/redisgraph/RedisGraph.java b/src/main/java/com/redislabs/redisgraph/RedisGraph.java
index 3a2ae19..6cc57ce 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 readOnlyQuery(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 readOnlyQuery(String graphId, String query, long timeout);
+
+
/**
* Execute a Cypher query with arguments
* @param graphId a graph to perform the query on
@@ -34,6 +52,7 @@ public interface RedisGraph extends Closeable {
@Deprecated
ResultSet query(String graphId, String query, Object ...args);
+
/**
* Executes a cypher query with parameters.
* @param graphId a graph to perform the query on.
@@ -43,6 +62,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 readOnlyQuery(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 +81,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 readOnlyQuery(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/RedisGraphTransaction.java b/src/main/java/com/redislabs/redisgraph/RedisGraphTransaction.java
index 08259fe..cbcd127 100644
--- a/src/main/java/com/redislabs/redisgraph/RedisGraphTransaction.java
+++ b/src/main/java/com/redislabs/redisgraph/RedisGraphTransaction.java
@@ -31,6 +31,14 @@ public interface RedisGraphTransaction extends
*/
Response 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 response which builds the result set with the query answer.
+ */
+ Response readOnlyQuery(String graphId, String query);
+
/**
* Execute a Cypher query with timeout.
* @param graphId a graph to perform the query on
@@ -40,6 +48,15 @@ public interface RedisGraphTransaction extends
*/
Response 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 response which builds the result set with the query answer.
+ */
+ Response readOnlyQuery(String graphId, String query, long timeout);
+
/**
* Execute a Cypher query with arguments
* @param graphId a graph to perform the query on
@@ -60,6 +77,15 @@ public interface RedisGraphTransaction extends
*/
Response 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 response which builds the result set with the query answer.
+ */
+ Response readOnlyQuery(String graphId, String query, Map params);
+
/**
* Executes a cypher query with parameters and timeout.
* @param graphId a graph to perform the query on.
@@ -70,6 +96,16 @@ public interface RedisGraphTransaction extends
*/
Response 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 response which builds the result set with the query answer.
+ */
+ Response readOnlyQuery(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..57fce53 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 readOnlyQuery(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 readOnlyQuery(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
@@ -84,6 +123,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 readOnlyQuery(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 +149,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 readOnlyQuery(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 7918c37..92896d0 100644
--- a/src/main/java/com/redislabs/redisgraph/impl/api/ContextedRedisGraph.java
+++ b/src/main/java/com/redislabs/redisgraph/impl/api/ContextedRedisGraph.java
@@ -59,6 +59,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