]> git.basschouten.com Git - openhab-addons.git/blob
582c46f122cc12922d3b3b87bf9f07ad0c7bdcbd
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.persistence.jpa.internal;
14
15 import java.util.Map;
16
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * The configuration required for Jpa binding.
22  *
23  * @author Manfred Bergmann - Initial contribution
24  * @author Kai Kreuzer - migrated to 3.x
25  *
26  */
27 public class JpaConfiguration {
28     private final Logger logger = LoggerFactory.getLogger(JpaConfiguration.class);
29
30     private static final String CFG_CONNECTION_URL = "url";
31     private static final String CFG_DRIVER_CLASS = "driver";
32     private static final String CFG_USERNAME = "user";
33     private static final String CFG_PASSWORD = "password";
34     private static final String CFG_SYNCMAPPING = "syncmappings";
35
36     public static boolean isInitialized = false;
37
38     public final String dbConnectionUrl;
39     public final String dbDriverClass;
40     public final String dbUserName;
41     public final String dbPassword;
42     public final String dbSyncMapping;
43
44     public JpaConfiguration(final Map<String, Object> properties) {
45         logger.debug("Update config...");
46
47         String param = (String) properties.get(CFG_CONNECTION_URL);
48         logger.debug("url: {}", param);
49         if (param == null) {
50             logger.warn("Connection url is required in jpa.cfg!");
51         } else if (param.isBlank()) {
52             logger.warn("Empty connection url in jpa.cfg!");
53         }
54         dbConnectionUrl = param;
55
56         param = (String) properties.get(CFG_DRIVER_CLASS);
57         logger.debug("driver: {}", param);
58         if (param == null) {
59             logger.warn("Driver class is required in jpa.cfg!");
60         } else if (param.isBlank()) {
61             logger.warn("Empty driver class in jpa.cfg!");
62         }
63         dbDriverClass = param;
64
65         if (properties.get(CFG_USERNAME) == null) {
66             logger.info("{} was not specified!", CFG_USERNAME);
67         }
68         dbUserName = (String) properties.get(CFG_USERNAME);
69
70         if (properties.get(CFG_PASSWORD) == null) {
71             logger.info("{} was not specified!", CFG_PASSWORD);
72         }
73         dbPassword = (String) properties.get(CFG_PASSWORD);
74
75         if (properties.get(CFG_SYNCMAPPING) == null) {
76             logger.debug("{} was not specified!", CFG_SYNCMAPPING);
77         }
78         dbSyncMapping = (String) properties.get(CFG_SYNCMAPPING);
79
80         isInitialized = true;
81         logger.debug("Update config... done");
82     }
83 }