summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmal/src/main/java/bjc/firmal/Firmal.java23
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
*