Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ adventure-text-minimessage = "4.26.1"
item-nbt-api = "2.16.0"

# Utilities / Libraries
sarah = "1.25"
sarah = "1.26"
currenciesapi = "1.0.15"
folialib = "0.5.1"
xseries = "13.8.0"
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/fr/maxlego08/menu/storage/ZStorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,18 @@ public void loadDatabase() {
}

Logger logger = JULogger.from(this.plugin.getLogger());
DatabaseType databaseType = storageType.equalsIgnoreCase("SQLITE") ? DatabaseType.SQLITE : storageType.equalsIgnoreCase("MYSQL") ? DatabaseType.MYSQL : DatabaseType.MARIADB;
DatabaseConfiguration databaseConfiguration = new DatabaseConfiguration(prefix, user, password, port, host, dataBase, enableDebug, databaseType);
Long maxLifetimeMillis = globalDatabaseConfiguration.getMaxLifetimeMillis();
if (maxLifetimeMillis != null) {
databaseConfiguration = databaseConfiguration.withMaxLifetime(maxLifetimeMillis);
}

DatabaseConnection databaseConnection;
if (storageType.equalsIgnoreCase("SQLITE")) {
databaseConnection = new SqliteConnection(new DatabaseConfiguration(prefix, user, password, port, host, dataBase, enableDebug, DatabaseType.SQLITE), this.plugin.getDataFolder(), logger);
databaseConnection = new SqliteConnection(databaseConfiguration, this.plugin.getDataFolder(), logger);
} else {
databaseConnection = new HikariDatabaseConnection(new DatabaseConfiguration(prefix, user, password, port, host, dataBase, enableDebug, storageType.equalsIgnoreCase("MYSQL") ? DatabaseType.MYSQL : DatabaseType.MARIADB), logger);
databaseConnection = new HikariDatabaseConnection(databaseConfiguration, logger);
}

this.requestHelper = new RequestHelper(databaseConnection, logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.util.concurrent.TimeUnit;

public class GlobalDatabaseConfiguration {

Expand Down Expand Up @@ -102,4 +103,18 @@ public String getTablePrefix() {
public boolean isDebug() {
return this.globalConfiguration == null ? this.pluginConfiguration.getBoolean("database-configuration.debug") : this.globalConfiguration.getBoolean("database-configuration.debug", this.pluginConfiguration.getBoolean("database-configuration.debug", false));
}

/**
* Maximum pooled-connection lifetime, in milliseconds, for MySQL and MariaDB.
* A missing or negative value keeps Sarah's default of 30 minutes. {@code 0} disables retirement.
*
* @return the lifetime in milliseconds, or {@code null} to keep the library default
*/
public Long getMaxLifetimeMillis() {
long seconds = this.globalConfiguration == null ? this.pluginConfiguration.getLong("database-configuration.max-lifetime", -1L) : this.globalConfiguration.getLong("database-configuration.max-lifetime", this.pluginConfiguration.getLong("database-configuration.max-lifetime", -1L));
if (seconds < 0) {
return null;
}
return TimeUnit.SECONDS.toMillis(seconds);
}
}
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ database-configuration:
database: zmenu
# Enable of not the SQL debug mode
debug: false
# Maximum lifetime of a pooled MySQL or MariaDB connection, in seconds.
# A connection older than this is retired and replaced. 0 keeps connections until the pool closes.
# Hikari requires at least 30 seconds. 1800 is 30 minutes, the same default used when this option is omitted.
max-lifetime: 1800

# Time in seconds for saving data in batches.
# Instead of making an SQL query for each update, a single query will be executed every 10 seconds
Expand Down
Loading