346cf026f3852ed5fa4fe112f64d5bfeed7a5e3b
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / serialization / engines / JanusGraphDBEngine.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
21 package org.onap.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.onap.aai.dbmap.DBConnectionType;
30 import org.onap.aai.introspection.Loader;
31 import org.onap.aai.serialization.db.JanusGraphSingleton;
32
33 public class JanusGraphDBEngine extends TransactionalGraphEngine {
34
35     /**
36      * Instantiates a new JanusGraph DB engine.
37      *
38      * @param style the style
39      * @param loader the loader
40      */
41     public JanusGraphDBEngine(QueryStyle style, DBConnectionType connectionType, Loader loader) {
42         super(style, loader, connectionType, JanusGraphSingleton.getInstance());
43     }
44
45     /**
46      * Instantiates a new JanusGraph DB engine.
47      *
48      * @param style the style
49      * @param loader the loader
50      * @param connect the connect
51      */
52     public JanusGraphDBEngine(QueryStyle style, Loader loader, boolean connect) {
53         super(style, loader);
54         if (connect) {
55             this.singleton = JanusGraphSingleton.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 }