diff options
| author | Benjamin Culkin <scorpress@gmail.com> | 2026-01-28 21:31:58 -0500 |
|---|---|---|
| committer | Benjamin Culkin <scorpress@gmail.com> | 2026-01-28 21:31:58 -0500 |
| commit | db210a8fd59f5281c120f1e8749b917246254e75 (patch) | |
| tree | 8f142c71a33906e8d363a2fb2b4acbaece237bb9 | |
| parent | 85e3e06fef5f52250a40e39e0674886635ac08fa (diff) | |
Minor tweak for future stuff
| -rw-r--r-- | firmal/src/main/java/bjc/firmal/Firmal.java | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/firmal/src/main/java/bjc/firmal/Firmal.java b/firmal/src/main/java/bjc/firmal/Firmal.java index b25d40f..b20186e 100644 --- a/firmal/src/main/java/bjc/firmal/Firmal.java +++ b/firmal/src/main/java/bjc/firmal/Firmal.java @@ -7,9 +7,9 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import javax.swing.JButton; @@ -90,7 +90,7 @@ public class Firmal { * @return A function that will execute batches using {@link NamedPreparedStatement.Args} to hold the data * @throws SQLException if something went wrong */ - public ClosableThrowFunction<List<NamedPreparedStatement.Args>, Future<List<Integer>>, SQLException> + public ClosableThrowFunction<List<NamedPreparedStatement.Args>, CompletableFuture<List<Integer>>, SQLException> createQueuedUpdater(String sql, NamedPreparedStatement.Args argShape) throws SQLException { if (dbConnection == null) { // Establish connection - we close it elsewhere @@ -100,22 +100,29 @@ public class Firmal { NamedPreparedStatement.Executor nameStatement = NamedPreparedStatement.Executor.create(dbConnection, sql, argShape); - // TODO do something to assist with this swallowing exceptions - ClosableThrowFunction<List<NamedPreparedStatement.Args>, Future<List<Integer>>, SQLException> func = + // TODO do something to properly handle exceptions here + ClosableThrowFunction<List<NamedPreparedStatement.Args>, CompletableFuture<List<Integer>>, SQLException> func = ClosableThrowFunction.bindFunction(record -> { - Future<List<Integer>> result = dbExecutor.submit(() -> { + CompletableFuture<List<Integer>> result = CompletableFuture.supplyAsync(() -> { List<Integer> resList = new ArrayList<>(record.size()); - int[] dbRes = nameStatement.executeBatch(record); - for (int i : dbRes) resList.add(i); + int[] dbRes; + try { + dbRes = nameStatement.executeBatch(record); + for (int i : dbRes) resList.add(i); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } return resList; - }); + }, dbExecutor); return result; }, nameStatement); return func; } + /** * Create a task batch that will be tracked in the activity window * |
