2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.serialization.engines.query;
24 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
25 import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
26 import org.apache.tinkerpop.gremlin.structure.Direction;
27 import org.apache.tinkerpop.gremlin.structure.Edge;
28 import org.apache.tinkerpop.gremlin.structure.Element;
29 import org.apache.tinkerpop.gremlin.structure.Vertex;
30 import org.onap.aai.db.props.AAIProperties;
31 import org.onap.aai.introspection.Loader;
33 import java.util.List;
35 public abstract class QueryEngine {
37 final protected GraphTraversalSource g;
38 protected double dbTimeMsecs = 0;
40 * Instantiates a new query engine.
42 * @param graphEngine the graph engine
44 public QueryEngine (GraphTraversalSource g) {
49 * Finds all the parents/grandparents/etc of the given start node.
51 * @param start - the start vertex whose parent chain you want
52 * @return the list of start and start's parent, grandparent, etc, in
53 * order (ie {start, parent, grandparent, etc}
55 public abstract List<Vertex> findParents(Vertex start);
58 * Finds all children, grandchildren, etc of start
60 * @param start the start vertex
61 * @return the list of child/grandchild/etc vertices
63 public abstract List<Vertex> findAllChildren(Vertex start);
66 * Finds all immediate children of start (no grandchildren or so forth) of the given type
67 * @param start - the start vertex
68 * @param type - the desired aai-node-type
69 * @return the list of immediate child vertices of given type
71 public abstract List<Vertex> findChildrenOfType(Vertex start, String type);
74 * Finds all immediate children of start (no grandchildren or so forth)
75 * @param start - the start vertex
76 * @return the list of immediate child vertices
78 public abstract List<Vertex> findChildren(Vertex start);
81 * Find all vertices that should be deleted in a cascade from a delete of start
83 * @param start - the start vertex
84 * @return the list of vertices to be deleted when start is deleted
86 public abstract List<Vertex> findDeletable(Vertex start);
89 * Finds the subgraph under start, including cousins as well as start's children/grandchildren/etc.
90 * More specifically, this includes start, all its descendants, start's cousins, and start's
91 * descendants' cousins (but not any of the cousins' cousins or descendants), and the edges
94 * @param start - the start vertex
95 * @return - Tree containing nodes and edges of the subgraph
97 public Tree<Element> findSubGraph(Vertex start) {
98 return findSubGraph(start, AAIProperties.MAXIMUM_DEPTH, false);
102 * Finds the subgraph under start, including cousins as well as start's children/grandchildren/etc.
103 * More specifically, this includes start, all its descendants, start's cousins, and start's
104 * descendants' cousins (but not any of the cousins' cousins or descendants), and the edges
107 * @param start - the start vertex
108 * @param iterations - depth of the subgraph, this limits how many generations of
109 * descendants are included
110 * @param nodeOnly - if true the subgraph will NOT include the cousins
111 * @return Tree containing nodes and edges of the subgraph
113 public abstract Tree<Element> findSubGraph(Vertex start, int iterations, boolean nodeOnly);
116 * Find vertices of type nodeType related to start by edges of the given
117 * direction and label.
119 * @param start - the start vertex
120 * @param direction - the direction of edges to traverse from start
121 * @param label - the label of edges to traverse from start
122 * @param nodeType - the node type the results should be
123 * @return the list of related vertices
125 public abstract List<Vertex> findRelatedVertices(Vertex start, Direction direction, String label, String nodeType);
128 * Finds cousin edges connecting start to other vertices only of types defined in an old version.
129 * The idea is that if a user is using an old version, they won't understand any new node types in
130 * subsequent versions. Thus, revealing edges to new types will cause problems. This methods
131 * filters any such edges out.
133 * @param start - the start vertex
134 * @param loader - loader for retrieving the list of allowed node types for the desired version
135 * (version is set when the loader was instantiated)
136 * @return list of cousin edges between start and any node types understood by the version specified in loader
138 public abstract List<Edge> findEdgesForVersion(Vertex start, Loader loader);
141 * Finds all cousins of start.
143 * @param start - the start vertex
144 * @return list of start's cousin vertices
146 public abstract List<Vertex> findCousinVertices(Vertex start);
148 public abstract double getDBTimeMsecs();