Allow PlayerKeyValueRepository Exceptions to propagate

This commit is contained in:
cnr 2016-05-25 10:08:07 -05:00
parent 857cf6ad30
commit 5331e2bec9
2 changed files with 47 additions and 20 deletions

View File

@ -6,6 +6,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
@ -94,6 +95,20 @@ public class BukkitFuture
};
}
/**
* Finalize a {@link CompletionStage} by executing code on the
* main thread after its normal or exceptional completion.
*
* @param action the {@link BiConsumer} that will execute
* @return a {@link BiConsumer} to be passed as an argument to
* {@link CompletionStage#whenComplete(BiConsumer)}
* @see CompletableFuture#whenComplete(BiConsumer)
*/
public static <T> BiConsumer<? super T,? super Throwable> complete(BiConsumer<? super T,? super Throwable> action)
{
return (val, throwable) -> runBlocking(() -> action.accept(val, throwable));
}
/**
* Create a {@link CompletionStage} from a supplier executed on the
* main thread.

View File

@ -117,9 +117,11 @@ public class PlayerKeyValueRepository<V>
return _mapper._deserializer.read(set, 1);
}
return null;
} catch (SQLException ignored) {}
return null; // yuck
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
}
@ -146,9 +148,11 @@ public class PlayerKeyValueRepository<V>
results.put(set.getString(1), _mapper._deserializer.read(set, 2));
}
return results;
} catch (SQLException ignored) {}
return new HashMap<>(); // yuck
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
}
@ -174,9 +178,11 @@ public class PlayerKeyValueRepository<V>
stmt.executeUpdate();
return true;
} catch (SQLException ignored) {}
return false;
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
}
@ -189,7 +195,7 @@ public class PlayerKeyValueRepository<V>
* @return a {@link CompletableFuture} whose value indicates
* success or failure
*/
public CompletableFuture<Boolean> putAll(UUID uuid, Map<String,V> values)
public CompletableFuture<Void> putAll(UUID uuid, Map<String,V> values)
{
return CompletableFuture.supplyAsync(() ->
{
@ -205,11 +211,13 @@ public class PlayerKeyValueRepository<V>
stmt.addBatch();
}
stmt.executeBatch();
return true;
return null;
} catch (SQLException ignored) {}
return false;
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
}
@ -233,9 +241,11 @@ public class PlayerKeyValueRepository<V>
stmt.executeUpdate();
return true;
} catch (SQLException ignored) {}
return false;
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
}
@ -257,9 +267,11 @@ public class PlayerKeyValueRepository<V>
stmt.executeUpdate();
return true;
} catch (SQLException ignored) {}
return false;
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
}