@@ -35,10 +35,10 @@ public static String createEdgeQuery(
3535 if (vertexExample != null && String .class .isAssignableFrom (vertexExample .getClass ())) {
3636 sb .append ("FOR v,e IN " );
3737 appendDepth (graphEdgesOptions , sb );
38- appendDirection (graphEdgesOptions , sb );
38+ appendDirection (graphEdgesOptions . getDirection () , sb );
3939 sb .append (" @" );
4040 sb .append (VERTEX_EXAMPLE );
41- bindVars .put (VERTEX_EXAMPLE , JsonUtils . convertNullToMap ( vertexExample ) );
41+ bindVars .put (VERTEX_EXAMPLE , vertexExample );
4242 } else {
4343 final List <String > startVertexCollectionRestriction = graphEdgesOptions
4444 .getStartVertexCollectionRestriction ();
@@ -65,7 +65,7 @@ public static String createEdgeQuery(
6565 }
6666 sb .append (" FOR v,e IN " );
6767 appendDepth (graphEdgesOptions , sb );
68- appendDirection (graphEdgesOptions , sb );
68+ appendDirection (graphEdgesOptions . getDirection () , sb );
6969 sb .append (" start" );
7070 }
7171 sb .append (" " );
@@ -78,9 +78,7 @@ public static String createEdgeQuery(
7878 // remove last ,
7979 sb .deleteCharAt (sb .length () - 1 );
8080 } else {
81- sb .append ("GRAPH @" );
82- sb .append (GRAPH_NAME );
83- bindVars .put (GRAPH_NAME , graphName );
81+ appendGraphName (graphName , bindVars , sb );
8482 }
8583 appendFilter ("e" , graphEdgesOptions .getEdgeExamples (), sb );
8684 appendFilter ("v" , graphEdgesOptions .getNeighborExamples (), sb );
@@ -98,6 +96,17 @@ public static String createEdgeQuery(
9896 return query ;
9997 }
10098
99+ /**
100+ * @param graphName
101+ * @param bindVars
102+ * @param sb
103+ */
104+ private static void appendGraphName (final String graphName , final MapBuilder bindVars , final StringBuilder sb ) {
105+ sb .append ("GRAPH @" );
106+ sb .append (GRAPH_NAME );
107+ bindVars .put (GRAPH_NAME , graphName );
108+ }
109+
101110 private static void appendDepth (final GraphEdgesOptions graphEdgesOptions , final StringBuilder sb ) {
102111 final Integer minDepth = graphEdgesOptions .getMinDepth ();
103112 final Integer maxDepth = graphEdgesOptions .getMaxDepth ();
@@ -109,10 +118,9 @@ private static void appendDepth(final GraphEdgesOptions graphEdgesOptions, final
109118 }
110119 }
111120
112- private static void appendDirection (final GraphEdgesOptions graphEdgesOptions , final StringBuilder sb ) {
113- final String direction = graphEdgesOptions .getDirection () != null ? graphEdgesOptions .getDirection ().name ()
114- : Direction .ANY .name ();
115- sb .append (direction );
121+ private static void appendDirection (final Direction direction , final StringBuilder sb ) {
122+ final String directionName = direction != null ? direction .name () : Direction .ANY .name ();
123+ sb .append (directionName );
116124 }
117125
118126 private static void appendFilter (final String var , final Object example , final StringBuilder sb )
@@ -167,7 +175,53 @@ public static String createVerticesQuery(
167175 final Object vertexExample ,
168176 final GraphVerticesOptions graphVerticesOptions ,
169177 final MapBuilder bindVars ) throws ArangoException {
170- return null ;
178+
179+ // final String query = "for i in graph_vertices(@graphName ,
180+ // @vertexExample, @options) return i";
181+ // final Map<String, Object> bindVars = new MapBuilder().put(GRAPH_NAME,
182+ // graphName)
183+ // .put(VERTEX_EXAMPLE, JsonUtils.convertNullToMap(vertexExample))
184+ // .put("options",
185+ // JsonUtils.convertNullToMap(graphVerticesOptions)).get();
186+
187+ StringBuilder sb = new StringBuilder ();
188+ final boolean stringVertexExample = vertexExample != null
189+ && String .class .isAssignableFrom (vertexExample .getClass ());
190+ if (stringVertexExample ) {
191+ sb .append ("RETURN " );
192+ sb .append ("DOCUMENT(" );
193+ sb .append ("@" );
194+ sb .append (VERTEX_EXAMPLE );
195+ bindVars .put (VERTEX_EXAMPLE , vertexExample );
196+ sb .append (")" );
197+ } else {
198+ final List <String > startVertexCollectionRestriction = graphVerticesOptions .getVertexCollectionRestriction ();
199+ final List <String > vertexCollections = startVertexCollectionRestriction != null
200+ && startVertexCollectionRestriction .size () > 0 ? startVertexCollectionRestriction
201+ : driver .graphGetVertexCollections (graphName , true );
202+ if (vertexCollections .size () == 1 ) {
203+ sb .append ("FOR start IN `" );
204+ sb .append (vertexCollections .get (0 ));
205+ sb .append ("`" );
206+ appendFilter ("start" , vertexExample , sb );
207+ } else {
208+ sb .append ("FOR start IN UNION (" );
209+ for (String vertexCollection : vertexCollections ) {
210+ sb .append ("(FOR start IN `" );
211+ sb .append (vertexCollection );
212+ sb .append ("`" );
213+ appendFilter ("start" , vertexExample , sb );
214+ sb .append (" RETURN start)," );
215+ }
216+ // remove last ,
217+ sb .deleteCharAt (sb .length () - 1 );
218+ sb .append (")" );
219+ }
220+ sb .append (" RETURN start" );
221+ }
222+
223+ String query = sb .toString ();
224+ return query ;
171225 }
172226
173227 public static String createShortestPathQuery (
0 commit comments