mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
Add some simple indexes to the DB.
This commit is contained in:
@@ -232,6 +232,30 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
+ " REFERENCES transports (transportId)"
|
+ " REFERENCES transports (transportId)"
|
||||||
+ " ON DELETE CASCADE)";
|
+ " ON DELETE CASCADE)";
|
||||||
|
|
||||||
|
private static final String INDEX_CONTACTS_BY_AUTHOR_ID =
|
||||||
|
"CREATE INDEX IF NOT EXISTS contactsByAuthorId"
|
||||||
|
+ " ON contacts (authorId)";
|
||||||
|
|
||||||
|
private static final String INDEX_MESSAGES_BY_GROUP_ID =
|
||||||
|
"CREATE INDEX IF NOT EXISTS messagesByGroupId"
|
||||||
|
+ " ON messages (groupId)";
|
||||||
|
|
||||||
|
private static final String INDEX_OFFERS_BY_CONTACT_ID =
|
||||||
|
"CREATE INDEX IF NOT EXISTS offersByContactId"
|
||||||
|
+ " ON offers (contactId)";
|
||||||
|
|
||||||
|
private static final String INDEX_GROUPS_BY_CLIENT_ID =
|
||||||
|
"CREATE INDEX IF NOT EXISTS groupsByClientId"
|
||||||
|
+ " ON groups (clientId)";
|
||||||
|
|
||||||
|
private static final String INDEX_MESSAGE_METADATA_BY_MESSAGE_ID =
|
||||||
|
"CREATE INDEX IF NOT EXISTS messageMetadataByMessageId"
|
||||||
|
+ " ON messageMetadata (messageId)";
|
||||||
|
|
||||||
|
private static final String INDEX_GROUP_METADATA_BY_GROUP_ID =
|
||||||
|
"CREATE INDEX IF NOT EXISTS groupMetadataByGroupId"
|
||||||
|
+ " ON groupMetadata (groupId)";
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(JdbcDatabase.class.getName());
|
Logger.getLogger(JdbcDatabase.class.getName());
|
||||||
|
|
||||||
@@ -267,7 +291,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
// Open the database and create the tables if necessary
|
// Open the database and create the tables and indexes if necessary
|
||||||
Connection txn = startTransaction();
|
Connection txn = startTransaction();
|
||||||
try {
|
try {
|
||||||
if (reopen) {
|
if (reopen) {
|
||||||
@@ -276,6 +300,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
createTables(txn);
|
createTables(txn);
|
||||||
storeSchemaVersion(txn);
|
storeSchemaVersion(txn);
|
||||||
}
|
}
|
||||||
|
createIndexes(txn);
|
||||||
commitTransaction(txn);
|
commitTransaction(txn);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
abortTransaction(txn);
|
abortTransaction(txn);
|
||||||
@@ -340,6 +365,23 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createIndexes(Connection txn) throws DbException {
|
||||||
|
Statement s = null;
|
||||||
|
try {
|
||||||
|
s = txn.createStatement();
|
||||||
|
s.executeUpdate(INDEX_CONTACTS_BY_AUTHOR_ID);
|
||||||
|
s.executeUpdate(INDEX_MESSAGES_BY_GROUP_ID);
|
||||||
|
s.executeUpdate(INDEX_OFFERS_BY_CONTACT_ID);
|
||||||
|
s.executeUpdate(INDEX_GROUPS_BY_CLIENT_ID);
|
||||||
|
s.executeUpdate(INDEX_MESSAGE_METADATA_BY_MESSAGE_ID);
|
||||||
|
s.executeUpdate(INDEX_GROUP_METADATA_BY_GROUP_ID);
|
||||||
|
s.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
tryToClose(s);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String insertTypeNames(String s) {
|
private String insertTypeNames(String s) {
|
||||||
s = s.replaceAll("HASH", hashType);
|
s = s.replaceAll("HASH", hashType);
|
||||||
s = s.replaceAll("BINARY", binaryType);
|
s = s.replaceAll("BINARY", binaryType);
|
||||||
|
|||||||
Reference in New Issue
Block a user