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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.dao;
24 import java.time.Instant;
25 import java.util.Collection;
26 import java.util.List;
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;
36 * The Interface PfDao describes the DAO interface for reading and writing Policy Framework {@link PfConcept} concepts
37 * to and from databases using JDBC.
39 public interface PfDao {
42 * Initialize the Policy Framework DAO with the given parameters.
44 * @param daoParameters parameters to use to access the database
45 * @throws PfModelException on initialization errors
47 void init(DaoParameters daoParameters) throws PfModelException;
50 * Close the Policy Framework DAO.
55 * Creates an Policy Framework concept on the database.
57 * @param <T> the type of the object to create, a subclass of {@link PfConcept}
58 * @param obj the object to create
60 <T extends PfConcept> void create(T obj);
63 * Delete an Policy Framework concept on the database.
65 * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
66 * @param obj the object to delete
68 <T extends PfConcept> void delete(T obj);
71 * Delete an Policy Framework concept on the database.
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
77 <T extends PfConcept> void delete(Class<T> someClass, PfConceptKey key);
80 * Delete an Policy Framework concept on the database.
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
86 <T extends PfConcept> void delete(Class<T> someClass, PfReferenceKey key);
89 * Delete an Policy Framework concept on the database.
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
95 <T extends PfConcept> void delete(Class<T> someClass, PfTimestampKey timeStampKey);
98 * Create a collection of objects in the database.
100 * @param <T> the type of the object to create, a subclass of {@link PfConcept}
101 * @param objs the objects to create
103 <T extends PfConcept> void createCollection(Collection<T> objs);
106 * Delete a collection of objects in the database.
108 * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
109 * @param objs the objects to delete
111 <T extends PfConcept> void deleteCollection(Collection<T> objs);
114 * Delete a collection of objects in the database referred to by concept key.
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
121 <T extends PfConcept> int deleteByConceptKey(Class<T> someClass, Collection<PfConceptKey> keys);
124 * Delete a collection of objects in the database referred to by reference key.
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
131 <T extends PfConcept> int deleteByReferenceKey(Class<T> someClass, Collection<PfReferenceKey> keys);
134 * Delete all objects of a given class in the database.
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}
139 <T extends PfConcept> void deleteAll(Class<T> someClass);
142 * Get an object from the database, referred to by concept key.
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
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
152 <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version);
155 * Get an object from the database, referred to by concept key.
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
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
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);
176 * Get an object from the database, referred to by concept key.
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
183 <T extends PfConcept> T get(Class<T> someClass, PfConceptKey key);
186 * Get an object from the database, referred to by reference key.
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
193 <T extends PfConcept> T get(Class<T> someClass, PfReferenceKey key);
196 * Get an object from the database, referred to by reference key.
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
203 <T extends PfConcept> T get(Class<T> someClass, PfTimestampKey timestampKey);
206 * Get an object from the database, referred to by reference timestamp key.
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
213 <T extends PfConcept> T get(Class<T> someClass, PfReferenceTimestampKey key);
216 * Get all the objects in the database of a given type.
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
222 <T extends PfConcept> List<T> getAll(Class<T> someClass);
225 * Get all the objects in the database of the given type with the given parent concept key.
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
232 <T extends PfConcept> List<T> getAll(Class<T> someClass, PfConceptKey parentKey);
235 * Get all the objects in the database of a given type.
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
242 <T extends PfConcept> List<T> getAllVersions(Class<T> someClass, final String name);
245 * Get all the objects in the database of a given type.
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
252 <T extends PfConcept> List<T> getAllVersionsByParent(Class<T> someClass, final String parentKeyName);
255 * Get a concept from the database with the given concept key.
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
262 <T extends PfConcept> T getConcept(Class<T> someClass, PfConceptKey conceptId);
265 * Get a concept from the database with the given reference key.
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
272 <T extends PfConcept> T getConcept(Class<T> someClass, PfReferenceKey conceptId);
275 * Get the number of instances of a concept that exist in the database.
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
281 <T extends PfConcept> long size(Class<T> someClass);
284 * Update a concept in the database.
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
290 <T extends PfConcept> T update(T obj);