QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 <QString>
23 
25 
47 class CORE_EXPORT QgsTransaction
48 {
49  public:
51  static QgsTransaction* create( const QString& connString, const QString& providerKey );
52 
55  static QgsTransaction* create( const QStringList& layerIds );
56 
57  virtual ~QgsTransaction();
58 
60  bool addLayer( const QString& layerId );
61 
70  bool begin( QString& errorMsg, int statementTimeout = 20 );
71 
73  bool commit( QString& errorMsg );
74 
76  bool rollback( QString& errorMsg );
77 
79  virtual bool executeSql( const QString& sql, QString& error ) = 0;
80 
81  protected:
82  QgsTransaction( const QString& connString );
83 
84  QString mConnString;
85 
86  private:
87  QgsTransaction( const QgsTransaction& other );
88  const QgsTransaction& operator=( const QgsTransaction& other );
89 
90  bool mTransactionActive;
91  QSet<QString> mLayers;
92 
93  void setLayerTransactionIds( QgsTransaction *transaction );
94 
95  virtual bool beginTransaction( QString& error, int statementTimeout ) = 0;
96  virtual bool commitTransaction( QString& error ) = 0;
97  virtual bool rollbackTransaction( QString& error ) = 0;
98 };
99 
100 #endif // QGSTRANSACTION_H