@@ -77,67 +77,96 @@ public String connectNodes(String graph, String srcNodeID, String relation, Stri
7777 String edgeId = conn .getClient ()
7878 .sendCommand (Commands .Command .ADDEDGE , stringArgs )
7979 .getBulkReply ();
80+
8081 conn .close ();
8182 return edgeId ;
8283 }
8384
84- public HashMap <String , String > getNode (String graphId , String id ) {
85+ public List < HashMap <String , String >> getNodes (String graphId , Object ... ids ) {
8586 Jedis conn = _conn ();
8687
8788 List <String > args = new ArrayList <String >(2 );
8889 args .add (graphId );
89- args .add (id );
90+ for (Object id : ids ) {
91+ args .add (id .toString ());
92+ }
9093
9194 String [] stringArgs = args .toArray (new String [args .size ()]);
92- List <String > properties ;
95+ List <String > replay ;
9396 try {
94- properties = conn .getClient ()
95- .sendCommand (Commands .Command .GETNODE , stringArgs )
96- .getMultiBulkReply ();
97+ replay = conn .getClient ()
98+ .sendCommand (Commands .Command .GETNODES , stringArgs )
99+ .getMultiBulkReply ();
97100 } catch (ClassCastException e ) {
98101 return null ;
99102 }
100103
101- HashMap <String , String > attributes = new HashMap <String , String >(properties .size ()/2 );
104+ List <HashMap <String , String >> nodes = new ArrayList <HashMap <String , String >>();
105+
106+ int numberOfNodes = Integer .parseInt (replay .get (replay .size ()-1 ));
107+ int offset = 0 ;
102108
103- for (int i = 0 ; i < properties .size (); i +=2 ) {
104- String key = properties .get (i ) ;
105- String value = properties .get (i +1 );
106- attributes .put (key , value );
109+ for (int i = 0 ; i < numberOfNodes ; i ++) {
110+ int numberOfProperties = Integer .parseInt (replay .get (offset ));
111+ offset ++;
112+
113+ HashMap <String , String > nodeAttributes = new HashMap <String , String >(numberOfProperties /2 );
114+ nodes .add (nodeAttributes );
115+ for (int j = 0 ; j < numberOfProperties ; j +=2 ) {
116+ String key = replay .get (offset + j );
117+ String value = replay .get (offset + j + 1 );
118+ nodeAttributes .put (key , value );
119+ }
120+
121+ offset += numberOfProperties ;
107122 }
108123
109124 conn .close ();
110- return attributes ;
125+ return nodes ;
111126 }
112127
113- public HashMap <String , String > getEdge (String graphId , String id ) {
128+ public List < HashMap <String , String >> getEdges (String graphId , Object ... ids ) {
114129 Jedis conn = _conn ();
115130
116131 List <String > args = new ArrayList <String >(2 );
117132 args .add (graphId );
118- args .add (id );
133+ for (Object id : ids ) {
134+ args .add (id .toString ());
135+ }
119136
120137 String [] stringArgs = args .toArray (new String [args .size ()]);
121- List <String > properties ;
138+ List <String > replay ;
122139
123140 try {
124- properties = conn .getClient ()
125- .sendCommand (Commands .Command .GETEDGE , stringArgs )
126- .getMultiBulkReply ();
141+ replay = conn .getClient ()
142+ .sendCommand (Commands .Command .GETEDGES , stringArgs )
143+ .getMultiBulkReply ();
127144 } catch (ClassCastException e ) {
128145 return null ;
129146 }
130147
131- HashMap <String , String > attributes = new HashMap <String , String >( properties . size ()/ 2 );
148+ List < HashMap <String , String >> edges = new ArrayList < HashMap <String , String >>( );
132149
133- for (int i = 0 ; i < properties .size (); i +=2 ) {
134- String key = properties .get (i ) ;
135- String value = properties .get (i +1 );
136- attributes .put (key , value );
150+ int numberOfEdges = Integer .parseInt (replay .get (replay .size ()-1 ));
151+ int offset = 0 ;
152+
153+ for (int i = 0 ; i < numberOfEdges ; i ++) {
154+ int numberOfProperties = Integer .parseInt (replay .get (offset ));
155+ offset ++;
156+
157+ HashMap <String , String > edgeAttributes = new HashMap <String , String >(numberOfProperties /2 );
158+ edges .add (edgeAttributes );
159+ for (int j = 0 ; j < numberOfProperties ; j +=2 ) {
160+ String key = replay .get (offset + j );
161+ String value = replay .get (offset + j + 1 );
162+ edgeAttributes .put (key , value );
163+ }
164+
165+ offset += numberOfProperties ;
137166 }
138167
139168 conn .close ();
140- return attributes ;
169+ return edges ;
141170 }
142171
143172 public List <String > getNodeEdges (String graphId , String nodeId , String edgeType , int direction ) {
@@ -154,6 +183,7 @@ public List<String> getNodeEdges(String graphId, String nodeId, String edgeType,
154183 .sendCommand (Commands .Command .GETNODEEDGES , stringArgs )
155184 .getMultiBulkReply ();
156185
186+ conn .close ();
157187 return edges ;
158188 }
159189
@@ -171,6 +201,7 @@ public List<String> getNeighbours(String graphId, String nodeId, String edgeType
171201 .sendCommand (Commands .Command .GETNEIGHBOURS , stringArgs )
172202 .getMultiBulkReply ();
173203
204+ conn .close ();
174205 return neighbours ;
175206 }
176207
@@ -181,6 +212,7 @@ public ResultSet query(String graphId, String query) {
181212 .sendCommand (Commands .Command .QUERY , graphId , query )
182213 .getObjectMultiBulkReply ();
183214
215+ conn .close ();
184216 return new ResultSet (resp );
185217 }
186218
@@ -194,5 +226,6 @@ public void deleteGraph(String graph) {
194226 conn .getClient ()
195227 .sendCommand (Commands .Command .DELETEGRAPH , graph )
196228 .getStatusCodeReply ();
229+ conn .close ();
197230 }
198231}
0 commit comments