From 825839d8533417944c4aa0aa1c32d4bfb4b442a6 Mon Sep 17 00:00:00 2001 From: cnr Date: Wed, 1 Jun 2016 00:38:29 -0500 Subject: [PATCH] Fix PlayerKeyValueRepository's exception and return types --- .../database/PlayerKeyValueRepository.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/PlayerKeyValueRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/database/PlayerKeyValueRepository.java index 9325679ae..3ea3adda9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/PlayerKeyValueRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/PlayerKeyValueRepository.java @@ -4,11 +4,15 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import mineplex.serverdata.database.DBPool; -import java.sql.*; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; /** * A SQL-backed repository supporting {@link String} keys and @@ -110,7 +114,7 @@ public class PlayerKeyValueRepository } catch (SQLException e) { - throw new RuntimeException(e); + throw new CompletionException(e); } }); } @@ -141,7 +145,7 @@ public class PlayerKeyValueRepository } catch (SQLException e) { - throw new RuntimeException(e); + throw new CompletionException(e); } }); } @@ -155,7 +159,7 @@ public class PlayerKeyValueRepository * @return a {@link CompletableFuture} whose value indicates * success or failure */ - public CompletableFuture put(UUID uuid, String key, V value) + public CompletableFuture put(UUID uuid, String key, V value) { return CompletableFuture.supplyAsync(() -> { @@ -166,12 +170,12 @@ public class PlayerKeyValueRepository _mapper._serializer.write(stmt, 2, value); stmt.setString(3, uuid.toString()); stmt.executeUpdate(); - return true; + return null; } catch (SQLException e) { - throw new RuntimeException(e); + throw new CompletionException(e); } }); } @@ -206,7 +210,7 @@ public class PlayerKeyValueRepository } catch (SQLException e) { - throw new RuntimeException(e); + throw new CompletionException(e); } }); } @@ -219,7 +223,7 @@ public class PlayerKeyValueRepository * @return a {@link CompletableFuture} whose value indicates * success or failure */ - public CompletableFuture remove(UUID uuid, String key) + public CompletableFuture remove(UUID uuid, String key) { return CompletableFuture.supplyAsync(() -> { @@ -229,12 +233,12 @@ public class PlayerKeyValueRepository stmt.setString(1, uuid.toString()); stmt.setString(2, key); stmt.executeUpdate(); - return true; + return null; } catch (SQLException e) { - throw new RuntimeException(e); + throw new CompletionException(e); } }); } @@ -246,7 +250,7 @@ public class PlayerKeyValueRepository * @return a {@link CompletableFuture} whose value indicates * success or failure */ - public CompletableFuture removeAll(UUID uuid) + public CompletableFuture removeAll(UUID uuid) { return CompletableFuture.supplyAsync(() -> { @@ -255,12 +259,12 @@ public class PlayerKeyValueRepository PreparedStatement stmt = conn.prepareStatement("DELETE FROM " + _tableName + " WHERE accountId=(SELECT id FROM accounts WHERE uuid=?)"); stmt.setString(1, uuid.toString()); stmt.executeUpdate(); - return true; + return null; } catch (SQLException e) { - throw new RuntimeException(e); + throw new CompletionException(e); } }); }