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