Merge "Add filter obejcts for concepts"
[policy/models.git] / models-dao / src / main / java / org / onap / policy / models / dao / PfDao.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.dao;
22
23 import java.util.Collection;
24 import java.util.List;
25
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;
30
31 /**
32  * The Interface PfDao describes the DAO interface for reading and writing Policy Framework {@link PfConcept} concepts
33  * to and from databases using JDBC.
34  */
35 public interface PfDao {
36
37     /**
38      * Initialize the Policy Framework DAO with the given parameters.
39      *
40      * @param daoParameters parameters to use to access the database
41      * @throws PfModelException on initialization errors
42      */
43     void init(DaoParameters daoParameters) throws PfModelException;
44
45     /**
46      * Close the Policy Framework DAO.
47      */
48     void close();
49
50     /**
51      * Creates an Policy Framework concept on the database.
52      *
53      * @param <T> the type of the object to create, a subclass of {@link PfConcept}
54      * @param obj the object to create
55      */
56     <T extends PfConcept> void create(T obj);
57
58     /**
59      * Delete an Policy Framework concept on the database.
60      *
61      * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
62      * @param obj the object to delete
63      */
64     <T extends PfConcept> void delete(T obj);
65
66     /**
67      * Delete an Policy Framework concept on the database.
68      *
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
72      */
73     <T extends PfConcept> void delete(Class<T> someClass, PfConceptKey key);
74
75     /**
76      * Delete an Policy Framework concept on the database.
77      *
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
81      */
82     <T extends PfConcept> void delete(Class<T> someClass, PfReferenceKey key);
83
84     /**
85      * Create a collection of objects in the database.
86      *
87      * @param <T> the type of the object to create, a subclass of {@link PfConcept}
88      * @param objs the objects to create
89      */
90     <T extends PfConcept> void createCollection(Collection<T> objs);
91
92     /**
93      * Delete a collection of objects in the database.
94      *
95      * @param <T> the type of the objects to delete, a subclass of {@link PfConcept}
96      * @param objs the objects to delete
97      */
98     <T extends PfConcept> void deleteCollection(Collection<T> objs);
99
100     /**
101      * Delete a collection of objects in the database referred to by concept key.
102      *
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
107      */
108     <T extends PfConcept> int deleteByConceptKey(Class<T> someClass, Collection<PfConceptKey> keys);
109
110     /**
111      * Delete a collection of objects in the database referred to by reference key.
112      *
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
117      */
118     <T extends PfConcept> int deleteByReferenceKey(Class<T> someClass, Collection<PfReferenceKey> keys);
119
120     /**
121      * Delete all objects of a given class in the database.
122      *
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}
125      */
126     <T extends PfConcept> void deleteAll(Class<T> someClass);
127
128     /**
129      * Get an object from the database, referred to by concept key.
130      *
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
134      *        name are returned.
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
138      */
139     <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version);
140
141     /**
142      * Get an object from the database, referred to by concept key.
143      *
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
148      */
149     <T extends PfConcept> T get(Class<T> someClass, PfConceptKey key);
150
151     /**
152      * Get an object from the database, referred to by reference key.
153      *
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
158      */
159     <T extends PfConcept> T get(Class<T> someClass, PfReferenceKey key);
160
161     /**
162      * Get all the objects in the database of a given type.
163      *
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
167      */
168     <T extends PfConcept> List<T> getAll(Class<T> someClass);
169
170     /**
171      * Get all the objects in the database of the given type with the given parent concept key.
172      *
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
176      * @return the all
177      */
178     <T extends PfConcept> List<T> getAll(Class<T> someClass, PfConceptKey parentKey);
179
180     /**
181      * Get all the objects in the database of a given type.
182      *
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
187      */
188     <T extends PfConcept> List<T> getAllVersions(Class<T> someClass, final String name);
189
190     /**
191      * Get a concept from the database with the given concept key.
192      *
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
197      */
198     <T extends PfConcept> T getConcept(Class<T> someClass, PfConceptKey conceptId);
199
200     /**
201      * Get a concept from the database with the given reference key.
202      *
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
207      */
208     <T extends PfConcept> T getConcept(Class<T> someClass, PfReferenceKey conceptId);
209
210     /**
211      * Get the number of instances of a concept that exist in the database.
212      *
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
216      */
217     <T extends PfConcept> long size(Class<T> someClass);
218
219     /**
220      * Update a concept in the database.
221      *
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
225      */
226     <T extends PfConcept> T update(T obj);
227 }