Fix Reference Key columns persistence issue in db
[policy/models.git] / models-dao / src / main / java / org / onap / policy / models / dao / PfDao.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2021 Nordix Foundation.
4  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.dao;
23
24 import java.time.Instant;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.Map;
28 import org.onap.policy.models.base.PfConcept;
29 import org.onap.policy.models.base.PfConceptKey;
30 import org.onap.policy.models.base.PfModelException;
31 import org.onap.policy.models.base.PfReferenceKey;
32 import org.onap.policy.models.base.PfReferenceTimestampKey;
33 import org.onap.policy.models.base.PfTimestampKey;
34
35 /**
36  * The Interface PfDao describes the DAO interface for reading and writing Policy Framework {@link PfConcept} concepts
37  * to and from databases using JDBC.
38  */
39 public interface PfDao {
40
41     /**
42      * Initialize the Policy Framework DAO with the given parameters.
43      *
44      * @param daoParameters parameters to use to access the database
45      * @throws PfModelException on initialization errors
46      */
47     void init(DaoParameters daoParameters) throws PfModelException;
48
49     /**
50      * Close the Policy Framework DAO.
51      */
52     void close();
53
54     /**
55      * Creates an Policy Framework concept on the database.
56      *
57      * @param <T> the type of the object to create, a subclass of {@link PfConcept}
58      * @param obj the object to create
59      */
60     <T extends PfConcept> void create(T obj);
61
62     /**
63      * Delete an Policy Framework concept on the database.
64      *
65      * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
66      * @param obj the object to delete
67      */
68     <T extends PfConcept> void delete(T obj);
69
70     /**
71      * Delete an Policy Framework concept on the database.
72      *
73      * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
74      * @param someClass the class of the object to delete, a subclass of {@link PfConcept}
75      * @param key the key of the object to delete
76      */
77     <T extends PfConcept> void delete(Class<T> someClass, PfConceptKey key);
78
79     /**
80      * Delete an Policy Framework concept on the database.
81      *
82      * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
83      * @param someClass the class of the object to delete, a subclass of {@link PfConcept}
84      * @param key the key of the object to delete
85      */
86     <T extends PfConcept> void delete(Class<T> someClass, PfReferenceKey key);
87
88     /**
89      * Delete an Policy Framework concept on the database.
90      *
91      * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
92      * @param someClass the class of the object to delete, a subclass of {@link PfConcept}
93      * @param timeStampKey the PfTimestampKey of the object to delete
94      */
95     <T extends PfConcept> void delete(Class<T> someClass, PfTimestampKey timeStampKey);
96
97     /**
98      * Create a collection of objects in the database.
99      *
100      * @param <T> the type of the object to create, a subclass of {@link PfConcept}
101      * @param objs the objects to create
102      */
103     <T extends PfConcept> void createCollection(Collection<T> objs);
104
105     /**
106      * Delete a collection of objects in the database.
107      *
108      * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
109      * @param objs the objects to delete
110      */
111     <T extends PfConcept> void deleteCollection(Collection<T> objs);
112
113     /**
114      * Delete a collection of objects in the database referred to by concept key.
115      *
116      * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
117      * @param someClass the class of the objects to delete, a subclass of {@link PfConcept}
118      * @param keys the keys of the objects to delete
119      * @return the number of objects deleted
120      */
121     <T extends PfConcept> int deleteByConceptKey(Class<T> someClass, Collection<PfConceptKey> keys);
122
123     /**
124      * Delete a collection of objects in the database referred to by reference key.
125      *
126      * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
127      * @param someClass the class of the objects to delete, a subclass of {@link PfConcept}
128      * @param keys the keys of the objects to delete
129      * @return the number of objects deleted
130      */
131     <T extends PfConcept> int deleteByReferenceKey(Class<T> someClass, Collection<PfReferenceKey> keys);
132
133     /**
134      * Delete all objects of a given class in the database.
135      *
136      * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
137      * @param someClass the class of the objects to delete, a subclass of {@link PfConcept}
138      */
139     <T extends PfConcept> void deleteAll(Class<T> someClass);
140
141     /**
142      * Get an object from the database, referred to by concept key.
143      *
144      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
145      * @param someClass the class of the object to get, a subclass of {@link PfConcept}, if name is null, all concepts
146      *        of type T are returned, if name is not null and version is null, all versions of that concept matching the
147      *        name are returned.
148      * @param name the name of the object to get, null returns all objects
149      * @param version the version the object to get, null returns all objects for a specified name
150      * @return the objects that was retrieved from the database
151      */
152     <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version);
153
154     /**
155      * Get an object from the database, referred to by concept key.
156      *
157      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
158      * @param someClass the class of the object to get, a subclass of {@link PfConcept}, if name is null, all concepts
159      *        of type T are returned, if name is not null and version is null, all versions of that concept matching the
160      *        name are returned.
161      * @param name the name of the object to get, null returns all objects
162      * @param version the version the object to get, null returns all objects for a specified name
163      * @param startTime the start timeStamp to filter from database, filter rule: startTime <= filteredRecord timeStamp
164      *        <= endTime. null for ignore start time.
165      * @param endTime the end timeStamp to filter from database, filter rule: startTime <= filteredRecord timeStamp <=
166      *        endTime. null for ignore end time
167      * @param filterMap Map store extra key/value used to filter from database, can be null.
168      * @param sortOrder sortOrder to query database
169      * @param getRecordNum Total query count from database
170      * @return the objects that was retrieved from the database
171      */
172     <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version, Instant startTime,
173             Instant endTime, Map<String, Object> filterMap, String sortOrder, int getRecordNum);
174
175     /**
176      * Get an object from the database, referred to by concept key.
177      *
178      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
179      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
180      * @param key the PfConceptKey of the object to get
181      * @return the object that was retrieved from the database
182      */
183     <T extends PfConcept> T get(Class<T> someClass, PfConceptKey key);
184
185     /**
186      * Get an object from the database, referred to by reference key.
187      *
188      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
189      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
190      * @param key the PfReferenceKey of the object to get
191      * @return the object that was retrieved from the database or null if the object was not retrieved
192      */
193     <T extends PfConcept> T get(Class<T> someClass, PfReferenceKey key);
194
195     /**
196      * Get an object from the database, referred to by reference key.
197      *
198      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
199      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
200      * @param timestampKey the PfTimestampKey of the object to get
201      * @return the object that was retrieved from the database or null if the object was not retrieved
202      */
203     <T extends PfConcept> T get(Class<T> someClass, PfTimestampKey timestampKey);
204
205     /**
206      * Get an object from the database, referred to by reference timestamp key.
207      *
208      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
209      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
210      * @param key the PfReferenceTimestampKey of the object to get
211      * @return the object that was retrieved from the database or null if the object was not retrieved
212      */
213     <T extends PfConcept> T get(Class<T> someClass, PfReferenceTimestampKey key);
214
215     /**
216      * Get all the objects in the database of a given type.
217      *
218      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
219      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
220      * @return the objects or null if no objects were retrieved
221      */
222     <T extends PfConcept> List<T> getAll(Class<T> someClass);
223
224     /**
225      * Get all the objects in the database of the given type with the given parent concept key.
226      *
227      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
228      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
229      * @param parentKey the parent key of the concepts to get
230      * @return the all
231      */
232     <T extends PfConcept> List<T> getAll(Class<T> someClass, PfConceptKey parentKey);
233
234     /**
235      * Get all the objects in the database of a given type.
236      *
237      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
238      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
239      * @param name the name of the concepts for which to get all versions
240      * @return the objects or null if no objects were retrieved
241      */
242     <T extends PfConcept> List<T> getAllVersions(Class<T> someClass, final String name);
243
244     /**
245      * Get all the objects in the database of a given type.
246      *
247      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
248      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
249      * @param parentKeyName the name of the concepts for which to get all versions
250      * @return the objects or null if no objects were retrieved
251      */
252     <T extends PfConcept> List<T> getAllVersionsByParent(Class<T> someClass, final String parentKeyName);
253
254     /**
255      * Get a concept from the database with the given concept key.
256      *
257      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
258      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
259      * @param conceptId the concept key of the concept to get
260      * @return the concept that matches the key or null if the concept is not retrieved
261      */
262     <T extends PfConcept> T getConcept(Class<T> someClass, PfConceptKey conceptId);
263
264     /**
265      * Get a concept from the database with the given reference key.
266      *
267      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
268      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
269      * @param conceptId the concept key of the concept to get
270      * @return the concept that matches the key or null if the concept is not retrieved
271      */
272     <T extends PfConcept> T getConcept(Class<T> someClass, PfReferenceKey conceptId);
273
274     /**
275      * Get the number of instances of a concept that exist in the database.
276      *
277      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
278      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
279      * @return the number of instances of the concept in the database
280      */
281     <T extends PfConcept> long size(Class<T> someClass);
282
283     /**
284      * Update a concept in the database.
285      *
286      * @param <T> the type of the object to update, a subclass of {@link PfConcept}
287      * @param obj the object to update
288      * @return the updated object
289      */
290     <T extends PfConcept> T update(T obj);
291 }