2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2021, 2023 Nordix Foundation.
4 * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
5 * Modifications Copyright (C) 2020, 2022 Bell Canada. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.models.provider.impl;
25 import jakarta.ws.rs.core.Response;
27 import lombok.NonNull;
28 import org.onap.policy.models.base.PfModelException;
29 import org.onap.policy.models.dao.PfDao;
30 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 * This class provides an implementation of the Policy Models Provider for the ONAP Policy Framework that works towards
36 * a relational database.
38 * @author Liam Fallon (liam.fallon@est.tech)
40 public class DatabasePolicyModelsProviderImpl extends AbstractPolicyModelsProvider {
42 private static final Logger LOGGER = LoggerFactory.getLogger(DatabasePolicyModelsProviderImpl.class);
44 private final PolicyModelsProviderParameters parameters;
46 // Database connection and the DAO for reading and writing Policy Framework concepts
51 * Constructor that takes the parameters.
53 * @param parameters the parameters for the provider
55 public DatabasePolicyModelsProviderImpl(@NonNull final PolicyModelsProviderParameters parameters) {
56 this.parameters = parameters;
60 public synchronized void init() throws PfModelException {
61 LOGGER.debug("opening the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(),
62 parameters.getPersistenceUnit());
65 var errorMessage = "provider is already initialized";
66 throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errorMessage);
69 pfDao = ModelsProvider.init(parameters);
73 public synchronized void close() throws PfModelException {
74 LOGGER.debug("closing the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(),
75 parameters.getPersistenceUnit());
82 LOGGER.debug("closed the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(),
83 parameters.getPersistenceUnit());