2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.persistence.jpa.internal;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * The configuration required for Jpa binding.
23 * @author Manfred Bergmann - Initial contribution
24 * @author Kai Kreuzer - migrated to 3.x
27 public class JpaConfiguration {
28 private final Logger logger = LoggerFactory.getLogger(JpaConfiguration.class);
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";
36 public static boolean isInitialized = false;
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;
44 public JpaConfiguration(final Map<String, Object> properties) {
45 logger.debug("Update config...");
47 String param = (String) properties.get(CFG_CONNECTION_URL);
48 logger.debug("url: {}", param);
50 logger.warn("Connection url is required in jpa.cfg!");
51 } else if (param.isBlank()) {
52 logger.warn("Empty connection url in jpa.cfg!");
54 dbConnectionUrl = param;
56 param = (String) properties.get(CFG_DRIVER_CLASS);
57 logger.debug("driver: {}", param);
59 logger.warn("Driver class is required in jpa.cfg!");
60 } else if (param.isBlank()) {
61 logger.warn("Empty driver class in jpa.cfg!");
63 dbDriverClass = param;
65 if (properties.get(CFG_USERNAME) == null) {
66 logger.info("{} was not specified!", CFG_USERNAME);
68 dbUserName = (String) properties.get(CFG_USERNAME);
70 if (properties.get(CFG_PASSWORD) == null) {
71 logger.info("{} was not specified!", CFG_PASSWORD);
73 dbPassword = (String) properties.get(CFG_PASSWORD);
75 if (properties.get(CFG_SYNCMAPPING) == null) {
76 logger.debug("{} was not specified!", CFG_SYNCMAPPING);
78 dbSyncMapping = (String) properties.get(CFG_SYNCMAPPING);
81 logger.debug("Update config... done");