Wolframe, 0.0.3

transaction.hpp
Go to the documentation of this file.
1 /************************************************************************
2 
3  Copyright (C) 2011 - 2014 Project Wolframe.
4  All rights reserved.
5 
6  This file is part of Project Wolframe.
7 
8  Commercial Usage
9  Licensees holding valid Project Wolframe Commercial licenses may
10  use this file in accordance with the Project Wolframe
11  Commercial License Agreement provided with the Software or,
12  alternatively, in accordance with the terms contained
13  in a written agreement between the licensee and Project Wolframe.
14 
15  GNU General Public License Usage
16  Alternatively, you can redistribute this file and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  Wolframe is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  GNU General Public License for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
28 
29  If you have questions regarding the use of this file, please contact
30  Project Wolframe.
31 
32 ************************************************************************/
35 
36 #ifndef _TRANSACTION_HPP_INCLUDED
37 #define _TRANSACTION_HPP_INCLUDED
42 #include "types/variant.hpp"
43 #include <string>
44 #include <vector>
45 #include <boost/shared_ptr.hpp>
46 
47 namespace _Wolframe {
48 namespace db {
49 
53 {
54 public:
58  Transaction( const std::string& name_, const TransactionExecStatemachineR& stm_)
59  :m_name(name_),m_stm(stm_){}
60 
62  virtual ~Transaction() {close();}
64  const std::string& databaseID() const {return m_stm->databaseID();}
65 
67  void begin();
69  void commit();
71  void rollback();
73  void close() {m_stm.reset();}
74 
77  virtual bool execute( const VmTransactionInput& input, VmTransactionOutput& output);
78 
80  const std::string& name() const
81  {
82  return m_name;
83  }
84 
87  class Result
88  {
89  public:
90  typedef std::vector<types::Variant> Row;
91 
93  Result(){}
97  Result( const std::vector<std::string>& colnames_, const std::vector<Row>& rows_)
98  :m_colnames(colnames_),m_rows(rows_){}
100  Result( const Result& o)
102 
103  const std::vector<std::string>& colnames() const {return m_colnames;}
104  const std::vector<Row>& rows() const {return m_rows;}
105  std::size_t size() const {return m_rows.size();}
106  std::vector<Row>::const_iterator begin() const {return m_rows.begin();}
107  std::vector<Row>::const_iterator end() const {return m_rows.end();}
108 
109  private:
110  std::vector<std::string> m_colnames;
111  std::vector<Row> m_rows;
112  };
113 
116  bool executeStatement( Result& result, const std::string& stm, const std::vector<types::Variant>& params=std::vector<types::Variant>());
119  bool executeStatement( const std::string& stm, const std::vector<types::Variant>& params=std::vector<types::Variant>());
120 
124  const DatabaseError* getLastError() const {return &m_lastError;}
125 
126 private:
127  Transaction( const Transaction&){} //... non copyable
128 
129 private:
130  std::string m_name;
133 };
134 
135 
136 typedef boost::shared_ptr<Transaction> TransactionR;
137 
138 }} // namespace _Wolframe::db
139 
140 #endif // _TRANSACTION_HPP_INCLUDED
141 
const DatabaseError * getLastError() const
Get the last error occurred.
Definition: transaction.hpp:124
Output of a transaction.
Definition: vmTransactionOutput.hpp:53
TransactionExecStatemachineR m_stm
Definition: transaction.hpp:131
std::vector< Row >::const_iterator begin() const
Definition: transaction.hpp:106
Class for describing database errors.
Definition: databaseError.hpp:46
Transaction(const std::string &name_, const TransactionExecStatemachineR &stm_)
Constructor.
Definition: transaction.hpp:58
Result of a single statement execute call: executeStatement( const std::string&, const std::vector
Definition: transaction.hpp:87
std::size_t size() const
Definition: transaction.hpp:105
Transaction interface.
Definition: transaction.hpp:52
Result(const Result &o)
Copy constructor.
Definition: transaction.hpp:100
void close()
Close of the committed or rolled back transaction.
Definition: transaction.hpp:73
void commit()
Commit of the running transaction.
const std::string & name() const
Get the name of the transaction.
Definition: transaction.hpp:80
const std::vector< std::string > & colnames() const
Definition: transaction.hpp:103
DatabaseError m_lastError
Definition: transaction.hpp:132
boost::shared_ptr< Transaction > TransactionR
Definition: transaction.hpp:136
const std::vector< Row > & rows() const
Definition: transaction.hpp:104
Error class for databases.
std::vector< Row > m_rows
Definition: transaction.hpp:111
Definition of transaction input.
Definition of transaction output.
std::vector< types::Variant > Row
Definition: transaction.hpp:90
void begin()
Begin of a new transaction.
Result()
Default constructor.
Definition: transaction.hpp:93
Variant value type.
std::vector< Row >::const_iterator end() const
Definition: transaction.hpp:107
Input of a transaction.
Definition: vmTransactionInput.hpp:46
TransactionExecStatemachine * execStatemachine()
Get the lower lever database specific execution statemachine of the transaction.
Definition: transaction.hpp:122
boost::shared_ptr< TransactionExecStatemachine > TransactionExecStatemachineR
Definition: transactionExecStatemachine.hpp:91
Interface to the database transaction execution statemechine.
Definition: transactionExecStatemachine.hpp:49
const std::string & databaseID() const
Configured ID of the underlaying database.
Definition: transaction.hpp:64
virtual bool execute(const VmTransactionInput &input, VmTransactionOutput &output)
Execute a transaction.
Transaction(const Transaction &)
Definition: transaction.hpp:127
bool executeStatement(Result &result, const std::string &stm, const std::vector< types::Variant > &params=std::vector< types::Variant >())
Execute a single statement with result.
Result(const std::vector< std::string > &colnames_, const std::vector< Row > &rows_)
Constructor.
Definition: transaction.hpp:97
Interface to the standard database transaction execution statemechine.
void rollback()
Rollback of the running transaction.
std::vector< std::string > m_colnames
Definition: transaction.hpp:110
std::string m_name
Definition: transaction.hpp:130
virtual ~Transaction()
Destructor.
Definition: transaction.hpp:62