Skip to content

Commit e1e9bfd

Browse files
author
DvirDukhan
committed
result set impl is now holding a local ref to redis graph api
1 parent 40be547 commit e1e9bfd

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

src/main/java/com/redislabs/redisgraph/RedisGraphAPI.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ public class RedisGraphAPI {
2727
private final List<String> relationshipTypes = new ArrayList<>();
2828
private final List<String> propertyNames = new ArrayList<>();
2929

30-
private static final Map<String, RedisGraphAPI> apiMap = new ConcurrentHashMap<>();
31-
32-
33-
34-
35-
3630
private static final CharSequenceTranslator ESCAPE_CHYPER;
3731
static {
3832
final Map<CharSequence, CharSequence> escapeJavaMap = new HashMap<>();
@@ -70,9 +64,6 @@ public RedisGraphAPI(String graphId, String host, int port) {
7064
public RedisGraphAPI(String graphId, Pool<Jedis> jedis) {
7165
this.graphId = graphId;
7266
this.client = jedis;
73-
apiMap.put(graphId, this);
74-
75-
7667
}
7768

7869
/**
@@ -93,7 +84,7 @@ public ResultSet query(String query, Object ...args) {
9384
}
9485

9586
try (Jedis conn = getConnection()) {
96-
return new ResultSetImpl(sendCompactCommand(conn, Command.QUERY, graphId, query).getObjectMultiBulkReply(), graphId);
87+
return new ResultSetImpl(sendCompactCommand(conn, Command.QUERY, graphId, query).getObjectMultiBulkReply(), this);
9788
}
9889
}
9990

@@ -104,6 +95,10 @@ public ResultSet query(String query, Object ...args) {
10495
* @return delete running time statistics
10596
*/
10697
public String deleteGraph() {
98+
//clear local state
99+
labels.clear();
100+
propertyNames.clear();
101+
relationshipTypes.clear();
107102
try (Jedis conn = getConnection()) {
108103
return sendCommand(conn, Command.DELETE, graphId).getBulkReply();
109104
}
@@ -166,7 +161,6 @@ public ResultSet callProcedure(String procedure ){
166161
public ResultSet callProcedure(String procedure, List<String> args ){
167162
return callProcedure(procedure, args, new HashMap<>());
168163

169-
170164
}
171165

172166

@@ -250,9 +244,7 @@ private void getProcedureInfo(List<String> list, String procedure){
250244
while (resultSet.hasNext()){
251245
Record record = resultSet.next();
252246
list.add(record.getString(0));
253-
254247
}
255-
256248
}
257249

258250

@@ -273,15 +265,6 @@ public ResultSet callProcedure(String procedure, List<String> args , Map<String
273265
q.append(String.join(",", y));
274266
}
275267
return query(q.toString());
276-
277-
278268
}
279269

280-
/**
281-
* static function to access an initialized graph api
282-
* @return an initialized instance of RedisGraphAPI
283-
*/
284-
public static RedisGraphAPI getInstance(String graphId){
285-
return apiMap.get(graphId);
286-
}
287270
}

src/main/java/com/redislabs/redisgraph/impl/ResultSetImpl.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ public class ResultSetImpl implements ResultSet {
1717
private final List<Record> results = new ArrayList<>();
1818

1919
private int position = 0;
20-
private final String graphId;
20+
private final RedisGraphAPI redisGraphAPI;
2121

2222
/**
2323
*
2424
* @param rawResponse the raw representation of response is at most 3 lists of objects.
2525
* The last list is the statistics list.
26-
* @param graphId, the graph ID
26+
* @param redisGraphAPI, the graph api
2727
*/
28-
public ResultSetImpl(List<Object> rawResponse, String graphId){
29-
this.graphId = graphId;
28+
public ResultSetImpl(List<Object> rawResponse, RedisGraphAPI redisGraphAPI){
29+
this.redisGraphAPI = redisGraphAPI;
3030
if(rawResponse.size() != 3){
3131

3232
parseStatistics(rawResponse.get(rawResponse.size()-1));
@@ -78,7 +78,6 @@ private void parseResult(List<List<Object>> rawResultSet) {
7878
Record record = new RecordImpl(header.getSchemaNames(), parsedRow);
7979
results.add(record);
8080

81-
8281
}
8382

8483
}
@@ -125,7 +124,7 @@ private Node deserializeNode(List<Object> rawNodeData) {
125124
deserializeGraphEntityId(node, rawNodeData.get(0));
126125
List<Long> labelsIndices = (List<Long>) rawNodeData.get(1);
127126
for (long labelIndex : labelsIndices) {
128-
String label = RedisGraphAPI.getInstance(graphId).getLabel((int) labelIndex);
127+
String label = redisGraphAPI.getLabel((int) labelIndex);
129128
node.addLabel(label);
130129
}
131130
deserializeGraphEntityProperties(node, (List<List<Object>>) rawNodeData.get(2));
@@ -157,7 +156,7 @@ private Edge deserializeEdge(List<Object> rawEdgeData) {
157156
Edge edge = new Edge();
158157
deserializeGraphEntityId(edge, rawEdgeData.get(0));
159158

160-
String relationshipType = RedisGraphAPI.getInstance(graphId).getRelationshipType(((Long) rawEdgeData.get(1)).intValue());
159+
String relationshipType = redisGraphAPI.getRelationshipType(((Long) rawEdgeData.get(1)).intValue());
161160
edge.setRelationshipType(relationshipType);
162161

163162
edge.setSource((int) (long) rawEdgeData.get(2));
@@ -181,7 +180,7 @@ void deserializeGraphEntityProperties(GraphEntity entity, List<List<Object>> raw
181180

182181
for (List<Object> rawProperty : rawProperties) {
183182
Property property = new Property();
184-
property.setName(RedisGraphAPI.getInstance(graphId).getPropertyName( ((Long) rawProperty.get(0)).intValue()));
183+
property.setName(redisGraphAPI.getPropertyName( ((Long) rawProperty.get(0)).intValue()));
185184

186185
//trimmed for getting to value using deserializeScalar
187186
List<Object> propertyScalar = rawProperty.subList(1, rawProperty.size());

0 commit comments

Comments
 (0)