Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

pqxxobject/transaction.h

Go to the documentation of this file.
00001 // database transaction convenience wrapper                      -*- C++ -*-
00002 // $Id: transaction.h,v 1.10 2004/04/02 22:44:55 roger Exp $
00003 //
00004 // Copyright (C) 2003  Roger Leigh <rleigh@debian.org>
00005 //
00006 //
00007 //  All rights reserved.
00008 //
00009 //  Redistribution and use in source and binary forms, with or without
00010 //  modification, are permitted provided that the following conditions
00011 //  are met:
00012 //
00013 //  * Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 //  * Redistributions in binary form must reproduce the above
00016 //    copyright notice, this list of conditions and the following
00017 //    disclaimer in the documentation and/or other materials provided
00018 //    with the distribution.
00019 //  * Neither the name of the author, nor the names of other
00020 //    contributors may be used to endorse or promote products derived
00021 //    from this software without specific prior written permission.
00022 //
00023 //  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
00024 //  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
00025 //  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00026 //  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027 //  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
00028 //  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00029 //  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00030 //  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00031 //  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00032 //  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
00033 //  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00034 //  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00035 //  SUCH DAMAGE.
00036 //
00038 
00039 #ifndef PQXXOBJECT_TRANSACTION_H
00040 #define PQXXOBJECT_TRANSACTION_H
00041 
00042 #include <pqxx/connection>
00043 #include <pqxx/transaction>
00044 
00045 #include <sigc++/signal.h>
00046 
00047 #include <pqxxobject/exceptions.h>
00048 #include <pqxxobject/query.h>
00049 
00050 namespace pqxxobject
00051 {
00084   class transaction
00085   {
00086   public:
00088     enum state
00089       {
00091         STATE_NONE,
00093         STATE_ABORTED,
00095         STATE_COMMITTED,
00097         STATE_EXECUTING,
00099         STATE_ABORTING,
00101         STATE_COMMITTING
00102       };
00103 
00111     explicit transaction(pqxx::connection& conn,
00112                          pqxx::transaction<>*& tran);
00113 
00114 
00116     virtual ~transaction();
00117 
00128     void begin(const std::string& name);
00129 
00130   protected:
00139     void end();
00140 
00141   public:
00149     pqxx::result exec(const std::string& query);
00150 
00158     pqxx::result exec(const std::ostringstream& query);
00159 
00167     pqxx::result exec(const query& query);
00168 
00177     pqxx::result::size_type exec_noresult(const std::string& query);
00178 
00187     pqxx::result::size_type exec_noresult(const std::ostringstream& query);
00188 
00197     pqxx::result::size_type exec_noresult(const query& query);
00198 
00221     pqxx::result::size_type perform(const std::string& query,
00222                                     pqxx::result::size_type min_rows,
00223                                     pqxx::result::size_type max_rows);
00224 
00247     pqxx::result::size_type perform(const std::ostringstream& query,
00248                                     pqxx::result::size_type min_rows,
00249                                     pqxx::result::size_type max_rows);
00250 
00273     pqxx::result::size_type perform(const query& query,
00274                                     pqxx::result::size_type min_rows,
00275                                     pqxx::result::size_type max_rows);
00276 
00290     void commit();
00291 
00292 
00302     void abort();
00303 
00314     void set_checkpoint(bool checkpoint_exists = true);
00315 
00320     bool get_checkpoint() const;
00321 
00329     SigC::Signal1<void, pqxxobject::transaction&>& signal_commit();
00330 
00338     SigC::Signal1<void, pqxxobject::transaction&>& signal_abort();
00339 
00347     SigC::Signal1<void, pqxxobject::transaction&>& signal_refresh();
00348 
00349   protected:
00357     void _begin(const std::string& name);
00358 
00363     void _end();
00364 
00370     void commit(bool refresh);
00371 
00377     void _commit(bool refresh);
00378 
00384     void abort(bool rollback);
00385 
00391     void _abort(bool rollback);
00392 
00393     // PostgreSQL connection details
00395     pqxx::connection& m_connection;
00397     pqxx::transaction<>*& m_transaction;
00398 
00400     SigC::Signal1<void, pqxxobject::transaction&> m_signal_commit;
00402     SigC::Signal1<void, pqxxobject::transaction&> m_signal_abort;
00404     SigC::Signal1<void, pqxxobject::transaction&> m_signal_refresh;
00405 
00407     state m_state;
00408 
00414     unsigned int m_recursion_level;
00415 
00421     bool m_checkpoint;
00422 
00423   }; // class transaction
00424 
00425 }; // namespace pqxxobject
00426 
00427 #endif // PQXXOBJECT_TRANSACTION_H

Generated on Sat May 22 18:33:58 2004 for pqxxobject API Reference by doxygen 1.3.6-20040222