Clang: Add RefactoringDatabaseInitializer

We moved the creation of the tables and indices to an extra class which can
be called from other places. So you can be sure that a database is
initialized.

Change-Id: Ief5b30ced7b9011ca94367aa2578098423dcecd9
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2017-09-19 17:56:54 +02:00
committed by Tim Jenssen
parent 623135592c
commit 2df9a99cac
7 changed files with 198 additions and 107 deletions

View File

@@ -47,56 +47,6 @@ public:
{
}
Sqlite::Table createSymbolsTable()
{
Sqlite::Table table;
table.setUseIfNotExists(true);
table.setName("symbols");
table.addColumn("symbolId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey);
const Sqlite::Column &usrColumn = table.addColumn("usr", Sqlite::ColumnType::Text);
table.addColumn("symbolName", Sqlite::ColumnType::Text);
table.addIndex({usrColumn});
Sqlite::ImmediateTransaction<DatabaseType> transaction(database);
table.initialize(database);
transaction.commit();
return table;
}
Sqlite::Table createLocationsTable()
{
Sqlite::Table table;
table.setUseIfNotExists(true);
table.setName("locations");
table.addColumn("symbolId", Sqlite::ColumnType::Integer);
table.addColumn("line", Sqlite::ColumnType::Integer);
table.addColumn("column", Sqlite::ColumnType::Integer);
const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer);
table.addIndex({sourceIdColumn});
Sqlite::ImmediateTransaction<DatabaseType> transaction(database);
table.initialize(database);
transaction.commit();
return table;
}
Sqlite::Table createSourcesTable()
{
Sqlite::Table table;
table.setUseIfNotExists(true);
table.setName("sources");
table.addColumn("sourceId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey);
table.addColumn("sourcePath", Sqlite::ColumnType::Text);
Sqlite::ImmediateTransaction<DatabaseType> transaction(database);
table.initialize(database);
transaction.commit();
return table;
}
Sqlite::Table createNewSymbolsTable() const
{
Sqlite::Table table;
@@ -137,9 +87,6 @@ public:
public:
Database &database;
Sqlite::Table symbolsTable{createSymbolsTable()};
Sqlite::Table locationsTable{createLocationsTable()};
Sqlite::Table sourcesTable{createSourcesTable()};
Sqlite::Table newSymbolsTablet{createNewSymbolsTable()};
Sqlite::Table newLocationsTable{createNewLocationsTable()};
WriteStatement insertSymbolsToNewSymbolsStatement{

View File

@@ -32,6 +32,7 @@
#include "symbolscollector.h"
#include "symbolstorage.h"
#include <refactoringdatabaseinitializer.h>
#include <stringcache.h>
#include <sqlitedatabase.h>
@@ -47,12 +48,13 @@ public:
Sqlite::ReadStatement,
Sqlite::WriteStatement>;
using Storage = ClangBackEnd::SymbolStorage<StatementFactory>;
using DatabaseInitializer = RefactoringDatabaseInitializer<Sqlite::Database>;
SymbolIndexing(FilePathCache<std::mutex> &filePathCache,
Utils::PathString &&databaseFilePath)
: m_filePathCache(filePathCache),
m_database(std::move(databaseFilePath))
m_database(std::move(databaseFilePath)),
m_databaseInitializer(m_database)
{
}
@@ -75,6 +77,7 @@ public:
private:
FilePathCache<std::mutex> &m_filePathCache;
Sqlite::Database m_database;
DatabaseInitializer m_databaseInitializer;
SymbolsCollector m_collector{m_filePathCache};
StatementFactory m_statementFactory{m_database};
Storage m_symbolStorage{m_statementFactory, m_filePathCache};