Skip to content

Commit

Permalink
Fixed #5 for real this time
Browse files Browse the repository at this point in the history
  • Loading branch information
BrainStone committed Apr 24, 2017
1 parent 9a63a42 commit d28330d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/main/java/world/jnc/invsync/DataSource.java
Expand Up @@ -82,6 +82,10 @@ public DataSource() throws SQLException {
}

public void saveInventory(Player player, PlayerData data) {
if (!connection.verifyConnection()) {
prepareStatements();
}

String playerName = getPlayerString(player);

try {
Expand All @@ -101,6 +105,10 @@ public void saveInventory(Player player, PlayerData data) {
}

public Optional<PlayerData> loadInventory(Player player) {
if (!connection.verifyConnection()) {
prepareStatements();
}

String playerName = getPlayerString(player);

try {
Expand Down Expand Up @@ -131,6 +139,10 @@ public Optional<PlayerData> loadInventory(Player player) {
}

public void setActive(Player player) {
if (!connection.verifyConnection()) {
prepareStatements();
}

String playerName = getPlayerString(player);

try {
Expand All @@ -146,6 +158,10 @@ public void setActive(Player player) {
}

public boolean isActive(Player player) {
if (!connection.verifyConnection()) {
prepareStatements();
}

try {
isActive.setBytes(1, getBytesFromUUID(player.getUniqueId()));

Expand Down
Expand Up @@ -30,7 +30,7 @@ protected static DataSource getDataSource(String jdbcUrl) throws SQLException {

return sql.getDataSource(jdbcUrl);
}

protected DatabaseConnection(String connectionURL) throws SQLException {
connect(connectionURL);
}
Expand Down Expand Up @@ -59,10 +59,18 @@ public boolean isConnectionActive() {
}
}

public void verifyConnection() throws SQLException {
public boolean verifyConnection() {
if (!isConnectionActive()) {
reconnect();
try {
reconnect();
} catch (SQLException e) {
InventorySync.getLogger().error("Reconnecting failed!", e);
}

return false;
}

return true;
}

public Statement getStatement() throws SQLException {
Expand Down

0 comments on commit d28330d

Please sign in to comment.