-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathAbstractRedisGraph.java
179 lines (158 loc) · 5.97 KB
/
AbstractRedisGraph.java
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package com.redislabs.redisgraph.impl.api;
import com.redislabs.redisgraph.Connection;
import com.redislabs.redisgraph.RedisGraph;
import com.redislabs.redisgraph.ResultSet;
import com.redislabs.redisgraph.impl.Utils;
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 connection
*/
protected abstract Connection 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 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
* @param preparedQuery prepared query
* @param timeout
* @return Result set
*/
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
* @param query Cypher query
* @return a result set
*/
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
* @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 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
* @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 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<String, Object> 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.
* @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);
}
/**
* 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<String, Object> 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);
}
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){
String preparedProcedure = Utils.prepareProcedure(procedure, args, kwargs);
return query(graphId, preparedProcedure);
}
}