Skip to content

Package: KapuaDatabaseCheckUpdate

KapuaDatabaseCheckUpdate

nameinstructionbranchcomplexitylinemethod
KapuaDatabaseCheckUpdate()
M: 59 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2018, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.broker.core;
14:
15: import com.google.common.base.MoreObjects;
16: import org.eclipse.kapua.commons.jpa.JdbcConnectionUrlResolvers;
17: import org.eclipse.kapua.commons.liquibase.KapuaLiquibaseClient;
18: import org.eclipse.kapua.commons.setting.system.SystemSetting;
19: import org.eclipse.kapua.commons.setting.system.SystemSettingKey;
20: import org.slf4j.Logger;
21: import org.slf4j.LoggerFactory;
22:
23: /**
24: * Call Liquibase database schema check and update (if enabled)
25: */
26: public class KapuaDatabaseCheckUpdate {
27:
28: private static final Logger logger = LoggerFactory.getLogger(KapuaDatabaseCheckUpdate.class);
29:
30: public KapuaDatabaseCheckUpdate() {
31: logger.info("Kapua database schema check and update...");
32: try {
33: SystemSetting config = SystemSetting.getInstance();
34:• if (config.getBoolean(SystemSettingKey.DB_SCHEMA_UPDATE, false)) {
35: logger.debug("Starting Liquibase embedded client.");
36: String dbUsername = config.getString(SystemSettingKey.DB_USERNAME);
37: String dbPassword = config.getString(SystemSettingKey.DB_PASSWORD);
38: String schema = MoreObjects.firstNonNull(config.getString(SystemSettingKey.DB_SCHEMA_ENV), config.getString(SystemSettingKey.DB_SCHEMA));
39:
40: new KapuaLiquibaseClient(JdbcConnectionUrlResolvers.resolveJdbcUrl(), dbUsername, dbPassword, schema).update();
41: logger.info("Kapua database schema check and update... DONE");
42: } else {
43: logger.info("Kapua database schema check and update... skipping (not enabled by configuration) DONE");
44: }
45: } catch (Exception e) {
46: logger.error("Error in plugin installation.", e);
47: throw new SecurityException(e);
48: }
49: }
50:
51: }