contains-other-v no longer implies delete-other-v
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / serialization / engines / TitanDBEngine.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  *
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.serialization.engines;
23
24 import java.util.ArrayList;
25 import java.util.Iterator;
26 import java.util.List;
27
28 import org.apache.tinkerpop.gremlin.structure.Vertex;
29 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
30 import org.onap.aai.dbmap.DBConnectionType;
31 import org.onap.aai.introspection.Loader;
32 import org.onap.aai.serialization.db.TitanGraphSingleton;
33
34 public class TitanDBEngine extends TransactionalGraphEngine {
35
36         /**
37          * Instantiates a new titan DB engine.
38          *
39          * @param style the style
40          * @param loader the loader
41          */
42         public TitanDBEngine(QueryStyle style, DBConnectionType connectionType, Loader loader) {
43                 super(style, loader, connectionType, TitanGraphSingleton.getInstance());
44         }
45         
46         /**
47          * Instantiates a new titan DB engine.
48          *
49          * @param style the style
50          * @param loader the loader
51          * @param connect the connect
52          */
53         public TitanDBEngine(QueryStyle style, Loader loader, boolean connect) {
54                 super(style, loader);
55                 if (connect) {
56                         this.singleton = TitanGraphSingleton.getInstance();
57                 }
58         }
59
60         /**
61          * {@inheritDoc} 
62          */
63         @Override
64         public boolean setListProperty(Vertex v, String name, List<?> objs) {
65
66                 //clear out list full replace style
67                 
68                 Iterator<VertexProperty<Object>> iterator = v.properties(name);
69                 while (iterator.hasNext()) {
70                         iterator.next().remove();
71                 }
72                 if (objs != null) {
73                         for (Object obj : objs) {
74                                 v.property(name, obj);
75                         }
76                 }
77                 return true;
78         }
79         
80         /**
81          * {@inheritDoc} 
82          */
83         @Override
84         public List<Object> getListProperty(Vertex v, String name) {
85
86                 List<Object> result = new ArrayList<Object>();
87                 
88                 Iterator<VertexProperty<Object>> iterator = v.properties(name);
89                 
90                 while (iterator.hasNext()) {
91                         result.add(iterator.next().value());
92                 }
93                 
94                 if (result.size() == 0) {
95                         result = null;
96                 }
97                 
98                 return result;
99
100         }
101         
102 }