Retry database tasks after signing in.

This commit is contained in:
akwizgran
2019-06-08 10:03:45 +01:00
parent 7ec826ccb7
commit e810785fe2
8 changed files with 30 additions and 14 deletions

View File

@@ -2,6 +2,7 @@ package org.briarproject.bramble.db;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DatabaseConfig;
import org.briarproject.bramble.api.db.DbClosedException;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.MigrationListener;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@@ -89,9 +90,9 @@ class H2Database extends JdbcDatabase {
}
@Override
protected Connection createConnection() throws SQLException {
protected Connection createConnection() throws DbException, SQLException {
SecretKey key = this.key;
if (key == null) throw new IllegalStateException();
if (key == null) throw new DbClosedException();
Properties props = new Properties();
props.setProperty("user", "user");
// Separate the file password from the user password with a space

View File

@@ -2,6 +2,7 @@ package org.briarproject.bramble.db;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DatabaseConfig;
import org.briarproject.bramble.api.db.DbClosedException;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.MigrationListener;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@@ -87,9 +88,9 @@ class HyperSqlDatabase extends JdbcDatabase {
}
@Override
protected Connection createConnection() throws SQLException {
protected Connection createConnection() throws DbException, SQLException {
SecretKey key = this.key;
if (key == null) throw new IllegalStateException();
if (key == null) throw new DbClosedException();
String hex = StringUtils.toHexString(key.getBytes());
return DriverManager.getConnection(url + ";crypt_key=" + hex);
}

View File

@@ -347,7 +347,8 @@ abstract class JdbcDatabase implements Database<Connection> {
private int openConnections = 0; // Locking: connectionsLock
private boolean closed = false; // Locking: connectionsLock
protected abstract Connection createConnection() throws SQLException;
protected abstract Connection createConnection()
throws DbException, SQLException;
protected abstract void compactAndClose() throws DbException;