655e9a99f6a11e7538473d9c652f31143f56f4c2
[policy/apex-pdp.git] / model / basic-model / src / main / java / org / onap / policy / apex / model / basicmodel / dao / ApexDao.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.model.basicmodel.dao;
22
23 import java.util.Collection;
24 import java.util.List;
25
26 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
27 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
28 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
30
31 /**
32  * The Interface ApexDao describes the DAO interface for reading and writing Apex {@link AxConcept} concepts to and from
33  * databases using JDBC.
34  *
35  * @author Sergey Sachkov
36  * @author liam.fallon@ericsson.com
37  */
38 public interface ApexDao {
39
40     /**
41      * Initialize the Apex DAO with the given parameters.
42      *
43      * @param daoParameters parameters to use to access the database
44      * @throws ApexException on initialization errors
45      */
46     void init(DaoParameters daoParameters) throws ApexException;
47
48     /**
49      * Close the Apex DAO.
50      */
51     void close();
52
53     /**
54      * Creates an Apex concept on the database.
55      *
56      * @param <T> the type of the object to create, a subclass of {@link AxConcept}
57      * @param obj the object to create
58      */
59     <T extends AxConcept> void create(T obj);
60
61     /**
62      * Delete an Apex concept on the database.
63      *
64      * @param <T> the type of the object to delete, a subclass of {@link AxConcept}
65      * @param obj the object to delete
66      */
67     <T extends AxConcept> void delete(T obj);
68
69     /**
70      * Delete an Apex concept on the database.
71      *
72      * @param <T> the type of the object to delete, a subclass of {@link AxConcept}
73      * @param someClass the class of the object to delete, a subclass of {@link AxConcept}
74      * @param key the key of the object to delete
75      */
76     <T extends AxConcept> void delete(Class<T> someClass, AxArtifactKey key);
77
78     /**
79      * Delete an Apex concept on the database.
80      *
81      * @param <T> the type of the object to delete, a subclass of {@link AxConcept}
82      * @param someClass the class of the object to delete, a subclass of {@link AxConcept}
83      * @param key the key of the object to delete
84      */
85     <T extends AxConcept> void delete(Class<T> someClass, AxReferenceKey key);
86
87     /**
88      * Create a collection of objects in the database.
89      *
90      * @param <T> the type of the object to create, a subclass of {@link AxConcept}
91      * @param objs the objects to create
92      */
93     <T extends AxConcept> void createCollection(Collection<T> objs);
94
95     /**
96      * Delete a collection of objects in the database.
97      *
98      * @param <T> the type of the objects to delete, a subclass of {@link AxConcept}
99      * @param objs the objects to delete
100      */
101     <T extends AxConcept> void deleteCollection(Collection<T> objs);
102
103     /**
104      * Delete a collection of objects in the database referred to by artifact key.
105      *
106      * @param <T> the type of the objects to delete, a subclass of {@link AxConcept}
107      * @param someClass the class of the objects to delete, a subclass of {@link AxConcept}
108      * @param keys the keys of the objects to delete
109      * @return the number of objects deleted
110      */
111     <T extends AxConcept> int deleteByArtifactKey(Class<T> someClass, Collection<AxArtifactKey> keys);
112
113     /**
114      * Delete a collection of objects in the database referred to by reference key.
115      *
116      * @param <T> the type of the objects to delete, a subclass of {@link AxConcept}
117      * @param someClass the class of the objects to delete, a subclass of {@link AxConcept}
118      * @param keys the keys of the objects to delete
119      * @return the number of objects deleted
120      */
121     <T extends AxConcept> int deleteByReferenceKey(Class<T> someClass, Collection<AxReferenceKey> keys);
122
123     /**
124      * Delete all objects of a given class in the database.
125      *
126      * @param <T> the type of the objects to delete, a subclass of {@link AxConcept}
127      * @param someClass the class of the objects to delete, a subclass of {@link AxConcept}
128      */
129     <T extends AxConcept> void deleteAll(Class<T> someClass);
130
131     /**
132      * Get an object from the database, referred to by artifact key.
133      *
134      * @param <T> the type of the object to get, a subclass of {@link AxConcept}
135      * @param someClass the class of the object to get, a subclass of {@link AxConcept}
136      * @param key the key of the object to get
137      * @return the object that was retrieved from the database
138      */
139     <T extends AxConcept> T get(Class<T> someClass, AxArtifactKey key);
140
141     /**
142      * Get an object from the database, referred to by reference key.
143      *
144      * @param <T> the type of the object to get, a subclass of {@link AxConcept}
145      * @param someClass the class of the object to get, a subclass of {@link AxConcept}
146      * @param key the key of the object to get
147      * @return the object that was retrieved from the database or null if the object was not retrieved
148      */
149     <T extends AxConcept> T get(Class<T> someClass, AxReferenceKey key);
150
151     /**
152      * Get all the objects in the database of a given type.
153      *
154      * @param <T> the type of the objects to get, a subclass of {@link AxConcept}
155      * @param someClass the class of the objects to get, a subclass of {@link AxConcept}
156      * @return the objects or null if no objects were retrieved
157      */
158     <T extends AxConcept> List<T> getAll(Class<T> someClass);
159
160     /**
161      * Get all the objects in the database of the given type with the given parent artifact key.
162      *
163      * @param <T> the type of the objects to get, a subclass of {@link AxConcept}
164      * @param someClass the class of the objects to get, a subclass of {@link AxConcept}
165      * @param parentKey the parent key of the concepts to get
166      * @return the all
167      */
168     <T extends AxConcept> List<T> getAll(Class<T> someClass, AxArtifactKey parentKey);
169
170     /**
171      * Get a concept from the database with the given artifact key.
172      *
173      * @param <T> the type of the object to get, a subclass of {@link AxConcept}
174      * @param someClass the class of the object to get, a subclass of {@link AxConcept}
175      * @param artifactId the artifact key of the concept to get
176      * @return the concept that matches the key or null if the concept is not retrieved
177      */
178     <T extends AxConcept> T getArtifact(Class<T> someClass, AxArtifactKey artifactId);
179
180     /**
181      * Get a concept from the database with the given reference key.
182      *
183      * @param <T> the type of the object to get, a subclass of {@link AxConcept}
184      * @param someClass the class of the object to get, a subclass of {@link AxConcept}
185      * @param artifactId the artifact key of the concept to get
186      * @return the concept that matches the key or null if the concept is not retrieved
187      */
188     <T extends AxConcept> T getArtifact(Class<T> someClass, AxReferenceKey artifactId);
189
190     /**
191      * Get the number of instances of a concept that exist in the database.
192      *
193      * @param <T> the type of the object to get, a subclass of {@link AxConcept}
194      * @param someClass the class of the object to get, a subclass of {@link AxConcept}
195      * @return the number of instances of the concept in the database
196      */
197     <T extends AxConcept> long size(Class<T> someClass);
198
199     /**
200      * Update a concept in the database.
201      *
202      * @param <T> the type of the object to get, a subclass of {@link AxConcept}
203      * @param obj the object to update
204      * @return the updated object
205      */
206     <T extends AxConcept> T update(T obj);
207 }