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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.dao;
23 import java.util.Collection;
24 import java.util.Date;
25 import java.util.List;
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;
34 * The Interface PfDao describes the DAO interface for reading and writing Policy Framework {@link PfConcept} concepts
35 * to and from databases using JDBC.
37 public interface PfDao {
40 * Initialize the Policy Framework DAO with the given parameters.
42 * @param daoParameters parameters to use to access the database
43 * @throws PfModelException on initialization errors
45 void init(DaoParameters daoParameters) throws PfModelException;
48 * Close the Policy Framework DAO.
53 * Creates an Policy Framework concept on the database.
55 * @param <T> the type of the object to create, a subclass of {@link PfConcept}
56 * @param obj the object to create
58 <T extends PfConcept> void create(T obj);
61 * Delete an Policy Framework concept on the database.
63 * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
64 * @param obj the object to delete
66 <T extends PfConcept> void delete(T obj);
69 * Delete an Policy Framework concept on the database.
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
75 <T extends PfConcept> void delete(Class<T> someClass, PfConceptKey key);
78 * Delete an Policy Framework concept on the database.
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
84 <T extends PfConcept> void delete(Class<T> someClass, PfReferenceKey key);
87 * Delete an Policy Framework concept on the database.
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
93 <T extends PfConcept> void delete(Class<T> someClass, PfTimestampKey timeStampKey);
96 * Create a collection of objects in the database.
98 * @param <T> the type of the object to create, a subclass of {@link PfConcept}
99 * @param objs the objects to create
101 <T extends PfConcept> void createCollection(Collection<T> objs);
104 * Delete a collection of objects in the database.
106 * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
107 * @param objs the objects to delete
109 <T extends PfConcept> void deleteCollection(Collection<T> objs);
112 * Delete a collection of objects in the database referred to by concept key.
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
119 <T extends PfConcept> int deleteByConceptKey(Class<T> someClass, Collection<PfConceptKey> keys);
122 * Delete a collection of objects in the database referred to by reference key.
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
129 <T extends PfConcept> int deleteByReferenceKey(Class<T> someClass, Collection<PfReferenceKey> keys);
132 * Delete all objects of a given class in the database.
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}
137 <T extends PfConcept> void deleteAll(Class<T> someClass);
140 * Get an object from the database, referred to by concept key.
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
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
150 <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version);
153 * Get an object from the database, referred to by concept key.
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
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
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);
174 * Get an object from the database, referred to by concept key.
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
181 <T extends PfConcept> T get(Class<T> someClass, PfConceptKey key);
184 * Get an object from the database, referred to by reference key.
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
191 <T extends PfConcept> T get(Class<T> someClass, PfReferenceKey key);
194 * Get an object from the database, referred to by reference key.
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
201 <T extends PfConcept> T get(Class<T> someClass, PfTimestampKey timestampKey);
204 * Get all the objects in the database of a given type.
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
210 <T extends PfConcept> List<T> getAll(Class<T> someClass);
213 * Get all the objects in the database of the given type with the given parent concept key.
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
220 <T extends PfConcept> List<T> getAll(Class<T> someClass, PfConceptKey parentKey);
223 * Get all the objects in the database of a given type.
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
230 <T extends PfConcept> List<T> getAllVersions(Class<T> someClass, final String name);
233 * Get a concept from the database with the given concept key.
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
240 <T extends PfConcept> T getConcept(Class<T> someClass, PfConceptKey conceptId);
243 * Get a concept from the database with the given reference key.
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
250 <T extends PfConcept> T getConcept(Class<T> someClass, PfReferenceKey conceptId);
253 * Get the number of instances of a concept that exist in the database.
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
259 <T extends PfConcept> long size(Class<T> someClass);
262 * Update a concept in the database.
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
268 <T extends PfConcept> T update(T obj);