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
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 * @filterMap Map store extra key/value used to filter from database, can be null.
166 * @return the objects that was retrieved from the database
168 <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version, Date startTime,
169 Date endTime, Map<String, Object> filterMap);
172 * Get an object from the database, referred to by concept key.
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
179 <T extends PfConcept> T get(Class<T> someClass, PfConceptKey key);
182 * Get an object from the database, referred to by reference key.
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
189 <T extends PfConcept> T get(Class<T> someClass, PfReferenceKey key);
192 * Get an object from the database, referred to by reference key.
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
199 <T extends PfConcept> T get(Class<T> someClass, PfTimestampKey timestampKey);
202 * Get all the objects in the database of a given type.
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
208 <T extends PfConcept> List<T> getAll(Class<T> someClass);
211 * Get all the objects in the database of the given type with the given parent concept key.
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
218 <T extends PfConcept> List<T> getAll(Class<T> someClass, PfConceptKey parentKey);
221 * Get all the objects in the database of a given type.
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
228 <T extends PfConcept> List<T> getAllVersions(Class<T> someClass, final String name);
231 * Get a concept from the database with the given concept key.
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
238 <T extends PfConcept> T getConcept(Class<T> someClass, PfConceptKey conceptId);
241 * Get a concept from the database with the given reference key.
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
248 <T extends PfConcept> T getConcept(Class<T> someClass, PfReferenceKey conceptId);
251 * Get the number of instances of a concept that exist in the database.
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
257 <T extends PfConcept> long size(Class<T> someClass);
260 * Update a concept in the database.
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
266 <T extends PfConcept> T update(T obj);