+}
+
+void AbstractSqlStorage::addConnectionToPool()
+{
+ QMutexLocker locker(&_connectionPoolMutex);
+ // we have to recheck if the connection pool already contains a connection for
+ // this thread. Since now (after the lock) we can only tell for sure
+ if (_connectionPool.contains(QThread::currentThread()))
+ return;
+
+ QThread* currentThread = QThread::currentThread();
+
+ int connectionId = _nextConnectionId++;
+
+ Connection* connection = new Connection(QLatin1String(QString("quassel_%1_con_%2").arg(driverName()).arg(connectionId).toLatin1()));
+ connection->moveToThread(currentThread);
+ connect(this, &QObject::destroyed, connection, &QObject::deleteLater);
+ connect(currentThread, &QObject::destroyed, connection, &QObject::deleteLater);
+ connect(connection, &QObject::destroyed, this, &AbstractSqlStorage::connectionDestroyed);
+ _connectionPool[currentThread] = connection;
+
+ QSqlDatabase db = QSqlDatabase::addDatabase(driverName(), connection->name());
+ db.setDatabaseName(databaseName());
+
+ if (!hostName().isEmpty())
+ db.setHostName(hostName());
+
+ if (port() != -1)
+ db.setPort(port());
+
+ if (!userName().isEmpty()) {
+ db.setUserName(userName());
+ db.setPassword(password());
+ }
+
+ dbConnect(db);
+}
+
+void AbstractSqlStorage::dbConnect(QSqlDatabase& db)
+{
+ if (!db.open()) {
+ qWarning() << "Unable to open database" << displayName() << "for thread" << QThread::currentThread();
+ qWarning() << "-" << db.lastError().text();
+ }
+ else {
+ if (!initDbSession(db)) {
+ qWarning() << "Unable to initialize database" << displayName() << "for thread" << QThread::currentThread();
+ db.close();
+ }
+ }
+}
+
+Storage::State AbstractSqlStorage::init(const QVariantMap& settings, const QProcessEnvironment& environment, bool loadFromEnvironment)
+{
+ setConnectionProperties(settings, environment, loadFromEnvironment);
+
+ _debug = Quassel::isOptionSet("debug");
+
+ QSqlDatabase db = logDb();
+ if (!db.isValid() || !db.isOpen())
+ return NotAvailable;