-bool AbstractSqlStorage::openDb() {
- QSqlDatabase db = QSqlDatabase::database("quassel_connection");
- if(db.isValid() && !db.isOpen())
- return db.open();
+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_connection_%1").arg(connectionId).toLatin1()));
+ connection->moveToThread(currentThread);
+ connect(this, SIGNAL(destroyed()), connection, SLOT(deleteLater()));
+ connect(currentThread, SIGNAL(destroyed()), connection, SLOT(deleteLater()));
+ connect(connection, SIGNAL(destroyed()), this, SLOT(connectionDestroyed()));
+ _connectionPool[currentThread] = connection;