mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Compare commits
1 Commits
beta-1.4.2
...
1528-log-t
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
580be7cfdc |
@@ -3,15 +3,16 @@ package org.briarproject.bramble.db;
|
||||
class DatabaseTypes {
|
||||
|
||||
private final String hashType, secretType, binaryType;
|
||||
private final String counterType, stringType;
|
||||
private final String counterType, stringType, schemaQuery;
|
||||
|
||||
public DatabaseTypes(String hashType, String secretType, String binaryType,
|
||||
String counterType, String stringType) {
|
||||
DatabaseTypes(String hashType, String secretType, String binaryType,
|
||||
String counterType, String stringType, String schemaQuery) {
|
||||
this.hashType = hashType;
|
||||
this.secretType = secretType;
|
||||
this.binaryType = binaryType;
|
||||
this.counterType = counterType;
|
||||
this.stringType = stringType;
|
||||
this.schemaQuery = schemaQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,4 +32,8 @@ class DatabaseTypes {
|
||||
s = s.replaceAll("_STRING", stringType);
|
||||
return s;
|
||||
}
|
||||
|
||||
String getSchemaQuery() {
|
||||
return schemaQuery;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +41,9 @@ class H2Database extends JdbcDatabase {
|
||||
private static final String BINARY_TYPE = "BINARY";
|
||||
private static final String COUNTER_TYPE = "INT NOT NULL AUTO_INCREMENT";
|
||||
private static final String STRING_TYPE = "VARCHAR";
|
||||
private static final String SCHEMA_QUERY = "SHOW TABLES";
|
||||
private static final DatabaseTypes dbTypes = new DatabaseTypes(HASH_TYPE,
|
||||
SECRET_TYPE, BINARY_TYPE, COUNTER_TYPE, STRING_TYPE);
|
||||
SECRET_TYPE, BINARY_TYPE, COUNTER_TYPE, STRING_TYPE, SCHEMA_QUERY);
|
||||
|
||||
private final DatabaseConfig config;
|
||||
private final String url;
|
||||
|
||||
@@ -41,8 +41,11 @@ class HyperSqlDatabase extends JdbcDatabase {
|
||||
private static final String COUNTER_TYPE =
|
||||
"INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY(START WITH 1)";
|
||||
private static final String STRING_TYPE = "VARCHAR";
|
||||
private static final String SCHEMA_QUERY =
|
||||
"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.SYSTEM_TABLES"
|
||||
+ " WHERE TABLE_TYPE='TABLE'";
|
||||
private static final DatabaseTypes dbTypes = new DatabaseTypes(HASH_TYPE,
|
||||
SECRET_TYPE, BINARY_TYPE, COUNTER_TYPE, STRING_TYPE);
|
||||
SECRET_TYPE, BINARY_TYPE, COUNTER_TYPE, STRING_TYPE, SCHEMA_QUERY);
|
||||
|
||||
private final DatabaseConfig config;
|
||||
private final String url;
|
||||
|
||||
@@ -405,6 +405,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
boolean compact;
|
||||
Connection txn = startTransaction();
|
||||
try {
|
||||
if (LOG.isLoggable(INFO)) logSchema(txn);
|
||||
if (reopen) {
|
||||
Settings s = getSettings(txn, DB_SETTINGS_NAMESPACE);
|
||||
wasDirtyOnInitialisation = isDirty(s);
|
||||
@@ -447,6 +448,24 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
return wasDirtyOnInitialisation;
|
||||
}
|
||||
|
||||
private void logSchema(Connection txn) throws DbException {
|
||||
Statement s = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
s = txn.createStatement();
|
||||
rs = s.executeQuery(dbTypes.getSchemaQuery());
|
||||
StringBuilder sb = new StringBuilder("Tables:");
|
||||
while (rs.next()) sb.append('\n').append(rs.getString(1));
|
||||
LOG.info(sb.toString());
|
||||
rs.close();
|
||||
s.close();
|
||||
} catch (SQLException e) {
|
||||
tryToClose(rs, LOG, WARNING);
|
||||
tryToClose(s, LOG, WARNING);
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the schema version stored in the database with the schema
|
||||
* version used by the current code and applies any suitable migrations to
|
||||
|
||||
Reference in New Issue
Block a user