00001 // database row base class -*- C++ -*- 00002 // $Id: row_base.h,v 1.9 2004/05/10 19:45:42 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_ROW_BASE_H 00040 #define PQXXOBJECT_ROW_BASE_H 00041 00042 #include <map> 00043 00044 #include <sigc++/object.h> 00045 #include <sigc++/signal.h> 00046 #include <sigc++/object_slot.h> 00047 00048 #include <pqxxobject/field_base.h> 00049 #include <pqxxobject/transaction.h> 00050 00051 namespace pqxxobject 00052 { 00059 class row_base : public SigC::Object 00060 { 00061 public: 00063 enum row_state 00064 { 00069 STATE_UNINITIALISED, 00071 STATE_INITIALISED, 00076 STATE_INCONSISTENT 00077 }; 00078 00079 protected: 00080 typedef std::pair<std::string, field_base *> field_type; 00082 std::map<std::string, field_base *> m_fields; 00083 00085 row_state m_state; 00087 bool m_modified; 00088 00090 SigC::Signal0<void> m_signal_changed; 00092 SigC::Signal0<void> m_signal_refreshed; 00094 SigC::Signal0<void> m_signal_inserted; 00096 SigC::Signal0<void> m_signal_updated; 00098 SigC::Signal0<void> m_signal_erased; 00099 00101 row_base(); 00102 00108 explicit row_base(row_state status, 00109 bool modified=false); 00110 00114 row_base(const row_base& rhs); 00115 00116 public: 00118 virtual ~row_base(); 00119 00124 row_base& operator = (const row_base& rhs); 00125 00130 row_state get_state() const; 00131 00136 bool is_modified() const; 00137 00142 void refresh(pqxxobject::transaction& tran); 00143 00148 void insert(pqxxobject::transaction& tran); 00149 00157 void autoupdate(pqxxobject::transaction& tran); 00158 00163 void update(pqxxobject::transaction& tran); 00164 00169 void erase(pqxxobject::transaction& tran); 00170 00175 void abort(pqxxobject::transaction& tran); 00176 00181 void commit(pqxxobject::transaction& tran); 00182 00187 SigC::Signal0<void>& signal_changed(); 00188 00193 SigC::Signal0<void>& signal_refreshed(); 00194 00199 SigC::Signal0<void>& signal_inserted(); 00200 00205 SigC::Signal0<void>& signal_updated(); 00206 00211 SigC::Signal0<void>& signal_erased(); 00212 00214 void raise_changed(); 00215 00217 void raise_refreshed(); 00218 00220 void raise_inserted(); 00221 00223 void raise_updated(); 00224 00226 void raise_erased(); 00227 00228 00229 protected: 00235 void begin(pqxxobject::transaction& tran); 00236 00243 virtual void refresh_impl(pqxxobject::transaction& tran); 00244 00251 virtual void insert_impl(pqxxobject::transaction& tran); 00252 00259 virtual void update_impl(pqxxobject::transaction& tran); 00260 00267 virtual void erase_impl(pqxxobject::transaction& tran); 00268 00275 virtual void begin_impl(pqxxobject::transaction& tran) = 0; 00276 00283 virtual void abort_impl(pqxxobject::transaction& tran) = 0; 00284 00291 virtual void commit_impl(pqxxobject::transaction& tran) = 0; 00292 00297 virtual bool get_checkpoint() const = 0; 00298 00303 void unset_checkpoint(pqxxobject::transaction& tran); 00304 00305 private: 00310 void connect_signal_handlers(pqxxobject::transaction& tran); 00311 00318 void connect_safe_signal_handlers(pqxxobject::transaction& tran); 00319 00320 }; // class row_base 00321 00322 }; // namespace pqxxobject 00323 00324 #endif // PQXXOBJECT_ROW_BASE_H