mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 06:39:54 +01:00
Throw an exception rather than blocking if a transaction is started
after the database has closed.
This commit is contained in:
@@ -55,6 +55,7 @@ class H2Database extends JdbcDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws DbException {
|
public void close() throws DbException {
|
||||||
|
// H2 will close the database when the last connection closes
|
||||||
try {
|
try {
|
||||||
super.closeAllConnections();
|
super.closeAllConnections();
|
||||||
} catch(SQLException e) {
|
} catch(SQLException e) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.sf.briar.db;
|
package net.sf.briar.db;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@@ -297,8 +298,8 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
protected void open(boolean resume, File dir, String driverClass)
|
protected void open(boolean resume, File dir, String driverClass)
|
||||||
throws DbException, IOException {
|
throws DbException, IOException {
|
||||||
if(resume) {
|
if(resume) {
|
||||||
if(!dir.exists()) throw new DbException();
|
if(!dir.exists()) throw new FileNotFoundException();
|
||||||
if(!dir.isDirectory()) throw new DbException();
|
if(!dir.isDirectory()) throw new FileNotFoundException();
|
||||||
} else {
|
} else {
|
||||||
if(dir.exists()) FileUtils.delete(dir);
|
if(dir.exists()) FileUtils.delete(dir);
|
||||||
}
|
}
|
||||||
@@ -388,14 +389,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
public Connection startTransaction() throws DbException {
|
public Connection startTransaction() throws DbException {
|
||||||
Connection txn = null;
|
Connection txn = null;
|
||||||
synchronized(connections) {
|
synchronized(connections) {
|
||||||
// If the database has been closed, don't return
|
if(closed) throw new DbException();
|
||||||
while(closed) {
|
|
||||||
try {
|
|
||||||
connections.wait();
|
|
||||||
} catch(InterruptedException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
txn = connections.poll();
|
txn = connections.poll();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user