3434import static org .apache .tinkerpop .gremlin .process .traversal .Order .decr ;
3535import static org .apache .tinkerpop .gremlin .process .traversal .Order .incr ;
3636
37- class SelectQueryConverter implements Function <GraphQueryMethod , List <Vertex >> {
37+ class SelectQueryConverter extends AbstractQueryConvert implements Function <GraphQueryMethod , List <Vertex >> {
3838
3939
4040 @ Override
@@ -60,6 +60,7 @@ public List<Vertex> apply(GraphQueryMethod graphQuery) {
6060 return traversal .next ((int ) query .getLimit ());
6161 }
6262 query .getOrderBy ().forEach (getSort (traversal , representation ));
63+ traversal .hasLabel (representation .getName ());
6364 return traversal .toList ();
6465 }
6566
@@ -73,41 +74,4 @@ private Consumer<Sort> getSort(GraphTraversal<Vertex, Vertex> traversal, ClassRe
7374 };
7475 }
7576
76- private GraphTraversal <Vertex , Vertex > getPredicate (GraphQueryMethod graphQuery , Condition condition ,
77- ClassRepresentation representation ) {
78- Operator operator = condition .getOperator ();
79- String name = condition .getName ();
80- String nativeName = representation .getColumnField (name );
81- switch (operator ) {
82- case EQUALS :
83- return __ .has (nativeName , P .eq (graphQuery .getValue (name )));
84- case GREATER_THAN :
85- return __ .has (nativeName , P .gt (graphQuery .getValue (name )));
86- case GREATER_EQUALS_THAN :
87- return __ .has (nativeName , P .gte (graphQuery .getValue (name )));
88- case LESSER_THAN :
89- return __ .has (nativeName , P .lt (graphQuery .getValue (name )));
90- case LESSER_EQUALS_THAN :
91- return __ .has (nativeName , P .lte (graphQuery .getValue (name )));
92- case BETWEEN :
93- return __ .has (nativeName , P .between (graphQuery .getValue (name ), graphQuery .getValue (name )));
94- case IN :
95- return __ .has (nativeName , P .within (graphQuery .getInValue (name )));
96- case NOT :
97- Condition notCondition = ConditionValue .class .cast (condition .getValue ()).get ().get (0 );
98- return __ .not (getPredicate (graphQuery , notCondition , representation ));
99- case AND :
100- return ConditionValue .class .cast (condition .getValue ()).get ().stream ()
101- .map (c -> getPredicate (graphQuery , c , representation )).reduce ((a , b ) -> a .and (b ))
102- .orElseThrow (() -> new UnsupportedOperationException ("There is an inconsistency at the AND operator" ));
103- case OR :
104- return ConditionValue .class .cast (condition .getValue ()).get ().stream ()
105- .map (c -> getPredicate (graphQuery , c , representation )).reduce ((a , b ) -> a .or (b ))
106- .orElseThrow (() -> new UnsupportedOperationException ("There is an inconsistency at the OR operator" ));
107- default :
108- throw new UnsupportedOperationException ("There is not support to the type " + operator + " in graph" );
109-
110-
111- }
112- }
11377}
0 commit comments