diff --git a/pom.xml b/pom.xml
index 8fd22c7..2b2c133 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,7 +46,7 @@
repo
-
+
org.apache.commons
@@ -62,7 +62,7 @@
redis.clients
jedis
- 3.0.1
+ 3.1.0
org.apache.commons
@@ -179,7 +179,7 @@
org.apache.maven.plugins
maven-pmd-plugin
- 3.11.0
+ 3.12.0
diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF
index 425ebf5..7356ba4 100644
--- a/src/main/java/META-INF/MANIFEST.MF
+++ b/src/main/java/META-INF/MANIFEST.MF
@@ -1,3 +1,3 @@
-Manifest-Version: 1.0
-Main-Class: com.redislabs.redisgraph.RedisGraphAPI
-
+Manifest-Version: 1.0
+Main-Class: com.redislabs.redisgraph.RedisGraph
+
diff --git a/src/main/java/com/redislabs/redisgraph/Header.java b/src/main/java/com/redislabs/redisgraph/Header.java
index 43cf8b3..a8156aa 100644
--- a/src/main/java/com/redislabs/redisgraph/Header.java
+++ b/src/main/java/com/redislabs/redisgraph/Header.java
@@ -3,16 +3,16 @@
import java.util.List;
/**
- * Query response header interface. Represents the response schame (column names and types)
+ * Query response header interface. Represents the response schema (column names and types)
*/
public interface Header {
- public enum ResultSetColumnTypes {
+ enum ResultSetColumnTypes {
COLUMN_UNKNOWN,
COLUMN_SCALAR,
COLUMN_NODE,
- COLUMN_RELATION;
+ COLUMN_RELATION
}
diff --git a/src/main/java/com/redislabs/redisgraph/RedisGraph.java b/src/main/java/com/redislabs/redisgraph/RedisGraph.java
index 9c0871d..90432bd 100644
--- a/src/main/java/com/redislabs/redisgraph/RedisGraph.java
+++ b/src/main/java/com/redislabs/redisgraph/RedisGraph.java
@@ -1,101 +1,19 @@
package com.redislabs.redisgraph;
-import com.redislabs.redisgraph.impl.graph_cache.GraphCache;
-import com.redislabs.redisgraph.impl.ResultSetImpl;
-import org.apache.commons.text.translate.AggregateTranslator;
-import org.apache.commons.text.translate.CharSequenceTranslator;
-import org.apache.commons.text.translate.LookupTranslator;
-import redis.clients.jedis.BinaryClient;
-import redis.clients.jedis.Jedis;
-import redis.clients.jedis.JedisPool;
-import redis.clients.jedis.commands.ProtocolCommand;
-import redis.clients.jedis.util.Pool;
-
import java.io.Closeable;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.stream.Collectors;
-
-
-/**
- *
- */
-public class RedisGraph implements Closeable {
-
-
-
- private final Pool client;
- private final Map graphCaches = new ConcurrentHashMap<>();
-
-
-
- private static final CharSequenceTranslator ESCAPE_CHYPER;
- static {
- final Map escapeJavaMap = new HashMap<>();
- escapeJavaMap.put("\'", "\\'");
- escapeJavaMap.put("\"", "\\\"");
- ESCAPE_CHYPER = new AggregateTranslator(new LookupTranslator(Collections.unmodifiableMap(escapeJavaMap)));
- }
-
- /**
- * Creates a client running on the local machine
-
- */
- public RedisGraph() {
- this("localhost", 6379);
- }
-
- /**
- * Creates a client running on the specific host/post
- *
- * @param host Redis host
- * @param port Redis port
- */
- public RedisGraph(String host, int port) {
- this( new JedisPool(host, port));
- }
-
- /**
- * Creates a client using provided Jedis pool
- *
- * @param jedis bring your own Jedis pool
- */
- public RedisGraph( Pool jedis) {
-
- this.client = jedis;
- }
-
- @Override
- public void close(){
- this.client.close();
- }
+import java.util.List;
+import java.util.Map;
+public interface RedisGraph extends Closeable {
/**
* Execute a Cypher query with arguments
- *
* @param graphId a graph to perform the query on
* @param query Cypher query
* @param args
* @return a result set
*/
- public ResultSet query(String graphId, String query, Object ...args) {
- if(args.length > 0) {
- for(int i=0; i rawResponse = null;
- try(Jedis conn = getConnection()){
- rawResponse= sendCompactCommand(conn, Command.QUERY, graphId, query).getObjectMultiBulkReply();
- }
- return new ResultSetImpl(rawResponse, graphCaches.get(graphId));
-
- }
+ ResultSet query(String graphId, String query, Object ...args);
/**
* Invokes stored procedures without arguments
@@ -103,10 +21,7 @@ public ResultSet query(String graphId, String query, Object ...args) {
* @param procedure procedure name to invoke
* @return result set with the procedure data
*/
- public ResultSet callProcedure(String graphId, String procedure ){
- return callProcedure(graphId, procedure, new ArrayList<>(), new HashMap<>());
- }
-
+ ResultSet callProcedure(String graphId, String procedure);
/**
* Invokes stored procedure with arguments
@@ -115,58 +30,7 @@ public ResultSet callProcedure(String graphId, String procedure ){
* @param args procedure arguments
* @return result set with the procedure data
*/
- public ResultSet callProcedure(String graphId, String procedure, List args ){
- return callProcedure(graphId, procedure, args, new HashMap<>());
- }
-
-
- /**
- * Deletes the entire graph
- *
- * @return delete running time statistics
- */
- public String deleteGraph(String graphId) {
- //clear local state
- graphCaches.remove(graphId);
- try (Jedis conn = getConnection()) {
- return sendCommand(conn, Command.DELETE, graphId).getBulkReply();
- }
-
- }
-
-
- /**
- * Sends command - will be replaced with sendCompactCommand once graph.delete support --compact flag
- * @param conn - connection
- * @param provider - command type
- * @param args - command arguments
- * @return
- */
- private BinaryClient sendCommand(Jedis conn, ProtocolCommand provider, String ...args) {
- BinaryClient binaryClient = conn.getClient();
- binaryClient.sendCommand(provider, args);
- return binaryClient;
- }
-
-
- /**
- * Sends the command with --COMPACT flag
- * @param conn - connection
- * @param provider - command type
- * @param args - command arguments
- * @return
- */
- private BinaryClient sendCompactCommand(Jedis conn, ProtocolCommand provider, String ...args) {
- String[] t = new String[args.length +1];
- System.arraycopy(args, 0 , t, 0, args.length);
- t[args.length]="--COMPACT";
- return sendCommand(conn, provider, t);
- }
-
- private Jedis getConnection() {
- return this.client.getResource();
- }
-
+ ResultSet callProcedure(String graphId, String procedure, List args);
/**
* Invoke a stored procedure
@@ -174,17 +38,15 @@ private Jedis getConnection() {
* @param procedure - procedure to execute
* @param args - procedure arguments
* @param kwargs - procedure output arguments
- * @return
+ * @return result set with the procedure data
+ */
+ ResultSet callProcedure(String graphId, String procedure, List args , Map> kwargs);
+
+ /**
+ * Deletes the entire graph
+ * @param graphId graph to delete
+ * @return delete running time statistics
*/
- public ResultSet callProcedure(String graphId, String procedure, List args , Map> kwargs ){
+ String deleteGraph(String graphId);
- args = args.stream().map( s -> Utils.quoteString(s)).collect(Collectors.toList());
- StringBuilder queryString = new StringBuilder();
- queryString.append(String.format("CALL %s(%s)", procedure, String.join(",", args)));
- List kwargsList = kwargs.getOrDefault("y", null);
- if(kwargsList != null){
- queryString.append(String.join(",", kwargsList));
- }
- return query(graphId, queryString.toString());
- }
}
diff --git a/src/main/java/com/redislabs/redisgraph/RedisGraphContexted.java b/src/main/java/com/redislabs/redisgraph/RedisGraphContexted.java
new file mode 100644
index 0000000..5ef1037
--- /dev/null
+++ b/src/main/java/com/redislabs/redisgraph/RedisGraphContexted.java
@@ -0,0 +1,32 @@
+package com.redislabs.redisgraph;
+
+import redis.clients.jedis.Jedis;
+
+public interface RedisGraphContexted extends RedisGraph {
+
+
+ /**
+ * Returns implementing class connection context
+ * @return Jedis connection
+ */
+ Jedis getConnectionContext();
+
+ /**
+ * Returns a Redis transactional object, over the connection context, with graph API capabilities
+ * @return Redis transactional object, over the connection context, with graph API capabilities
+ */
+ RedisGraphTransaction multi();
+
+ /**
+ * Perform watch over given Redis keys
+ * @param keys
+ * @return "OK"
+ */
+ String watch(String... keys);
+
+ /**
+ * Removes watch from all keys
+ * @return
+ */
+ String unwatch();
+}
diff --git a/src/main/java/com/redislabs/redisgraph/RedisGraphGeneralContext.java b/src/main/java/com/redislabs/redisgraph/RedisGraphGeneralContext.java
new file mode 100644
index 0000000..cdf218a
--- /dev/null
+++ b/src/main/java/com/redislabs/redisgraph/RedisGraphGeneralContext.java
@@ -0,0 +1,11 @@
+package com.redislabs.redisgraph;
+
+public interface RedisGraphGeneralContext extends RedisGraph {
+
+ /**
+ * Generate a connection bounded api
+ * @return a connection bounded api
+ */
+ RedisGraphContexted getContextedAPI();
+
+}
diff --git a/src/main/java/com/redislabs/redisgraph/RedisGraphTransaction.java b/src/main/java/com/redislabs/redisgraph/RedisGraphTransaction.java
new file mode 100644
index 0000000..c206640
--- /dev/null
+++ b/src/main/java/com/redislabs/redisgraph/RedisGraphTransaction.java
@@ -0,0 +1,91 @@
+package com.redislabs.redisgraph;
+
+import redis.clients.jedis.Response;
+import redis.clients.jedis.commands.BasicRedisPipeline;
+import redis.clients.jedis.commands.BinaryRedisPipeline;
+import redis.clients.jedis.commands.BinaryScriptingCommandsPipeline;
+import redis.clients.jedis.commands.ClusterPipeline;
+import redis.clients.jedis.commands.MultiKeyBinaryRedisPipeline;
+import redis.clients.jedis.commands.MultiKeyCommandsPipeline;
+import redis.clients.jedis.commands.RedisPipeline;
+import redis.clients.jedis.commands.ScriptingCommandsPipeline;
+
+import java.io.Closeable;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * An interface which aligned to Jedis transactional interface
+ */
+public interface RedisGraphTransaction extends
+ MultiKeyBinaryRedisPipeline,
+ MultiKeyCommandsPipeline, ClusterPipeline,
+ BinaryScriptingCommandsPipeline, ScriptingCommandsPipeline,
+ BasicRedisPipeline, BinaryRedisPipeline, RedisPipeline, Closeable {
+ /**
+ * Execute a Cypher query with arguments
+ * @param graphId a graph to perform the query on
+ * @param query Cypher query
+ * @param args
+ * @return a response which builds the result set with the query answer
+ */
+ Response query(String graphId, String query, Object ...args);
+
+ /**
+ * Invokes stored procedures without arguments
+ * @param graphId a graph to perform the query on
+ * @param procedure procedure name to invoke
+ * @return a response which builds result set with the procedure data
+ */
+ Response callProcedure(String graphId, String procedure);
+
+ /**
+ * Invokes stored procedure with arguments
+ * @param graphId a graph to perform the query on
+ * @param procedure procedure name to invoke
+ * @param args procedure arguments
+ * @return a response which builds result set with the procedure data
+ */
+ Response callProcedure(String graphId, String procedure, List args);
+
+ /**
+ * Invoke a stored procedure
+ * @param graphId a graph to perform the query on
+ * @param procedure - procedure to execute
+ * @param args - procedure arguments
+ * @param kwargs - procedure output arguments
+ * @return a response which builds result set with the procedure data
+ */
+ Response callProcedure(String graphId, String procedure, List args , Map> kwargs);
+
+ /**
+ * Deletes the entire graph
+ * @param graphId graph to delete
+ * @return a response which builds the delete running time statistics
+ */
+ Response deleteGraph(String graphId);
+
+
+ /**
+ * executes the transaction
+ * @return a list of the executed transaction commands answers, in case of successful transaction, null otherwise
+ */
+ List