-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathAbstractRedisGraph.java
More file actions
117 lines (102 loc) · 3.91 KB
/
AbstractRedisGraph.java
File metadata and controls
117 lines (102 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.redislabs.redisgraph.impl.api;
import com.redislabs.redisgraph.RedisGraph;
import com.redislabs.redisgraph.ResultSet;
import com.redislabs.redisgraph.impl.Utils;
import redis.clients.jedis.Jedis;
import java.util.List;
import java.util.Map;
/**
* An abstract class to handle non implementation specific user requests
*/
public abstract class AbstractRedisGraph implements RedisGraph {
/**
* Inherited classes should return a Jedis connection, with respect to their context
* @return Jedis connection
*/
protected abstract Jedis getConnection();
/**
* Sends a 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 sendQuery(String graphId, String preparedQuery);
/**
* Sends a 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 sendQuery(String graphId, String preparedQuery, long timeout);
/**
* Execute a Cypher query.
* @param graphId a graph to perform the query on
* @param query Cypher query
* @return a result set
*/
public ResultSet query(String graphId, String query) {
return sendQuery(graphId, query);
}
/**
* Execute a Cypher 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 query(String graphId, String query, long timeout) {
return sendQuery(graphId, query, timeout);
}
/**
* 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
* @deprecated use {@link #query(String, String, Map)} instead.
*/
@Deprecated
public ResultSet query(String graphId, String query, Object ...args) {
String preparedQuery = Utils.prepareQuery(query, args);
return sendQuery(graphId, preparedQuery);
}
/**
* Executes a cypher 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 query(String graphId, String query, Map<String, Object> params) {
String preparedQuery = Utils.prepareQuery(query, params);
return sendQuery(graphId, preparedQuery);
}
/**
* Executes a cypher 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 query(String graphId, String query, Map<String, Object> params, long timeout) {
String preparedQuery = Utils.prepareQuery(query, params);
return sendQuery(graphId, preparedQuery, timeout);
}
public ResultSet callProcedure(String graphId, String procedure){
return callProcedure(graphId, procedure, Utils.DUMMY_LIST, Utils.DUMMY_MAP);
}
public ResultSet callProcedure(String graphId, String procedure, List<String> args){
return callProcedure(graphId, procedure, args, Utils.DUMMY_MAP);
}
public ResultSet callProcedure(String graphId, String procedure, List<String> args , Map<String, List<String>> kwargs){
long startTime = System.nanoTime();
String preparedProcedure = Utils.prepareProcedure(procedure, args, kwargs);
long stopTime = System.nanoTime();
System.out.println("Prepare procedure " + procedure + " " + (stopTime - startTime)/1000000);
return query(graphId, preparedProcedure);
}
}