-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'backport-3355' into release-1.7.x
- Loading branch information
Showing
9 changed files
with
194 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
commons/src/main/java/org/eclipse/kapua/commons/jpa/DataSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.kapua.commons.jpa; | ||
|
||
import com.zaxxer.hikari.HikariDataSource; | ||
import org.eclipse.kapua.commons.setting.system.SystemSetting; | ||
import org.eclipse.kapua.commons.setting.system.SystemSettingKey; | ||
|
||
public final class DataSource { | ||
|
||
private static HikariDataSource hikariDataSource; | ||
|
||
private DataSource() { | ||
} | ||
|
||
public static HikariDataSource getDataSource() { | ||
if (hikariDataSource == null) { | ||
SystemSetting config = SystemSetting.getInstance(); | ||
|
||
hikariDataSource = new HikariDataSource(); | ||
hikariDataSource.setDriverClassName(config.getString(SystemSettingKey.DB_JDBC_DRIVER)); | ||
hikariDataSource.setJdbcUrl(JdbcConnectionUrlResolvers.resolveJdbcUrl()); | ||
hikariDataSource.setUsername(config.getString(SystemSettingKey.DB_USERNAME)); | ||
hikariDataSource.setPassword(config.getString(SystemSettingKey.DB_PASSWORD)); | ||
|
||
hikariDataSource.setMaximumPoolSize(config.getInt(SystemSettingKey.DB_POOL_SIZE_MAX, 20)); | ||
hikariDataSource.setMinimumIdle(config.getInt(SystemSettingKey.DB_POOL_SIZE_MIN, 1)); | ||
hikariDataSource.setIdleTimeout(config.getInt(SystemSettingKey.DB_POOL_IDLE_TIMEOUT, 180000)); | ||
hikariDataSource.setKeepaliveTime(config.getInt(SystemSettingKey.DB_POOL_KEEPALIVE_TIME, 30000)); | ||
hikariDataSource.setMaxLifetime(config.getInt(SystemSettingKey.DB_POOL_MAX_LIFETIME, 1800000)); | ||
hikariDataSource.setConnectionTestQuery(config.getString(SystemSettingKey.DB_POOL_TEST_QUERY, "SELECT 1")); | ||
|
||
hikariDataSource.setLeakDetectionThreshold(config.getInt(SystemSettingKey.DB_POOL_LEAKDETECTION_THRESHOLD, 0)); | ||
} | ||
|
||
return hikariDataSource; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return hikariDataSource.getDriverClassName() + "@" + hikariDataSource.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.