283e1a1cae3f84ca1ff42b5854b991dc2311c9d9
[aai/gizmo.git] / src / main / java / org / onap / crud / dao / GraphDao.java
1 /**
2  * ============LICENSE_START=======================================================
3  * Gizmo
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *    http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  *
22  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23  */
24 package org.onap.crud.dao;
25
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.Map;
29
30 import org.onap.crud.entity.Edge;
31
32 import org.onap.crud.entity.Vertex;
33 import org.onap.crud.exception.CrudException;
34
35 public interface GraphDao {
36
37   public Vertex getVertex(String id, String version) throws CrudException;
38
39   public Vertex getVertex(String id, String type, String version) throws CrudException;
40
41   /**
42    * Retrieve all of the edges which are incident to the vertex with the
43    * specified identifier.
44    *
45    * @param id
46    *          - The unique identifier of the vertex to retrieve the edges for.
47    * @return - A collection of edges.
48    * @throws CrudException
49    */
50   public List<Edge> getVertexEdges(String id) throws CrudException;
51
52   /**
53    * Retrieve a collection of {@link Vertex} objects which match the supplied
54    * type label and filter properties.
55    *
56    * @param type
57    *          - The vertex type that we want to retrieve.
58    * @param filter
59    *          - The parameters to filter our results by.
60    * @return - A collection of vertices.
61    * @throws CrudException
62    */
63   public List<Vertex> getVertices(String type, Map<String, Object> filter, String version) throws CrudException;
64
65   /**
66    * Retrieve a collection of {@link Vertex} objects which match the supplied
67    * type label and filter properties.
68    *
69    * @param type
70    *          - The vertex type that we want to retrieve.
71    * @param filter
72    *          - The parameters to filter our results by.
73    * @param properties
74    *          - The properties to retrieve with the vertex
75    * @return - A collection of vertices.
76    * @throws CrudException
77    */
78   public List<Vertex> getVertices(String type, Map<String, Object> filter, HashSet<String> properties, String version) throws CrudException;
79
80   /**
81    * Retrieve an {@link Edge} from the graph database by specifying its unique
82    * identifier.
83    *
84    * @param id
85    *          - The unique identifier for the Edge to be retrieved.
86    * @return - The Edge corresponding to the specified identifier.
87    * @throws CrudException
88    */
89   public Edge getEdge(String id, String type) throws CrudException;
90
91   /**
92    * Retrieve a collection of {@link Edge} objects with a given type and which
93    * match a set of supplied filter parameters.
94    *
95    * @param type
96    *          - The type of edges that we are interested in.
97    * @param filter
98    *          - The parameters that we want to filter our edges by.
99    * @return - A collection of edges which match the supplied filter parameters.
100    * @throws CrudException
101    */
102   public List<Edge> getEdges(String type, Map<String, Object> filter) throws CrudException;
103
104   /**
105    * Insert a new {@link Vertex} into the graph data store.
106    *
107    * @param type
108    *          - The type label to assign to the vertex.
109    * @param properties
110    *          - The properties to associated with this vertex.
111    * @return - The {@link Vertex} object that was created.
112    * @throws CrudException
113    */
114   public Vertex addVertex(String type, Map<String, Object> properties, String version) throws CrudException;
115
116   /**
117    * Updates an existing {@link Vertex}.
118    *
119    * @param id
120    *          - The unique identifier of the vertex to be updated.
121    * @param properties
122    *          - The properties to associate with the vertex.
123    * @return - The udpated vertex.
124    * @throws CrudException
125    */
126   public Vertex updateVertex(String id, String type, Map<String, Object> properties, String version) throws CrudException;
127
128   /**
129    * Removes the specified vertex from the graph data base.
130    *
131    * <p>
132    * NOTE: The vertex MUST contain NO incident edges before it can be deleted.
133    *
134    * @param id
135    *          - The unique identifier of the vertex to be deleted.
136    * @throws CrudException
137    */
138   public void deleteVertex(String id, String type) throws CrudException;
139
140   /**
141    * Adds an edge to the graph database.
142    *
143    * @param type
144    *          - The 'type' label to apply to the edge.
145    * @param source
146    *          - The source vertex for this edge.
147    * @param target
148    *          - The target vertex for this edge.
149    * @param properties
150    *          - The properties map to associate with this edge.
151    * @return - The {@link Edge} object that was created.
152    * @throws CrudException
153    */
154   public Edge addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties, String version) throws CrudException;
155
156   /**
157    * Updates an existing {@link Edge}.
158    *
159    * @param id
160    *          - The unique identifier of the edge to be updated.
161    * @param properties
162    *          - The properties to associate with the edge.
163    * @return - The update edge.
164    * @throws CrudException
165    */
166   public Edge updateEdge(Edge edge) throws CrudException;
167
168   /**
169    * Remove the specified edge from the graph data base.
170    *
171    * @param id
172    *          - The unique identifier of the edge to be deleted.
173    * @throws CrudException
174    */
175   public void deleteEdge(String id, String type) throws CrudException;
176
177   public String openTransaction();
178
179   public void commitTransaction(String id) throws CrudException;
180
181   public void rollbackTransaction(String id) throws CrudException;
182
183   public boolean transactionExists(String id) throws CrudException;
184
185   public Vertex addVertex(String type, Map<String, Object> properties, String version, String txId) throws CrudException;
186
187   public Edge addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties, String version, String txId)
188       throws CrudException;
189
190   public Vertex updateVertex(String id, String type, Map<String, Object> properties, String version, String txId) throws CrudException;
191
192   public Edge updateEdge(Edge edge, String txId) throws CrudException;
193
194   public void deleteVertex(String id, String type, String txId) throws CrudException;
195
196   public void deleteEdge(String id, String type, String txId) throws CrudException;
197
198   public Edge getEdge(String id, String type, String txId) throws CrudException;
199 }