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.List;
26 import org.onap.policy.models.base.PfConcept;
27 import org.onap.policy.models.base.PfConceptKey;
28 import org.onap.policy.models.base.PfModelException;
29 import org.onap.policy.models.base.PfReferenceKey;
32 * The Interface PfDao describes the DAO interface for reading and writing Policy Framework {@link PfConcept} concepts
33 * to and from databases using JDBC.
35 public interface PfDao {
38 * Initialize the Policy Framework DAO with the given parameters.
40 * @param daoParameters parameters to use to access the database
41 * @throws PfModelException on initialization errors
43 void init(DaoParameters daoParameters) throws PfModelException;
46 * Close the Policy Framework DAO.
51 * Creates an Policy Framework concept on the database.
53 * @param <T> the type of the object to create, a subclass of {@link PfConcept}
54 * @param obj the object to create
56 <T extends PfConcept> void create(T obj);
59 * Delete an Policy Framework concept on the database.
61 * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
62 * @param obj the object to delete
64 <T extends PfConcept> void delete(T obj);
67 * Delete an Policy Framework concept on the database.
69 * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
70 * @param someClass the class of the object to delete, a subclass of {@link PfConcept}
71 * @param key the key of the object to delete
73 <T extends PfConcept> void delete(Class<T> someClass, PfConceptKey key);
76 * Delete an Policy Framework concept on the database.
78 * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
79 * @param someClass the class of the object to delete, a subclass of {@link PfConcept}
80 * @param key the key of the object to delete
82 <T extends PfConcept> void delete(Class<T> someClass, PfReferenceKey key);
85 * Create a collection of objects in the database.
87 * @param <T> the type of the object to create, a subclass of {@link PfConcept}
88 * @param objs the objects to create
90 <T extends PfConcept> void createCollection(Collection<T> objs);
93 * Delete a collection of objects in the database.
95 * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
96 * @param objs the objects to delete
98 <T extends PfConcept> void deleteCollection(Collection<T> objs);
101 * Delete a collection of objects in the database referred to by concept key.
103 * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
104 * @param someClass the class of the objects to delete, a subclass of {@link PfConcept}
105 * @param keys the keys of the objects to delete
106 * @return the number of objects deleted
108 <T extends PfConcept> int deleteByConceptKey(Class<T> someClass, Collection<PfConceptKey> keys);
111 * Delete a collection of objects in the database referred to by reference key.
113 * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
114 * @param someClass the class of the objects to delete, a subclass of {@link PfConcept}
115 * @param keys the keys of the objects to delete
116 * @return the number of objects deleted
118 <T extends PfConcept> int deleteByReferenceKey(Class<T> someClass, Collection<PfReferenceKey> keys);
121 * Delete all objects of a given class in the database.
123 * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
124 * @param someClass the class of the objects to delete, a subclass of {@link PfConcept}
126 <T extends PfConcept> void deleteAll(Class<T> someClass);
129 * Get an object from the database, referred to by concept key.
131 * @param <T> the type of the object to get, a subclass of {@link PfConcept}
132 * @param someClass the class of the object to get, a subclass of {@link PfConcept}, if name is null, all concepts
133 * of type T are returned, if name is not null and version is null, all versions of that concept matching the
135 * @param name the name of the object to get, null returns all objects
136 * @param version the version the object to get, null returns all objects for a specified name
137 * @return the objects that was retrieved from the database
139 <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version);
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}
146 * @param key the key of the object to get
147 * @return the object that was retrieved from the database
149 <T extends PfConcept> T get(Class<T> someClass, PfConceptKey key);
152 * Get an object from the database, referred to by reference key.
154 * @param <T> the type of the object to get, a subclass of {@link PfConcept}
155 * @param someClass the class of the object to get, a subclass of {@link PfConcept}
156 * @param key the key of the object to get
157 * @return the object that was retrieved from the database or null if the object was not retrieved
159 <T extends PfConcept> T get(Class<T> someClass, PfReferenceKey key);
162 * Get all the objects in the database of a given type.
164 * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
165 * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
166 * @return the objects or null if no objects were retrieved
168 <T extends PfConcept> List<T> getAll(Class<T> someClass);
171 * Get all the objects in the database of the given type with the given parent concept key.
173 * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
174 * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
175 * @param parentKey the parent key of the concepts to get
178 <T extends PfConcept> List<T> getAll(Class<T> someClass, PfConceptKey parentKey);
181 * Get all the objects in the database of a given type.
183 * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
184 * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
185 * @param name the name of the concepts for which to get all versions
186 * @return the objects or null if no objects were retrieved
188 <T extends PfConcept> List<T> getAllVersions(Class<T> someClass, final String name);
191 * Get a concept from the database with the given concept key.
193 * @param <T> the type of the object to get, a subclass of {@link PfConcept}
194 * @param someClass the class of the object to get, a subclass of {@link PfConcept}
195 * @param conceptId the concept key of the concept to get
196 * @return the concept that matches the key or null if the concept is not retrieved
198 <T extends PfConcept> T getConcept(Class<T> someClass, PfConceptKey conceptId);
201 * Get a concept from the database with the given reference key.
203 * @param <T> the type of the object to get, a subclass of {@link PfConcept}
204 * @param someClass the class of the object to get, a subclass of {@link PfConcept}
205 * @param conceptId the concept key of the concept to get
206 * @return the concept that matches the key or null if the concept is not retrieved
208 <T extends PfConcept> T getConcept(Class<T> someClass, PfReferenceKey conceptId);
211 * Get the number of instances of a concept that exist in the database.
213 * @param <T> the type of the object to get, a subclass of {@link PfConcept}
214 * @param someClass the class of the object to get, a subclass of {@link PfConcept}
215 * @return the number of instances of the concept in the database
217 <T extends PfConcept> long size(Class<T> someClass);
220 * Update a concept in the database.
222 * @param <T> the type of the object to update, a subclass of {@link PfConcept}
223 * @param obj the object to update
224 * @return the updated object
226 <T extends PfConcept> T update(T obj);