1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtSystems module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34#ifndef QSERVICEDATABASE_H_
35#define QSERVICEDATABASE_H_
36
37//
38// W A R N I N G
39// -------------
40//
41// This file is not part of the Qt API. It exists purely as an
42// implementation detail. This header file may change from version to
43// version without notice, or even be removed.
44//
45// We mean it.
46//
47
48#include "qserviceframeworkglobal.h"
49#include <QtSql>
50#include <QList>
51#include "servicemetadata_p.h"
52#include "qservicefilter.h"
53#include "dberror_p.h"
54
55QT_BEGIN_NAMESPACE
56
57class QServiceInterfaceDescriptor;
58
59class Q_AUTOTEST_EXPORT ServiceDatabase : public QObject
60{
61 Q_OBJECT
62
63 public:
64 ServiceDatabase(void);
65
66 virtual ~ServiceDatabase();
67
68 bool open();
69 bool close();
70
71 bool isOpen() const;
72 void setDatabasePath(const QString &databasePath);
73 QString databasePath() const;
74
75 bool registerService(const ServiceMetaDataResults &service, const QString &securityToken = QString());
76 bool unregisterService(const QString &serviceName, const QString &securityToken = QString());
77 bool serviceInitialized(const QString &serviceName, const QString &securityToken = QString());
78
79 QList<QServiceInterfaceDescriptor> getInterfaces(const QServiceFilter &filter);
80 QServiceInterfaceDescriptor getInterface(const QString &interfaceID);
81 QString getInterfaceID(const QServiceInterfaceDescriptor &serviceInterface);
82 QStringList getServiceNames(const QString &interfaceName);
83
84 QServiceInterfaceDescriptor interfaceDefault(const QString &interfaceName,
85 QString *interfaceID = 0, bool inTransaction = false);
86 bool setInterfaceDefault(const QServiceInterfaceDescriptor &serviceInterface,
87 const QString &externalInterfaceID = QString());
88 QList<QPair<QString,QString> > externalDefaultsInfo();
89 bool removeExternalDefaultServiceInterface(const QString &interfaceID);
90
91 DBError lastError() const { return m_lastError; }
92
93Q_SIGNALS:
94 void serviceAdded(const QString& serviceName);
95 void serviceRemoved(const QString& serviceName);
96
97#ifdef QT_BUILD_INTERNAL
98 public:
99#else
100 private:
101#endif
102 enum TransactionType{Read, Write};
103
104 bool createTables();
105 bool dropTables();
106 bool checkTables();
107
108 bool checkConnection();
109
110 bool executeQuery(QSqlQuery *query, const QString &statement, const QList<QVariant> &bindValues = QList<QVariant>());
111 QString getInterfaceID(QSqlQuery *query, const QServiceInterfaceDescriptor &serviceInterface);
112 bool insertInterfaceData(QSqlQuery *query, const QServiceInterfaceDescriptor &anInterface, const QString &serviceID);
113
114 bool beginTransaction(QSqlQuery *query, TransactionType);
115 bool commitTransaction(QSqlQuery *query);
116 bool rollbackTransaction(QSqlQuery *query);
117
118 bool populateInterfaceProperties(QServiceInterfaceDescriptor *descriptor, const QString &interfaceID);
119 bool populateServiceProperties(QServiceInterfaceDescriptor *descriptor, const QString &serviceID);
120
121 QString m_databasePath;
122 QString m_connectionName;
123 bool m_isDatabaseOpen;
124 bool m_inTransaction;
125 DBError m_lastError;
126};
127
128QT_END_NAMESPACE
129
130#endif /*QSERVICEDATABASE_H_*/
131

source code of qtsystems/src/serviceframework/servicedatabase_p.h