2 * Copyright (c) 2010-2023 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.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * The configuration required for Jpa binding.
25 * @author Manfred Bergmann - Initial contribution
26 * @author Kai Kreuzer - migrated to 3.x
30 public class JpaConfiguration {
31 private final Logger logger = LoggerFactory.getLogger(JpaConfiguration.class);
33 private static final String CFG_CONNECTION_URL = "url";
34 private static final String CFG_DRIVER_CLASS = "driver";
35 private static final String CFG_USERNAME = "user";
36 private static final String CFG_PASSWORD = "password";
37 private static final String CFG_SYNCMAPPING = "syncmappings";
39 public final String dbConnectionUrl;
40 public final String dbDriverClass;
41 public final String dbUserName;
42 public final String dbPassword;
43 public final String dbSyncMapping;
45 public JpaConfiguration(final Map<String, @Nullable Object> properties) throws IllegalArgumentException {
46 logger.debug("Creating JPA config...");
48 String param = (String) properties.get(CFG_CONNECTION_URL);
49 logger.debug("url: {}", param);
51 throw new IllegalArgumentException("Connection URL is required in JPA configuration!");
52 } else if (param.isBlank()) {
53 throw new IllegalArgumentException("Empty connection URL in JPA configuration!");
55 dbConnectionUrl = param;
57 param = (String) properties.get(CFG_DRIVER_CLASS);
58 logger.debug("driver: {}", param);
60 throw new IllegalArgumentException("Driver class is required in JPA configuration!");
61 } else if (param.isBlank()) {
62 throw new IllegalArgumentException("Empty driver class in JPA configuration!");
64 dbDriverClass = param;
66 param = (String) properties.get(CFG_USERNAME);
68 logger.info("{} was not specified in JPA configuration!", CFG_USERNAME);
70 dbUserName = param == null ? "" : param;
72 param = (String) properties.get(CFG_PASSWORD);
74 logger.info("{} was not specified in JPA configuration!", CFG_PASSWORD);
76 dbPassword = param == null ? "" : param;
78 param = (String) properties.get(CFG_SYNCMAPPING);
80 logger.debug("{} was not specified in JPA configuration!", CFG_SYNCMAPPING);
82 dbSyncMapping = param == null ? "" : param;
84 logger.debug("Creating JPA config... done");