Sqlite: Cleanup Sqlite

We don't need the threading anymore, so we removed it. The indexer
will be run in its thread anyway, so an extra thread makes the code
only more complicated. And we added namespaces.

Change-Id: Ibcba306324763285cf653c28bb08122345e5f8da
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2017-07-26 16:02:24 +02:00
parent 94ba1b8b5d
commit 3dcce060b2
50 changed files with 461 additions and 1196 deletions

View File

@@ -27,88 +27,91 @@
#include "sqlitecolumn.h"
#include "sqlitedatabase.h"
#include "createtablesqlstatementbuilder.h"
#include "sqlitewritestatement.h"
#include "sqlitetransaction.h"
namespace Sqlite {
SqliteTable::SqliteTable()
: withoutRowId(false)
: m_withoutRowId(false)
{
}
SqliteTable::~SqliteTable()
{
qDeleteAll(sqliteColumns);
qDeleteAll(m_sqliteColumns);
}
void SqliteTable::setName(const Utf8String &name)
{
tableName = name;
m_tableName = name;
}
const Utf8String &SqliteTable::name() const
{
return tableName;
return m_tableName;
}
void SqliteTable::setUseWithoutRowId(bool useWithoutWorId)
{
withoutRowId = useWithoutWorId;
m_withoutRowId = useWithoutWorId;
}
bool SqliteTable::useWithoutRowId() const
{
return withoutRowId;
return m_withoutRowId;
}
void SqliteTable::addColumn(SqliteColumn *newColumn)
{
sqliteColumns.append(newColumn);
m_sqliteColumns.append(newColumn);
}
const QVector<SqliteColumn *> &SqliteTable::columns() const
{
return sqliteColumns;
return m_sqliteColumns;
}
void SqliteTable::setSqliteDatabase(SqliteDatabase *database)
{
sqliteDatabase = database;
writeWorker.moveWorkerToThread(sqliteDatabase->writeWorkerThread());
m_sqliteDatabase = database;
}
void SqliteTable::initialize()
{
writeWorker.connectWithWorker(this);
try {
CreateTableSqlStatementBuilder createTableSqlStatementBuilder;
writeWorker.createTable(createTableCommand());
createTableSqlStatementBuilder.setTable(m_tableName);
createTableSqlStatementBuilder.setUseWithoutRowId(m_withoutRowId);
createTableSqlStatementBuilder.setColumnDefinitions(createColumnDefintions());
SqliteImmediateTransaction transaction;
SqliteWriteStatement::execute(createTableSqlStatementBuilder.sqlStatement());
transaction.commit();
m_isReady = true;
} catch (const SqliteException &exception) {
exception.printWarning();
}
}
void SqliteTable::shutdown()
bool SqliteTable::isReady() const
{
writeWorker.disconnectWithWorker(this);
return m_isReady;
}
void SqliteTable::handleTableCreated()
QVector<ColumnDefinition> SqliteTable::createColumnDefintions() const
{
emit tableIsReady();
}
QVector<ColumnDefinition> columnDefintions;
Internal::CreateTableCommand SqliteTable::createTableCommand() const
{
Internal::CreateTableCommand createTableCommand;
createTableCommand.tableName = tableName;
createTableCommand.useWithoutRowId = withoutRowId;
createTableCommand.definitions = createColumnDefintions();
return createTableCommand;
}
QVector<Internal::ColumnDefinition> SqliteTable::createColumnDefintions() const
{
QVector<Internal::ColumnDefinition> columnDefintions;
for (SqliteColumn *sqliteColumn: sqliteColumns)
for (SqliteColumn *sqliteColumn : m_sqliteColumns)
columnDefintions.append(sqliteColumn->columnDefintion());
return columnDefintions;
}
} // namespace Sqlite