QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgstransaction.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgstransaction.h
3  ----------------
4  begin : May 5, 2014
5  copyright : (C) 2014 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSTRANSACTION_H
19 #define QGSTRANSACTION_H
20 
21 #include <QSet>
22 #include "qgis_sip.h"
23 #include <QString>
24 #include <QObject>
25 #include <QStack>
26 
27 #include "qgis_core.h"
28 #include "qgis_sip.h"
29 
31 class QgsVectorLayer;
32 
56 class CORE_EXPORT QgsTransaction : public QObject SIP_ABSTRACT
57 {
58  Q_OBJECT
59 
60  public:
61 
66  static QgsTransaction *create( const QString &connString, const QString &providerKey ) SIP_FACTORY;
67 
73  static QgsTransaction *create( const QSet<QgsVectorLayer *> &layers ) SIP_FACTORY;
74 
75  ~QgsTransaction() override;
76 
81  bool addLayer( QgsVectorLayer *layer );
82 
93  bool begin( QString &errorMsg SIP_OUT, int statementTimeout = 20 );
94 
98  bool commit( QString &errorMsg SIP_OUT );
99 
103  bool rollback( QString &errorMsg SIP_OUT );
104 
115  virtual bool executeSql( const QString &sql, QString &error SIP_OUT, bool isDirty = false, const QString &name = QString() ) = 0;
116 
120  static bool supportsTransaction( const QgsVectorLayer *layer );
121 
128  QString createSavepoint( QString &error SIP_OUT );
129 
135  QString createSavepoint( const QString &savePointId, QString &error SIP_OUT );
136 
141  bool rollbackToSavepoint( const QString &name, QString &error SIP_OUT );
142 
147  void dirtyLastSavePoint();
148 
153  QList< QString > savePoints() const { return QList< QString >::fromVector( mSavepoints ); }
154 
159  bool lastSavePointIsDirty() const { return mLastSavePointIsDirty; }
160 
162  // For internal use only, or by QgsTransactionGroup
163  static QString connectionString( const QString &layerName ) SIP_SKIP;
165 
166  signals:
167 
171  void afterRollback();
172 
176  void dirtied( const QString &sql, const QString &name );
177 
178  protected:
179  QgsTransaction( const QString &connString ) SIP_SKIP;
180 
181  QString mConnString;
182 
183  private slots:
184  void onLayerDeleted();
185 
186  private:
187 
188  bool mTransactionActive;
189  QSet<QgsVectorLayer *> mLayers;
190 
191  QStack< QString > mSavepoints;
192  bool mLastSavePointIsDirty;
193 
194  void setLayerTransactionIds( QgsTransaction *transaction );
195 
196  static QString removeLayerIdOrName( const QString &str );
197 
198  virtual bool beginTransaction( QString &error, int statementTimeout ) = 0;
199  virtual bool commitTransaction( QString &error ) = 0;
200  virtual bool rollbackTransaction( QString &error ) = 0;
201 };
202 
203 #endif // QGSTRANSACTION_H
bool lastSavePointIsDirty() const
returns the last created savepoint
#define SIP_ABSTRACT
Definition: qgis_sip.h:187
#define SIP_SKIP
Definition: qgis_sip.h:119
#define SIP_FACTORY
Definition: qgis_sip.h:69
This class allows including a set of layers in a database-side transaction, provided the layer data p...
#define SIP_OUT
Definition: qgis_sip.h:51
This is the base class for vector data providers.
Represents a vector layer which manages a vector based data sets.
QList< QString > savePoints() const
returns savepoints