1 /***************************************************************************
2 * Copyright (C) 2005-07 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #ifndef ABSTRACTSQLSTORAGE_H
22 #define ABSTRACTSQLSTORAGE_H
26 #include <QSqlDatabase>
30 class AbstractSqlStorage : public Storage {
34 AbstractSqlStorage(QObject *parent = 0);
35 virtual ~AbstractSqlStorage();
38 virtual bool init(const QVariantMap &settings = QVariantMap());
39 inline virtual void sync() {};
43 QString queryString(const QString &queryName, int version);
44 inline QString queryString(const QString &queryName) { return queryString(queryName, 0); }
46 QStringList setupQueries();
47 bool setup(const QVariantMap &settings = QVariantMap());
49 QStringList upgradeQueries(int ver);
52 bool watchQuery(QSqlQuery &query);
55 virtual int installedSchemaVersion() { return -1; };
57 virtual QString driverName() = 0;
58 inline virtual QString hostName() { return QString(); }
59 virtual QString databaseName() = 0;
60 inline virtual QString userName() { return QString(); }
61 inline virtual QString password() { return QString(); }
64 void connectionDestroyed();
67 void addConnectionToPool();
71 int _nextConnectionId;
72 QMutex _connectionPoolMutex;
73 // we let a Connection Object manage each actual db connection
74 // those objects reside in the thread the connection belongs to
75 // which allows us thread safe termination of a connection
77 QHash<QThread *, Connection *> _connectionPool;
80 // ========================================
81 // AbstractSqlStorage::Connection
82 // ========================================
83 class AbstractSqlStorage::Connection : public QObject {
87 Connection(const QString &name, QObject *parent = 0);
90 inline QLatin1String name() const { return QLatin1String(_name); }