Add impl of more PDP persistence
[policy/models.git] / models-dao / src / main / java / org / onap / policy / models / dao / PfDao.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
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.models.dao;
22
23 import java.util.Collection;
24 import java.util.List;
25
26 import org.onap.policy.models.base.PfConcept;
27 import org.onap.policy.models.base.PfConceptKey;
28 import org.onap.policy.models.base.PfModelException;
29 import org.onap.policy.models.base.PfReferenceKey;
30
31 /**
32  * The Interface PfDao describes the DAO interface for reading and writing Policy Framework {@link PfConcept} concepts
33  * to and from databases using JDBC.
34  */
35 public interface PfDao {
36
37     /**
38      * Initialize the Policy Framework DAO with the given parameters.
39      *
40      * @param daoParameters parameters to use to access the database
41      * @throws PfModelException on initialization errors
42      */
43     void init(DaoParameters daoParameters) throws PfModelException;
44
45     /**
46      * Close the Policy Framework DAO.
47      */
48     void close();
49
50     /**
51      * Creates an Policy Framework concept on the database.
52      *
53      * @param <T> the type of the object to create, a subclass of {@link PfConcept}
54      * @param obj the object to create
55      */
56     <T extends PfConcept> void create(T obj);
57
58     /**
59      * Delete an Policy Framework concept on the database.
60      *
61      * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
62      * @param obj the object to delete
63      */
64     <T extends PfConcept> void delete(T obj);
65
66     /**
67      * Delete an Policy Framework concept on the database.
68      *
69      * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
70      * @param someClass the class of the object to delete, a subclass of {@link PfConcept}
71      * @param key the key of the object to delete
72      */
73     <T extends PfConcept> void delete(Class<T> someClass, PfConceptKey key);
74
75     /**
76      * Delete an Policy Framework concept on the database.
77      *
78      * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
79      * @param someClass the class of the object to delete, a subclass of {@link PfConcept}
80      * @param key the key of the object to delete
81      */
82     <T extends PfConcept> void delete(Class<T> someClass, PfReferenceKey key);
83
84     /**
85      * Create a collection of objects in the database.
86      *
87      * @param <T> the type of the object to create, a subclass of {@link PfConcept}
88      * @param objs the objects to create
89      */
90     <T extends PfConcept> void createCollection(Collection<T> objs);
91
92     /**
93      * Delete a collection of objects in the database.
94      *
95      * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
96      * @param objs the objects to delete
97      */
98     <T extends PfConcept> void deleteCollection(Collection<T> objs);
99
100     /**
101      * Delete a collection of objects in the database referred to by concept key.
102      *
103      * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
104      * @param someClass the class of the objects to delete, a subclass of {@link PfConcept}
105      * @param keys the keys of the objects to delete
106      * @return the number of objects deleted
107      */
108     <T extends PfConcept> int deleteByConceptKey(Class<T> someClass, Collection<PfConceptKey> keys);
109
110     /**
111      * policypolicypolicy Delete a collection of objects in the database referred to by reference key.
112      *
113      * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
114      * @param someClass the class of the objects to delete, a subclass of {@link PfConcept}
115      * @param keys the keys of the objects to delete
116      * @return the number of objects deleted
117      */
118     <T extends PfConcept> int deleteByReferenceKey(Class<T> someClass, Collection<PfReferenceKey> keys);
119
120     /**
121      * Delete all objects of a given class in the database.
122      *
123      * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
124      * @param someClass the class of the objects to delete, a subclass of {@link PfConcept}
125      */
126     <T extends PfConcept> void deleteAll(Class<T> someClass);
127
128     /**
129      * Get an object from the database, referred to by concept key.
130      *
131      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
132      * @param someClass the class of the object to get, a subclass of {@link PfConcept}, if name is null, all concepts
133      *        of type T are returned, if name is not null and version is null, all versions of that concept matching the
134      *        name are returned.
135      * @param key the key of the object to get
136      * @return the objects that was retrieved from the database
137      */
138     <T extends PfConcept> List<T> getFiltered(Class<T> someClass, PfConceptKey key);
139
140     /**
141      * Get an object from the database, referred to by concept key.
142      *
143      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
144      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
145      * @param key the key of the object to get
146      * @return the object that was retrieved from the database
147      */
148     <T extends PfConcept> T get(Class<T> someClass, PfConceptKey key);
149
150     /**
151      * Get an object from the database, referred to by reference key.
152      *
153      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
154      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
155      * @param key the key of the object to get
156      * @return the object that was retrieved from the database or null if the object was not retrieved
157      */
158     <T extends PfConcept> T get(Class<T> someClass, PfReferenceKey key);
159
160     /**
161      * Get all the objects in the database of a given type.
162      *
163      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
164      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
165      * @return the objects or null if no objects were retrieved
166      */
167     <T extends PfConcept> List<T> getAll(Class<T> someClass);
168
169     /**
170      * Get all the objects in the database of the given type with the given parent concept key.
171      *
172      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
173      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
174      * @param parentKey the parent key of the concepts to get
175      * @return the all
176      */
177     <T extends PfConcept> List<T> getAll(Class<T> someClass, PfConceptKey parentKey);
178
179     /**
180      * Get all the objects in the database of a given type.
181      *
182      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
183      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
184      * @param name the name of the concepts for which to get all versions
185      * @return the objects or null if no objects were retrieved
186      */
187     <T extends PfConcept> List<T> getAllVersions(Class<T> someClass, final String name);
188
189     /**
190      * Get latest version of objects in the database of a given type.
191      *
192      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
193      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
194      * @return the objects or null if no objects were retrieved
195      */
196     <T extends PfConcept> List<T> getLatestVersions(Class<T> someClass);
197
198     /**
199      * Get latest version of an object in the database of a given type.
200      *
201      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
202      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
203      * @param conceptName the name of the concept for which to get the latest version
204      * @return the objects or null if no objects were retrieved
205      */
206     <T extends PfConcept> T getLatestVersion(Class<T> someClass, final String conceptName);
207
208     /**
209      * Get a concept from the database with the given concept key.
210      *
211      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
212      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
213      * @param conceptId the concept key of the concept to get
214      * @return the concept that matches the key or null if the concept is not retrieved
215      */
216     <T extends PfConcept> T getConcept(Class<T> someClass, PfConceptKey conceptId);
217
218     /**
219      * Get a concept from the database with the given reference key.
220      *
221      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
222      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
223      * @param conceptId the concept key of the concept to get
224      * @return the concept that matches the key or null if the concept is not retrieved
225      */
226     <T extends PfConcept> T getConcept(Class<T> someClass, PfReferenceKey conceptId);
227
228     /**
229      * Get the number of instances of a concept that exist in the database.
230      *
231      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
232      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
233      * @return the number of instances of the concept in the database
234      */
235     <T extends PfConcept> long size(Class<T> someClass);
236
237     /**
238      * Update a concept in the database.
239      *
240      * @param <T> the type of the object to update, a subclass of {@link PfConcept}
241      * @param obj the object to update
242      * @return the updated object
243      */
244     <T extends PfConcept> T update(T obj);
245 }