Allow PlayerKeyValueRepository Exceptions to propagate
This commit is contained in:
parent
857cf6ad30
commit
5331e2bec9
@ -6,6 +6,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.CompletionStage;
|
import java.util.concurrent.CompletionStage;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
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
|
* Create a {@link CompletionStage} from a supplier executed on the
|
||||||
* main thread.
|
* main thread.
|
||||||
|
@ -117,9 +117,11 @@ public class PlayerKeyValueRepository<V>
|
|||||||
return _mapper._deserializer.read(set, 1);
|
return _mapper._deserializer.read(set, 1);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (SQLException ignored) {}
|
}
|
||||||
|
catch (SQLException e)
|
||||||
return null; // yuck
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,9 +148,11 @@ public class PlayerKeyValueRepository<V>
|
|||||||
results.put(set.getString(1), _mapper._deserializer.read(set, 2));
|
results.put(set.getString(1), _mapper._deserializer.read(set, 2));
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
} catch (SQLException ignored) {}
|
}
|
||||||
|
catch (SQLException e)
|
||||||
return new HashMap<>(); // yuck
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,9 +178,11 @@ public class PlayerKeyValueRepository<V>
|
|||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (SQLException ignored) {}
|
}
|
||||||
|
catch (SQLException e)
|
||||||
return false;
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +195,7 @@ public class PlayerKeyValueRepository<V>
|
|||||||
* @return a {@link CompletableFuture} whose value indicates
|
* @return a {@link CompletableFuture} whose value indicates
|
||||||
* success or failure
|
* 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(() ->
|
return CompletableFuture.supplyAsync(() ->
|
||||||
{
|
{
|
||||||
@ -205,11 +211,13 @@ public class PlayerKeyValueRepository<V>
|
|||||||
stmt.addBatch();
|
stmt.addBatch();
|
||||||
}
|
}
|
||||||
stmt.executeBatch();
|
stmt.executeBatch();
|
||||||
return true;
|
return null;
|
||||||
|
|
||||||
} catch (SQLException ignored) {}
|
}
|
||||||
|
catch (SQLException e)
|
||||||
return false;
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,9 +241,11 @@ public class PlayerKeyValueRepository<V>
|
|||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (SQLException ignored) {}
|
}
|
||||||
|
catch (SQLException e)
|
||||||
return false;
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,9 +267,11 @@ public class PlayerKeyValueRepository<V>
|
|||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (SQLException ignored) {}
|
}
|
||||||
|
catch (SQLException e)
|
||||||
return false;
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user