mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-30 18:40:46 +00:00
Catch more exceptions in db init
This commit is contained in:
parent
cfc02bbcc8
commit
f3eb32e2ec
1 changed files with 27 additions and 21 deletions
|
@ -24,29 +24,13 @@ public class SqliteDBStore implements DBStore {
|
|||
|
||||
private final Connection connection;
|
||||
|
||||
public SqliteDBStore(
|
||||
File dbFile
|
||||
) {
|
||||
File parentDir = dbFile.getParentFile();
|
||||
if (!parentDir.exists() && !parentDir.mkdirs()) {
|
||||
throw new DBInitException(
|
||||
parentDir.getAbsolutePath() + " directory didn't exist, " +
|
||||
"and unable to create. Check your permissions."
|
||||
);
|
||||
}
|
||||
public SqliteDBStore(File dbFile) {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new DBInitException(e);
|
||||
connection = openConnectionTo(dbFile);
|
||||
createTables();
|
||||
} catch (Throwable t) {
|
||||
throw new DBInitException(t);
|
||||
}
|
||||
try {
|
||||
connection = DriverManager.getConnection(
|
||||
"jdbc:sqlite:" + dbFile.getAbsolutePath()
|
||||
);
|
||||
} catch (SQLException e) {
|
||||
throw new DBInitException("Unable to connect to DB", e);
|
||||
}
|
||||
createTables();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,6 +91,28 @@ public class SqliteDBStore implements DBStore {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private Connection openConnectionTo(File dbFile) {
|
||||
File parentDir = dbFile.getParentFile();
|
||||
if (!parentDir.exists() && !parentDir.mkdirs()) {
|
||||
throw new DBInitException(
|
||||
parentDir.getAbsolutePath() + " directory didn't exist, " +
|
||||
"and unable to create. Check your permissions."
|
||||
);
|
||||
}
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new DBInitException(e);
|
||||
}
|
||||
try {
|
||||
return DriverManager.getConnection(
|
||||
"jdbc:sqlite:" + dbFile.getAbsolutePath()
|
||||
);
|
||||
} catch (SQLException e) {
|
||||
throw new DBInitException("Unable to connect to DB", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void createTables() {
|
||||
Stream.of(
|
||||
new CreateProjectsTableSQLUpdate(),
|
||||
|
|
Loading…
Reference in a new issue