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
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.util.Collection;
25 import java.util.Date;
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.PfTimestampKey;
35 * The Interface PfDao describes the DAO interface for reading and writing Policy Framework {@link PfConcept} concepts
36 * to and from databases using JDBC.
38 public interface PfDao {
41 * Initialize the Policy Framework DAO with the given parameters.
43 * @param daoParameters parameters to use to access the database
44 * @throws PfModelException on initialization errors
46 void init(DaoParameters daoParameters) throws PfModelException;
49 * Close the Policy Framework DAO.
54 * Creates an Policy Framework concept on the database.
56 * @param <T> the type of the object to create, a subclass of {@link PfConcept}
57 * @param obj the object to create
59 <T extends PfConcept> void create(T obj);
62 * Delete an Policy Framework concept on the database.
64 * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
65 * @param obj the object to delete
67 <T extends PfConcept> void delete(T obj);
70 * Delete an Policy Framework concept on the database.
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
76 <T extends PfConcept> void delete(Class<T> someClass, PfConceptKey key);
79 * Delete an Policy Framework concept on the database.
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
85 <T extends PfConcept> void delete(Class<T> someClass, PfReferenceKey key);
88 * Delete an Policy Framework concept on the database.
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
94 <T extends PfConcept> void delete(Class<T> someClass, PfTimestampKey timeStampKey);
97 * Create a collection of objects in the database.
99 * @param <T> the type of the object to create, a subclass of {@link PfConcept}
100 * @param objs the objects to create
102 <T extends PfConcept> void createCollection(Collection<T> objs);
105 * Delete a collection of objects in the database.
107 * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
108 * @param objs the objects to delete
110 <T extends PfConcept> void deleteCollection(Collection<T> objs);
113 * Delete a collection of objects in the database referred to by concept key.
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
120 <T extends PfConcept> int deleteByConceptKey(Class<T> someClass, Collection<PfConceptKey> keys);
123 * Delete a collection of objects in the database referred to by reference key.
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
130 <T extends PfConcept> int deleteByReferenceKey(Class<T> someClass, Collection<PfReferenceKey> keys);
133 * Delete all objects of a given class in the database.
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}
138 <T extends PfConcept> void deleteAll(Class<T> someClass);
141 * Get an object from the database, referred to by concept key.
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
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
151 <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version);
154 * Get an object from the database, referred to by concept key.
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
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
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);
175 * Get an object from the database, referred to by concept key.
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
182 <T extends PfConcept> T get(Class<T> someClass, PfConceptKey key);
185 * Get an object from the database, referred to by reference key.
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
192 <T extends PfConcept> T get(Class<T> someClass, PfReferenceKey key);
195 * Get an object from the database, referred to by reference key.
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
202 <T extends PfConcept> T get(Class<T> someClass, PfTimestampKey timestampKey);
205 * Get all the objects in the database of a given type.
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
211 <T extends PfConcept> List<T> getAll(Class<T> someClass);
214 * Get all the objects in the database of the given type with the given parent concept key.
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
221 <T extends PfConcept> List<T> getAll(Class<T> someClass, PfConceptKey parentKey);
224 * Get all the objects in the database of a given type.
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
231 <T extends PfConcept> List<T> getAllVersions(Class<T> someClass, final String name);
234 * Get all the objects in the database of a given type.
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
241 <T extends PfConcept> List<T> getAllVersionsByParent(Class<T> someClass, final String parentKeyName);
244 * Get a concept from the database with the given concept key.
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
251 <T extends PfConcept> T getConcept(Class<T> someClass, PfConceptKey conceptId);
254 * Get a concept from the database with the given reference key.
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
261 <T extends PfConcept> T getConcept(Class<T> someClass, PfReferenceKey conceptId);
264 * Get the number of instances of a concept that exist in the database.
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
270 <T extends PfConcept> long size(Class<T> someClass);
273 * Update a concept in the database.
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
279 <T extends PfConcept> T update(T obj);