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