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