1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
/**
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.onap.aai.serialization.engines.query;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.introspection.Loader;
import java.util.List;
public abstract class QueryEngine {
final protected GraphTraversalSource g;
protected double dbTimeMsecs = 0;
/**
* Instantiates a new query engine.
*
* @param graphEngine the graph engine
*/
public QueryEngine (GraphTraversalSource g) {
this.g = g;
}
/**
* Finds all the parents/grandparents/etc of the given start node.
*
* @param start - the start vertex whose parent chain you want
* @return the list of start and start's parent, grandparent, etc, in
* order (ie {start, parent, grandparent, etc}
*/
public abstract List<Vertex> findParents(Vertex start);
/**
* Finds all the parents/grandparents/etc of the given start node.
*
* This method should be used in place of the #findParents(Vertex)
* as since the aai-uri is added the lookup for finding the parents
* using the given list of aai-uri will be much faster than using
* a traversal to follow a start vertex and keep repeating since
* as the number of different type of edges keeps growing that call
* will be more expensive than using the aai-uri's as they are fast lookup
*
* @param uris - list of the uris representing the aai-uris of
* parent, grandparent, etc
* @return the list of start and start's parent, grandparent, etc, in
* order (ie {start, parent, grandparent, etc}
*/
public abstract List<Vertex> findParents(String [] uris);
/**
* Finds all children, grandchildren, etc of start
*
* @param start the start vertex
* @return the list of child/grandchild/etc vertices
*/
public abstract List<Vertex> findAllChildren(Vertex start);
/**
* Finds all immediate children of start (no grandchildren or so forth) of the given type
* @param start - the start vertex
* @param type - the desired aai-node-type
* @return the list of immediate child vertices of given type
*/
public abstract List<Vertex> findChildrenOfType(Vertex start, String type);
/**
* Finds all immediate children of start (no grandchildren or so forth)
* @param start - the start vertex
* @return the list of immediate child vertices
*/
public abstract List<Vertex> findChildren(Vertex start);
/**
* Find all vertices that should be deleted in a cascade from a delete of start
*
* @param start - the start vertex
* @return the list of vertices to be deleted when start is deleted
*/
public abstract List<Vertex> findDeletable(Vertex start);
/**
* Finds the subgraph under start, including cousins as well as start's children/grandchildren/etc.
* More specifically, this includes start, all its descendants, start's cousins, and start's
* descendants' cousins (but not any of the cousins' cousins or descendants), and the edges
* connecting them.
*
* @param start - the start vertex
* @return - Tree containing nodes and edges of the subgraph
*/
public Tree<Element> findSubGraph(Vertex start) {
return findSubGraph(start, AAIProperties.MAXIMUM_DEPTH, false);
}
/**
* Finds the subgraph under start, including cousins as well as start's children/grandchildren/etc.
* More specifically, this includes start, all its descendants, start's cousins, and start's
* descendants' cousins (but not any of the cousins' cousins or descendants), and the edges
* connecting them.
*
* @param start - the start vertex
* @param iterations - depth of the subgraph, this limits how many generations of
* descendants are included
* @param nodeOnly - if true the subgraph will NOT include the cousins
* @return Tree containing nodes and edges of the subgraph
*/
public abstract Tree<Element> findSubGraph(Vertex start, int iterations, boolean nodeOnly);
/**
* Find vertices of type nodeType related to start by edges of the given
* direction and label.
*
* @param start - the start vertex
* @param direction - the direction of edges to traverse from start
* @param label - the label of edges to traverse from start
* @param nodeType - the node type the results should be
* @return the list of related vertices
*/
public abstract List<Vertex> findRelatedVertices(Vertex start, Direction direction, String label, String nodeType);
/**
* Finds cousin edges connecting start to other vertices only of types defined in an old version.
* The idea is that if a user is using an old version, they won't understand any new node types in
* subsequent versions. Thus, revealing edges to new types will cause problems. This methods
* filters any such edges out.
*
* @param start - the start vertex
* @param loader - loader for retrieving the list of allowed node types for the desired version
* (version is set when the loader was instantiated)
* @return list of cousin edges between start and any node types understood by the version specified in loader
*/
public abstract List<Edge> findEdgesForVersion(Vertex start, Loader loader);
/**
* Finds all cousins of start.
*
* @param start - the start vertex
* @return list of start's cousin vertices
*/
public abstract List<Vertex> findCousinVertices(Vertex start, String... labels);
public abstract double getDBTimeMsecs();
}
|