From dffd759c05e60332a3981ad3f406d36e0f11c941 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Wed, 30 May 2018 12:54:37 +0300 Subject: [PATCH] Attempt to fix closed datasource issue on Sponge --- .../database/databases/sql/SpongeMySQLDB.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SpongeMySQLDB.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SpongeMySQLDB.java index a066005ca..f1fcb6b4d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SpongeMySQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SpongeMySQLDB.java @@ -6,6 +6,7 @@ import com.djrapitops.plugin.api.utility.log.Log; import org.spongepowered.api.Sponge; import org.spongepowered.api.service.sql.SqlService; +import java.sql.Connection; import java.sql.SQLException; import java.util.Optional; @@ -44,4 +45,21 @@ public class SpongeMySQLDB extends MySQLDB { } } + @Override + public Connection getConnection() throws SQLException { + try { + return super.getConnection(); + } catch (SQLException e) { + if (e.getMessage().contains("has been closed")) { + try { + setupDataSource(); + } catch (DBInitException setupException) { + throw new IllegalStateException("Failed to set up a new datasource after connection failure.", setupException); + } + return super.getConnection(); + } else { + throw e; + } + } + } } \ No newline at end of file