update Db provider to support query number
[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  * ================================================================================
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      * @param filterMap Map store extra key/value used to filter from database, can be null.
166      * @param sortOrder sortOrder to query database
167      * @param getRecordNum Total query count from database
168      * @return the objects that was retrieved from the database
169      */
170     <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version, Date startTime,
171             Date endTime, Map<String, Object> filterMap, String sortOrder, int getRecordNum);
172
173     /**
174      * Get an object from the database, referred to by concept key.
175      *
176      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
177      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
178      * @param key the PfConceptKey of the object to get
179      * @return the object that was retrieved from the database
180      */
181     <T extends PfConcept> T get(Class<T> someClass, PfConceptKey key);
182
183     /**
184      * Get an object from the database, referred to by reference key.
185      *
186      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
187      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
188      * @param key the PfReferenceKey of the object to get
189      * @return the object that was retrieved from the database or null if the object was not retrieved
190      */
191     <T extends PfConcept> T get(Class<T> someClass, PfReferenceKey key);
192
193     /**
194      * Get an object from the database, referred to by reference key.
195      *
196      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
197      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
198      * @param timestampKey the PfTimestampKey of the object to get
199      * @return the object that was retrieved from the database or null if the object was not retrieved
200      */
201     <T extends PfConcept> T get(Class<T> someClass, PfTimestampKey timestampKey);
202
203     /**
204      * Get all the objects in the database of a given type.
205      *
206      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
207      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
208      * @return the objects or null if no objects were retrieved
209      */
210     <T extends PfConcept> List<T> getAll(Class<T> someClass);
211
212     /**
213      * Get all the objects in the database of the given type with the given parent concept key.
214      *
215      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
216      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
217      * @param parentKey the parent key of the concepts to get
218      * @return the all
219      */
220     <T extends PfConcept> List<T> getAll(Class<T> someClass, PfConceptKey parentKey);
221
222     /**
223      * Get all the objects in the database of a given type.
224      *
225      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
226      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
227      * @param name the name of the concepts for which to get all versions
228      * @return the objects or null if no objects were retrieved
229      */
230     <T extends PfConcept> List<T> getAllVersions(Class<T> someClass, final String name);
231
232     /**
233      * Get a concept from the database with the given concept key.
234      *
235      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
236      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
237      * @param conceptId the concept key of the concept to get
238      * @return the concept that matches the key or null if the concept is not retrieved
239      */
240     <T extends PfConcept> T getConcept(Class<T> someClass, PfConceptKey conceptId);
241
242     /**
243      * Get a concept from the database with the given reference key.
244      *
245      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
246      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
247      * @param conceptId the concept key of the concept to get
248      * @return the concept that matches the key or null if the concept is not retrieved
249      */
250     <T extends PfConcept> T getConcept(Class<T> someClass, PfReferenceKey conceptId);
251
252     /**
253      * Get the number of instances of a concept that exist in the database.
254      *
255      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
256      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
257      * @return the number of instances of the concept in the database
258      */
259     <T extends PfConcept> long size(Class<T> someClass);
260
261     /**
262      * Update a concept in the database.
263      *
264      * @param <T> the type of the object to update, a subclass of {@link PfConcept}
265      * @param obj the object to update
266      * @return the updated object
267      */
268     <T extends PfConcept> T update(T obj);
269 }