Skip to content

Commit a02c515

Browse files
committed
delete graph
1 parent 40c2d41 commit a02c515

File tree

7 files changed

+76
-12
lines changed

7 files changed

+76
-12
lines changed

.idea/libraries/Maven__redis_clients_jedis_3_0_0.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/commons-pool2-2.4.2.jar

-109 KB
Binary file not shown.

lib/jedis-3.0.0.jar

-544 KB
Binary file not shown.

pom.xml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@
2020
<artifactId>commons-pool2</artifactId>
2121
<version>2.0</version>
2222
</dependency>
23-
2423
<dependency>
2524
<groupId>redis.clients</groupId>
2625
<artifactId>jedis</artifactId>
27-
<version>2.9.0</version>
28-
<type>jar</type>
29-
<scope>system</scope>
30-
<systemPath>${project.basedir}/lib/jedis-3.0.0.jar</systemPath>
26+
<version>3.0.0</version>
3127
</dependency>
28+
29+
<!--<dependency>-->
30+
<!--<groupId>redis.clients</groupId>-->
31+
<!--<artifactId>jedis</artifactId>-->
32+
<!--<version>3.0.0</version>-->
33+
<!--<type>jar</type>-->
34+
<!--<scope>system</scope>-->
35+
<!--<systemPath>${project.basedir}/lib/jedis-3.0.0.jar</systemPath>-->
36+
<!--</dependency>-->
3237
</dependencies>
33-
</project>
38+
</project>

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public String createNode(String graph, Object... attributes) {
5959
return nodeId;
6060
}
6161

62-
6362
public String connectNodes(String graph, String srcNodeID, String relation, String destNodeID, Object... attributes) {
6463
Jedis conn = _conn();
6564

@@ -70,7 +69,7 @@ public String connectNodes(String graph, String srcNodeID, String relation, Stri
7069
args.add(destNodeID);
7170

7271
for(Object attr: attributes) {
73-
args.add(attr);
72+
args.add(attr.toString());
7473
}
7574

7675
String[] stringArgs = args.toArray(new String[args.size()]);
@@ -90,10 +89,14 @@ public HashMap<String, String> getNode(String graphId, String id) {
9089
args.add(id);
9190

9291
String[] stringArgs = args.toArray(new String[args.size()]);
93-
94-
List<String> properties = conn.getClient()
92+
List<String> properties;
93+
try {
94+
properties = conn.getClient()
9595
.sendCommand(Commands.Command.GETNODE, stringArgs)
9696
.getMultiBulkReply();
97+
} catch(ClassCastException e) {
98+
return null;
99+
}
97100

98101
HashMap<String, String> attributes = new HashMap<String, String>(properties.size()/2);
99102

@@ -115,10 +118,15 @@ public HashMap<String, String> getEdge(String graphId, String id) {
115118
args.add(id);
116119

117120
String[] stringArgs = args.toArray(new String[args.size()]);
121+
List<String> properties;
118122

119-
List<String> properties = conn.getClient()
123+
try {
124+
properties = conn.getClient()
120125
.sendCommand(Commands.Command.GETEDGE, stringArgs)
121126
.getMultiBulkReply();
127+
} catch (ClassCastException e) {
128+
return null;
129+
}
122130

123131
HashMap<String, String> attributes = new HashMap<String, String>(properties.size()/2);
124132

@@ -166,7 +174,6 @@ public List<String> getNeighbours(String graphId, String nodeId, String edgeType
166174
return neighbours;
167175
}
168176

169-
170177
public ResultSet query(String graphId, String query) {
171178
Jedis conn = _conn();
172179

@@ -181,4 +188,11 @@ public boolean setProperty(String elementId, String key, Object value) {
181188
Jedis conn = _conn();
182189
return conn.hset(elementId, key, value.toString()) == 1;
183190
}
191+
192+
public void deleteGraph(String graph) {
193+
Jedis conn = _conn();
194+
conn.getClient()
195+
.sendCommand(Commands.Command.DELETEGRAPH, graph)
196+
.getStatusCodeReply();
197+
}
184198
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public RedisNode createLabeledNode(String label, Object... attributes) {
4545

4646
public RedisNode getNode(String id) {
4747
HashMap<String, String> attributes = client.getNode(this.graphId, id);
48+
49+
if(attributes == null) {
50+
return null;
51+
}
52+
4853
String label = attributes.get("label");
4954
attributes.remove("label");
5055

@@ -53,6 +58,11 @@ public RedisNode getNode(String id) {
5358

5459
public RedisEdge getEdge(String id) {
5560
HashMap<String, String> attributes = client.getEdge(this.graphId, id);
61+
62+
if(attributes == null) {
63+
return null;
64+
}
65+
5666
String edgeId = attributes.get("id");
5767
String relation = attributes.get("type");
5868
String srcNodeId = attributes.get("src");
@@ -111,4 +121,8 @@ public ResultSet query(String query) {
111121
public boolean setProperty(String elementId, String key, Object value) {
112122
return client.setProperty(elementId, key, value);
113123
}
124+
125+
public void deleteGraph() {
126+
client.deleteGraph(this.graphId);
127+
}
114128
}

src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,22 @@ public void testGetNeighbours() throws Exception {
211211
neighbours = api.getNeighbours(amit.getId(), "knows", DIR_BOTH);
212212
Assert.assertEquals(neighbours.size(), 2);
213213
}
214+
215+
@org.testng.annotations.Test
216+
public void testGraphDelete() throws Exception {
217+
RedisGraphAPI api = new RedisGraphAPI("social");
218+
RedisNode roi = api.createNode("name", "roi", "age", 32);
219+
RedisNode amit = api.createNode("name", "amit", "age", 30);
220+
221+
// Connect source and destination nodes.
222+
RedisEdge edge = api.connectNodes(roi, "knows", amit);
223+
224+
api.deleteGraph();
225+
226+
roi = api.getNode(roi.getId());
227+
Assert.assertNull(roi);
228+
229+
edge = api.getEdge(edge.getId());
230+
Assert.assertNull(edge);
231+
}
214232
}

0 commit comments

Comments
 (0)