2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.serialization.engines.query;
22 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
23 import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
24 import org.apache.tinkerpop.gremlin.structure.Direction;
25 import org.apache.tinkerpop.gremlin.structure.Edge;
26 import org.apache.tinkerpop.gremlin.structure.Element;
27 import org.apache.tinkerpop.gremlin.structure.Vertex;
28 import org.onap.aai.db.props.AAIProperties;
29 import org.onap.aai.introspection.Loader;
31 import java.util.List;
33 public abstract class QueryEngine {
35 final protected GraphTraversalSource g;
36 protected double dbTimeMsecs = 0;
38 * Instantiates a new query engine.
40 * @param graphEngine the graph engine
42 public QueryEngine (GraphTraversalSource g) {
47 * Finds all the parents/grandparents/etc of the given start node.
49 * @param start - the start vertex whose parent chain you want
50 * @return the list of start and start's parent, grandparent, etc, in
51 * order (ie {start, parent, grandparent, etc}
53 public abstract List<Vertex> findParents(Vertex start);
56 * Finds all children, grandchildren, etc of start
58 * @param start the start vertex
59 * @return the list of child/grandchild/etc vertices
61 public abstract List<Vertex> findAllChildren(Vertex start);
64 * Finds all immediate children of start (no grandchildren or so forth) of the given type
65 * @param start - the start vertex
66 * @param type - the desired aai-node-type
67 * @return the list of immediate child vertices of given type
69 public abstract List<Vertex> findChildrenOfType(Vertex start, String type);
72 * Finds all immediate children of start (no grandchildren or so forth)
73 * @param start - the start vertex
74 * @return the list of immediate child vertices
76 public abstract List<Vertex> findChildren(Vertex start);
79 * Find all vertices that should be deleted in a cascade from a delete of start
81 * @param start - the start vertex
82 * @return the list of vertices to be deleted when start is deleted
84 public abstract List<Vertex> findDeletable(Vertex start);
87 * Finds the subgraph under start, including cousins as well as start's children/grandchildren/etc.
88 * More specifically, this includes start, all its descendants, start's cousins, and start's
89 * descendants' cousins (but not any of the cousins' cousins or descendants), and the edges
92 * @param start - the start vertex
93 * @return - Tree containing nodes and edges of the subgraph
95 public Tree<Element> findSubGraph(Vertex start) {
96 return findSubGraph(start, AAIProperties.MAXIMUM_DEPTH, false);
100 * Finds the subgraph under start, including cousins as well as start's children/grandchildren/etc.
101 * More specifically, this includes start, all its descendants, start's cousins, and start's
102 * descendants' cousins (but not any of the cousins' cousins or descendants), and the edges
105 * @param start - the start vertex
106 * @param iterations - depth of the subgraph, this limits how many generations of
107 * descendants are included
108 * @param nodeOnly - if true the subgraph will NOT include the cousins
109 * @return Tree containing nodes and edges of the subgraph
111 public abstract Tree<Element> findSubGraph(Vertex start, int iterations, boolean nodeOnly);
114 * Find vertices of type nodeType related to start by edges of the given
115 * direction and label.
117 * @param start - the start vertex
118 * @param direction - the direction of edges to traverse from start
119 * @param label - the label of edges to traverse from start
120 * @param nodeType - the node type the results should be
121 * @return the list of related vertices
123 public abstract List<Vertex> findRelatedVertices(Vertex start, Direction direction, String label, String nodeType);
126 * Finds cousin edges connecting start to other vertices only of types defined in an old version.
127 * The idea is that if a user is using an old version, they won't understand any new node types in
128 * subsequent versions. Thus, revealing edges to new types will cause problems. This methods
129 * filters any such edges out.
131 * @param start - the start vertex
132 * @param loader - loader for retrieving the list of allowed node types for the desired version
133 * (version is set when the loader was instantiated)
134 * @return list of cousin edges between start and any node types understood by the version specified in loader
136 public abstract List<Edge> findEdgesForVersion(Vertex start, Loader loader);
139 * Finds all cousins of start.
141 * @param start - the start vertex
142 * @return list of start's cousin vertices
144 public abstract List<Vertex> findCousinVertices(Vertex start);
146 public abstract double getDBTimeMsecs();