Add DAO module for Models
[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
33  * {@link PfConcept} concepts 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}
133      * @param key the key of the object to get
134      * @return the object that was retrieved from the database
135      */
136     <T extends PfConcept> T get(Class<T> someClass, PfConceptKey key);
137
138     /**
139      * Get an object from the database, referred to by reference key.
140      *
141      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
142      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
143      * @param key the key of the object to get
144      * @return the object that was retrieved from the database or null if the object was not
145      *         retrieved
146      */
147     <T extends PfConcept> T get(Class<T> someClass, PfReferenceKey key);
148
149     /**
150      * Get all the objects in the database of a given type.
151      *
152      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
153      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
154      * @return the objects or null if no objects were retrieved
155      */
156     <T extends PfConcept> List<T> getAll(Class<T> someClass);
157
158     /**
159      * Get all the objects in the database of the given type with the given parent concept key.
160      *
161      * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
162      * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
163      * @param parentKey the parent key of the concepts to get
164      * @return the all
165      */
166     <T extends PfConcept> List<T> getAll(Class<T> someClass, PfConceptKey parentKey);
167
168     /**
169      * Get a concept from the database with the given concept key.
170      *
171      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
172      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
173      * @param conceptId the concept key of the concept to get
174      * @return the concept that matches the key or null if the concept is not retrieved
175      */
176     <T extends PfConcept> T getConcept(Class<T> someClass, PfConceptKey conceptId);
177
178     /**
179      * Get a concept from the database with the given reference key.
180      *
181      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
182      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
183      * @param conceptId the concept key of the concept to get
184      * @return the concept that matches the key or null if the concept is not retrieved
185      */
186     <T extends PfConcept> T getConcept(Class<T> someClass, PfReferenceKey conceptId);
187
188     /**
189      * Get the number of instances of a concept that exist in the database.
190      *
191      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
192      * @param someClass the class of the object to get, a subclass of {@link PfConcept}
193      * @return the number of instances of the concept in the database
194      */
195     <T extends PfConcept> long size(Class<T> someClass);
196
197     /**
198      * Update a concept in the database.
199      *
200      * @param <T> the type of the object to get, a subclass of {@link PfConcept}
201      * @param obj the object to update
202      * @return the updated object
203      */
204     <T extends PfConcept> T update(T obj);
205 }