67c1ff3c65f8582499011bd780e111b6cce08059
[aai/gizmo.git] / src / main / java / org / openecomp / 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.openecomp.crud.dao;
25
26 import java.util.List;
27 import java.util.Map;
28
29 import org.openecomp.crud.entity.Edge;
30
31 import org.openecomp.crud.entity.Vertex;
32 import org.openecomp.crud.exception.CrudException;
33
34 public interface GraphDao {
35
36   public Vertex getVertex(String id) throws CrudException;
37
38   public Vertex getVertex(String id, String type) throws CrudException;
39
40   /**
41    * Retrieve all of the edges which are incident to the vertex with the specified identifier.
42    *
43    * @param id - The unique identifier of the vertex to retrieve the edges for.
44    * @return - A collection of edges.
45    * @throws CrudException
46    */
47   public List<Edge> getVertexEdges(String id) throws CrudException;
48
49   /**
50    * Retrieve a collection of {@link Vertex} objects which match the supplied type label
51    * and filter properties.
52    *
53    * @param type   - The vertex type that we want to retrieve.
54    * @param filter - The parameters to filter our results by.
55    * @return - A collection of vertices.
56    * @throws CrudException
57    */
58   public List<Vertex> getVertices(String type, Map<String, Object> filter) throws CrudException;
59
60   /**
61    * Retrieve an {@link Edge} from the graph database by specifying its unique identifier.
62    *
63    * @param id - The unique identifier for the Edge to be retrieved.
64    * @return - The Edge corresponding to the specified identifier.
65    * @throws CrudException
66    */
67   public Edge getEdge(String id, String type) throws CrudException;
68
69   /**
70    * Retrieve a collection of {@link Edge} objects with a given type and which match a set of
71    * supplied filter parameters.
72    *
73    * @param type   - The type of edges that we are interested in.
74    * @param filter - The parameters that we want to filter our edges by.
75    * @return - A collection of edges which match the supplied filter parameters.
76    * @throws CrudException
77    */
78   public List<Edge> getEdges(String type, Map<String, Object> filter) throws CrudException;
79
80   /**
81    * Insert a new {@link Vertex} into the graph data store.
82    *
83    * @param type       - The type label to assign to the vertex.
84    * @param properties - The properties to associated with this vertex.
85    * @return - The {@link Vertex} object that was created.
86    * @throws CrudException
87    */
88   public Vertex addVertex(String type, Map<String, Object> properties) throws CrudException;
89
90   /**
91    * Updates an existing {@link Vertex}.
92    *
93    * @param id         - The unique identifier of the vertex to be updated.
94    * @param properties - The properties to associate with the vertex.
95    * @return - The udpated vertex.
96    * @throws CrudException
97    */
98   public Vertex updateVertex(String id, String type, Map<String, Object> properties)
99       throws CrudException;
100
101   /**
102    * Removes the specified vertex from the graph data base.
103    *
104    * <p>NOTE: The vertex MUST contain NO incident edges before it can be deleted.
105    *
106    * @param id - The unique identifier of the vertex to be deleted.
107    * @throws CrudException
108    */
109   public void deleteVertex(String id, String type) throws CrudException;
110
111   /**
112    * Adds an edge to the graph database.
113    *
114    * @param type       - The 'type' label to apply to the edge.
115    * @param source     - The source vertex for this edge.
116    * @param target     - The target vertex for this edge.
117    * @param properties - The properties map to associate with this edge.
118    * @return - The {@link Edge} object that was created.
119    * @throws CrudException
120    */
121   public Edge addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties)
122       throws CrudException;
123
124   /**
125    * Updates an existing {@link Edge}.
126    *
127    * @param id         - The unique identifier of the edge to be updated.
128    * @param properties - The properties to associate with the edge.
129    * @return - The update edge.
130    * @throws CrudException
131    */
132   public Edge updateEdge(Edge edge) throws CrudException;
133
134   /**
135    * Remove the specified edge from the graph data base.
136    *
137    * @param id - The unique identifier of the edge to be deleted.
138    * @throws CrudException
139    */
140   public void deleteEdge(String id, String type) throws CrudException;
141   
142  
143   public String openTransaction();
144   public void commitTransaction(String id) throws CrudException;
145   public void rollbackTransaction(String id) throws CrudException;
146   public boolean transactionExists(String id) throws CrudException;
147   
148   public Vertex addVertex(String type, Map<String, Object> properties, String txId) throws CrudException;
149   public Edge addEdge(String type, Vertex source, Vertex target, Map<String, Object> properties, String txId)
150               throws CrudException;
151   public Vertex updateVertex(String id, String type, Map<String, Object> properties, String txId)
152               throws CrudException;
153   
154   public Edge updateEdge(Edge edge, String txId) throws CrudException;
155   public void deleteVertex(String id, String type, String txId) throws CrudException;
156   public void deleteEdge(String id, String type, String txId) throws CrudException;
157   public Edge getEdge(String id, String type, String txId) throws CrudException;
158 }