remove ThreadDeath and QueueException

This commit is contained in:
Jörg Prante 2024-06-12 22:56:01 +02:00
parent 07b20d8188
commit f7fd2df016
6 changed files with 16 additions and 21 deletions

View file

@ -19,7 +19,7 @@ jar {
tasks.withType(JavaCompile) {
options.fork = true
options.forkOptions.jvmArgs += ['-Duser.language=en','-Duser.country=US']
options.compilerArgs << '-Xlint:all'
options.compilerArgs << '-Xlint:all,-exports'
options.encoding = 'UTF-8'
}

View file

@ -4,7 +4,7 @@ import org.xbib.jdbc.postgresql.Postgresql;
module org.xbib.jdbc.postgresql {
requires org.xbib.jdbc.query;
requires java.sql;
requires org.postgresql.jdbc;
requires org.postgresql.jdbc; // automatic module
uses Flavor;
exports org.xbib.jdbc.postgresql;
provides Flavor with Postgresql;

View file

@ -35,6 +35,7 @@ public class Listener implements Runnable {
while (true) {
try (Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1")) {
//
} catch (SQLException e) {
errorConsumer.accept(e);
}

View file

@ -550,7 +550,10 @@ public class DatabaseImpl implements Database {
}
@Override
public void consumeQueue(String table, String channel, int limit, Consumer<String> consumer) throws SQLException {
public void consumeQueue(String table,
String channel,
int limit,
Consumer<String> consumer) throws SQLException {
List<Long> consumedKeys = new ArrayList<>();
try {
connection.setAutoCommit(false);
@ -563,13 +566,12 @@ public class DatabaseImpl implements Database {
consumer.accept(resultSet.getString("data"));
}
succeedInQueue(connection, table, key);
} catch (QueueException e) {
} catch (Exception e) {
connection.rollback();
failInQueue(connection, table, key);
throw e;
}
}
} finally {
connection.commit();
}
} catch (Exception e) {

View file

@ -170,7 +170,7 @@ public final class DatabaseProvider implements Supplier<Database>, Closeable {
try {
code.run(this);
complete = true;
} catch (ThreadDeath | DatabaseException t) {
} catch (DatabaseException t) {
throw t;
} catch (Throwable t) {
throw new DatabaseException("Error during transaction", t);
@ -188,7 +188,7 @@ public final class DatabaseProvider implements Supplier<Database>, Closeable {
try {
code.run(this);
complete = true;
} catch (ThreadDeath | DatabaseException t) {
} catch (DatabaseException t) {
throw t;
} catch (Throwable t) {
throw new DatabaseException("Error during transaction", t);
@ -207,7 +207,7 @@ public final class DatabaseProvider implements Supplier<Database>, Closeable {
try {
result = code.run(this);
complete = true;
} catch (ThreadDeath | DatabaseException t) {
} catch (DatabaseException t) {
throw t;
} catch (Throwable t) {
throw new DatabaseException("Error during transaction", t);
@ -227,7 +227,7 @@ public final class DatabaseProvider implements Supplier<Database>, Closeable {
try {
result = code.run(this);
complete = true;
} catch (ThreadDeath | DatabaseException t) {
} catch (DatabaseException t) {
throw t;
} catch (Throwable t) {
throw new DatabaseException("Error during transaction", t);
@ -249,7 +249,7 @@ public final class DatabaseProvider implements Supplier<Database>, Closeable {
try {
code.run(this, tx);
complete = true;
} catch (ThreadDeath | DatabaseException t) {
} catch (DatabaseException t) {
throw t;
} catch (Throwable t) {
throw new DatabaseException("Error during transaction", t);
@ -270,7 +270,7 @@ public final class DatabaseProvider implements Supplier<Database>, Closeable {
try {
code.run(this, tx);
complete = true;
} catch (ThreadDeath | DatabaseException t) {
} catch (DatabaseException t) {
throw t;
} catch (Throwable t) {
throw new DatabaseException("Error during transaction", t);
@ -299,7 +299,7 @@ public final class DatabaseProvider implements Supplier<Database>, Closeable {
// Don't try to be clever about clearing it conditionally.
if (!builder.options.flavor().isAutoCommitOnly()) {
connection.setAutoCommit(false);
metric.checkpoint("setAutoCommit");
metric.checkpoint("setAutoCommit false");
}
} catch (SQLException e) {
throw new DatabaseException("Unable to set autoCommit for the connection", e);
@ -402,9 +402,9 @@ public final class DatabaseProvider implements Supplier<Database>, Closeable {
logger.log(Level.SEVERE, "Unable to close the database connection", e);
}
}
builder.close();
connection = null;
database = null;
builder.close();
}
private static class DatabaseProviderBuilderImpl implements DatabaseProviderBuilder, Closeable {

View file

@ -1,8 +0,0 @@
package org.xbib.jdbc.query;
public class QueueException extends DatabaseException {
public QueueException(String message, Throwable cause) {
super(message, cause);
}
}