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

View file

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

View file

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

View file

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

View file

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