Merge "Rename keywords used as column names in API and PAP JPA"
[policy/models.git] / models-dao / src / main / java / org / onap / policy / models / dao / PfDao.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2020 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.util.Collection;
25 import java.util.Date;
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.PfTimestampKey;
33
34 /**
35  * The Interface PfDao describes the DAO interface for reading and writing Policy Framework {@link PfConcept} concepts
36  * to and from databases using JDBC.
37  */
38 public interface PfDao {
39
40     /**
41      * Initialize the Policy Framework DAO with the given parameters.
42      *
43      * @param daoParameters parameters to use to access the database
44      * @throws PfModelException on initialization errors
45      */
46     void init(DaoParameters daoParameters) throws PfModelException;
47
48     /**
49      * Close the Policy Framework DAO.
50      */
51     void close();
52
53     /**
54      * Creates an Policy Framework concept on the database.
55      *
56      * @param <T> the type of the object to create, a subclass of {@link PfConcept}
57      * @param obj the object to create
58      */
59     <T extends PfConcept> void create(T obj);
60
61     /**
62      * Delete an Policy Framework concept on the database.
63      *
64      * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
65      * @param obj the object to delete
66      */
67     <T extends PfConcept> void delete(T obj);
68
69     /**
70      * Delete an Policy Framework concept on the database.
71      *
72      * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
73      * @param someClass the class of the object to delete, a subclass of {@link PfConcept}
74      * @param key the key of the object to delete
75      */
76     <T extends PfConcept> void delete(Class<T> someClass, PfConceptKey key);
77
78     /**
79      * Delete an Policy Framework concept on the database.
80      *
81      * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
82      * @param someClass the class of the object to delete, a subclass of {@link PfConcept}
83      * @param key the key of the object to delete
84      */
85     <T extends PfConcept> void delete(Class<T> someClass, PfReferenceKey key);
86
87     /**
88      * Delete an Policy Framework concept on the database.
89      *
90      * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
91      * @param someClass the class of the object to delete, a subclass of {@link PfConcept}
92      * @param timeStampKey the PfTimestampKey of the object to delete
93      */
94     <T extends PfConcept> void delete(Class<T> someClass, PfTimestampKey timeStampKey);
95
96     /**
97      * Create a collection of objects in the database.
98      *
99      * @param <T> the type of the object to create, a subclass of {@link PfConcept}
100      * @param objs the objects to create
101      */
102     <T extends PfConcept> void createCollection(Collection<T> objs);
103
104     /**
105      * Delete a collection of objects in the database.
106      *
107      * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
108      * @param objs the objects to delete
109      */
110     <T extends PfConcept> void deleteCollection(Collection<T> objs);
111
112     /**
113      * Delete a collection of objects in the database referred to by concept key.
114      *
115      * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
116      * @param someClass the class of the objects to delete, a subclass of {@link PfConcept}
117      * @param keys the keys of the objects to delete
118      * @return the number of objects deleted
119      */
120     <T extends PfConcept> int deleteByConceptKey(Class<T> someClass, Collection<PfConceptKey> keys);
121
122     /**
123      * Delete a collection of objects in the database referred to by reference key.
124      *
125      * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
126      * @param someClass the class of the objects to delete, a subclass of {@link PfConcept}
127      * @param keys the keys of the objects to delete
128      * @return the number of objects deleted
129      */
130     <T extends PfConcept> int deleteByReferenceKey(Class<T> someClass, Collection<PfReferenceKey> keys);
131
132     /**
133      * Delete all objects of a given class in the database.
134      *
135      * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
136      * @param someClass the class of the objects to delete, a subclass of {@link PfConcept}
137      */
138     <T extends PfConcept> void deleteAll(Class<T> someClass);
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}, if name is null, all concepts
145      *        of type T are returned, if name is not null and version is null, all versions of that concept matching the
146      *        name are returned.
147      * @param name the name of the object to get, null returns all objects
148      * @param version the version the object to get, null returns all objects for a specified name
149      * @return the objects that was retrieved from the database
150      */
151     <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version);
152
153     /**
154      * Get an object from the database, referred to by concept key.
155      *
156      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
157      * @param someClass the class of the object to get, a subclass of {@link PfConcept}, if name is null, all concepts
158      *        of type T are returned, if name is not null and version is null, all versions of that concept matching the
159      *        name are returned.
160      * @param name the name of the object to get, null returns all objects
161      * @param version the version the object to get, null returns all objects for a specified name
162      * @param startTime the start timeStamp to filter from database, filter rule: startTime <= filteredRecord timeStamp
163      *        <= endTime. null for ignore start time.
164      * @param endTime the end timeStamp to filter from database, filter rule: startTime <= filteredRecord timeStamp <=
165      *        endTime. null for ignore end time
166      * @param filterMap Map store extra key/value used to filter from database, can be null.
167      * @param sortOrder sortOrder to query database
168      * @param getRecordNum Total query count from database
169      * @return the objects that was retrieved from the database
170      */
171     <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version, Date startTime,
172             Date endTime, Map<String, Object> filterMap, String sortOrder, int getRecordNum);
173
174     /**
175      * Get an object from the database, referred to by concept key.
176      *
177      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
178      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
179      * @param key the PfConceptKey of the object to get
180      * @return the object that was retrieved from the database
181      */
182     <T extends PfConcept> T get(Class<T> someClass, PfConceptKey key);
183
184     /**
185      * Get an object from the database, referred to by reference key.
186      *
187      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
188      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
189      * @param key the PfReferenceKey of the object to get
190      * @return the object that was retrieved from the database or null if the object was not retrieved
191      */
192     <T extends PfConcept> T get(Class<T> someClass, PfReferenceKey key);
193
194     /**
195      * Get an object from the database, referred to by reference key.
196      *
197      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
198      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
199      * @param timestampKey the PfTimestampKey of the object to get
200      * @return the object that was retrieved from the database or null if the object was not retrieved
201      */
202     <T extends PfConcept> T get(Class<T> someClass, PfTimestampKey timestampKey);
203
204     /**
205      * Get all the objects in the database of a given type.
206      *
207      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
208      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
209      * @return the objects or null if no objects were retrieved
210      */
211     <T extends PfConcept> List<T> getAll(Class<T> someClass);
212
213     /**
214      * Get all the objects in the database of the given type with the given parent concept key.
215      *
216      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
217      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
218      * @param parentKey the parent key of the concepts to get
219      * @return the all
220      */
221     <T extends PfConcept> List<T> getAll(Class<T> someClass, PfConceptKey parentKey);
222
223     /**
224      * Get all the objects in the database of a given type.
225      *
226      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
227      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
228      * @param name the name of the concepts for which to get all versions
229      * @return the objects or null if no objects were retrieved
230      */
231     <T extends PfConcept> List<T> getAllVersions(Class<T> someClass, final String name);
232
233     /**
234      * Get all the objects in the database of a given type.
235      *
236      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
237      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
238      * @param parentKeyName the name of the concepts for which to get all versions
239      * @return the objects or null if no objects were retrieved
240      */
241     <T extends PfConcept> List<T> getAllVersionsByParent(Class<T> someClass, final String parentKeyName);
242
243     /**
244      * Get a concept from the database with the given concept key.
245      *
246      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
247      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
248      * @param conceptId the concept key of the concept to get
249      * @return the concept that matches the key or null if the concept is not retrieved
250      */
251     <T extends PfConcept> T getConcept(Class<T> someClass, PfConceptKey conceptId);
252
253     /**
254      * Get a concept from the database with the given reference key.
255      *
256      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
257      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
258      * @param conceptId the concept key of the concept to get
259      * @return the concept that matches the key or null if the concept is not retrieved
260      */
261     <T extends PfConcept> T getConcept(Class<T> someClass, PfReferenceKey conceptId);
262
263     /**
264      * Get the number of instances of a concept that exist in the database.
265      *
266      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
267      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
268      * @return the number of instances of the concept in the database
269      */
270     <T extends PfConcept> long size(Class<T> someClass);
271
272     /**
273      * Update a concept in the database.
274      *
275      * @param <T> the type of the object to update, a subclass of {@link PfConcept}
276      * @param obj the object to update
277      * @return the updated object
278      */
279     <T extends PfConcept> T update(T obj);
280 }