Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Connection.cpp

Go to the documentation of this file.
00001 // /******************************************************************************\
00002 // *
00003 // * File:          Connection.cpp
00004 // * Creation date: May 17, 2001 13:11
00005 // * Author:        ClassBuilder
00006 // *                XXXX
00007 // * Purpose:       Method implementations of class 'DOConnection'
00008 // *
00009 // * Modifications: @INSERT_MODIFICATIONS(* )
00010 // * June 29, 2001 11:41 WERS
00011 // *     Deleted method 'LastInsertId'
00012 // *     Updated return type of method 'LastInsertId'
00013 // * May 18, 2001 10:04 WERS
00014 // *     Updated code of method 'GetHdl'
00015 // *     Updated code of method 'Connect'
00016 // * May 17, 2001 15:19 WERS
00017 // *     Added member 'm_database'
00018 // *     Updated code of method 'Connect'
00019 // * May 17, 2001 14:26 WERS
00020 // *     Updated code of method 'GetHdl'
00021 // * May 17, 2001 14:26 WERS
00022 // *     Deleted method 'GetHandle'
00023 // *     Added method 'GetHdl'
00024 // *     Updated member 'm_handle'
00025 // * May 17, 2001 14:24 WERS
00026 // *     Deleted method 'Disconnect'
00027 // *     Added relation 'Connection(DOConnection) <>-->> Query(DOQuery)'
00028 // *     Updated code of method 'ConstructorInclude'
00029 // *     Updated code of method '~DOConnection'
00030 // * May 17, 2001 14:02 WERS
00031 // *     Deleted method 'DOConnection'
00032 // *     Added method 'DOConnection'
00033 // * May 17, 2001 14:01 WERS
00034 // *     Deleted inheritance 'DOConnection'
00035 // *     Added member 'm_username'
00036 // *     Added member 'm_password'
00037 // *     Added member 'm_hostname'
00038 // *     Updated code of method 'GetHandle'
00039 // *     Updated code of method 'Disconnect'
00040 // *     Updated code of method '~DOConnection'
00041 // *     Updated code of method 'DOConnection'
00042 // *     Updated member 'm_handle'
00043 // * May 17, 2001 13:57 WERS
00044 // *     Added method 'GetHandle'
00045 // *     Added method 'Disconnect'
00046 // *     Added method 'Connect'
00047 // *     Added member 'm_handle'
00048 // *     Updated code of method 'DOConnection'
00049 // * May 17, 2001 13:40 WERS
00050 // *     Added method 'DOConnection'
00051 // * May 17, 2001 13:11 WERS
00052 // *     Added method 'DestructorInclude'
00053 // *     Added method 'ConstructorInclude'
00054 // *     Added method '~DOConnection'
00055 // *     Added inheritance 'DOConnection'
00056 // *
00057 // *
00058 // \******************************************************************************/
00059 //@START_USER1
00060 
00065 /* --------------------------------------------------------------
00066 Copyright (C) 2001 LifeLine Networks BV <soap2corba@lifeline.nl>
00067 
00068 This program is free software; you can redistribute it and/or
00069 modify it under the terms of the GNU General Public License
00070 as published by the Free Software Foundation; either
00071 version 2 of the License, or (at your option) any later
00072 version.
00073 
00074 This program is distributed in the hope that it will be useful,
00075 but WITHOUT ANY WARRANTY; without even the implied warranty of
00076 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00077 GNU General Public License for more details.
00078 
00079 You should have received a copy of the GNU General Public License
00080 along with this program; if not, write to the Free Software
00081 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00082 -------------------------------------------------------------- */
00083 
00084 //@END_USER1
00085 
00086 
00087 // Master include file
00088 #include "DbObjects.h"
00089 
00090 
00091 //@START_USER2
00092 //@END_USER2
00093 
00094 
00095 // Static members
00096 
00097 
00101 DOConnection::DOConnection() //@INIT_51
00102     : m_handle()
00103     , m_hostname()
00104     , m_password()
00105     , m_username()
00106     , m_database()
00107 {//@CODE_51
00108     ConstructorInclude();
00109 
00110     // Put in your own code
00111 }//@CODE_51
00112 
00113 
00117 DOConnection::~DOConnection()
00118 {//@CODE_34
00119     DestructorInclude();
00120 
00121     mysql_close (&m_handle);
00122 }//@CODE_34
00123 
00124 
00128 void DOConnection::Connect()
00129 {//@CODE_49
00130     if (mysql_connect (&m_handle, m_hostname, m_username, m_password) != NULL) {
00131         mysql_select_db (&m_handle, m_database);
00132     }
00133     
00134 }//@CODE_49
00135 
00136 
00140 MYSQL* DOConnection::GetHdl()
00141 {//@CODE_146
00142     return &m_handle;
00143 }//@CODE_146
00144 
00145 
00146 //{{AFX DO NOT EDIT CODE BELOW THIS LINE !!!
00147 
00151 void DOConnection::ConstructorInclude()
00152 {
00153     // INIT_MULTI_OWNED_ACTIVE(DOConnection, Connection, DOQuery, Query)
00154    
00155     _firstQuery = (DOQuery*)0;
00156     _lastQuery = (DOQuery*)0;
00157     _countQuery = 0;
00158 }
00159 
00160 
00164 void DOConnection::DestructorInclude()
00165 {
00166     // EXIT_MULTI_OWNED_ACTIVE(DOConnection, Connection, DOQuery, Query)
00167     { for (DOQuery* item = GetFirstQuery(); item; item = GetFirstQuery())
00168           delete item; }
00169 }
00170 
00171 
00172 // Methods for the relation(s) of the class
00173 // METHODS_MULTI_OWNED_ACTIVE(DOConnection, Connection, DOQuery, Query)
00174 void DOConnection::AddQueryFirst(DOQuery* item)
00175 {
00176     
00177     assert(this);
00178 
00179     assert(item);
00180     assert(item->_refConnection == (DOConnection*)0);
00181 
00182     _countQuery++;
00183 
00184     item->_refConnection = this;
00185 
00186     if (_firstQuery)
00187     {
00188         _firstQuery->_prevConnection = item;
00189         item->_nextConnection = _firstQuery;
00190         _firstQuery = item;
00191     }
00192     else
00193         _firstQuery = _lastQuery = item; 
00194 }
00195 
00196 void DOConnection::AddQueryLast(DOQuery* item)
00197 {
00198     
00199     assert(this);
00200 
00201     assert(item);
00202     assert(item->_refConnection == (DOConnection*)0);
00203 
00204     _countQuery++;
00205 
00206     item->_refConnection = this;
00207 
00208     if (_lastQuery)
00209     {
00210         _lastQuery->_nextConnection = item;
00211         item->_prevConnection = _lastQuery;
00212         _lastQuery = item;
00213     }
00214     else
00215         _firstQuery = _lastQuery = item; 
00216 }
00217 
00218 void DOConnection::AddQueryAfter(DOQuery* item, DOQuery* pos)
00219 {
00220     
00221     assert(this);
00222 
00223     assert(item);
00224     assert(item->_refConnection == (DOConnection*)0);
00225 
00226     assert(pos);
00227     assert(pos->_refConnection == this);
00228 
00229     _countQuery++;
00230 
00231     item->_refConnection = this;
00232     item->_prevConnection = pos;
00233     item->_nextConnection = pos->_nextConnection;
00234     pos->_nextConnection  = item;
00235 
00236     if (item->_nextConnection)
00237         item->_nextConnection->_prevConnection = item;
00238     else
00239         _lastQuery = item; 
00240 }
00241 
00242 void DOConnection::AddQueryBefore(DOQuery* item, DOQuery* pos)
00243 {
00244     
00245     assert(this);
00246 
00247     assert(item);
00248     assert(item->_refConnection == (DOConnection*)0);
00249 
00250     assert(pos);
00251     assert(pos->_refConnection == this);
00252 
00253     _countQuery++;
00254 
00255     item->_refConnection = this;
00256     item->_nextConnection = pos;
00257     item->_prevConnection = pos->_prevConnection;
00258     pos->_prevConnection  = item;
00259 
00260     if (item->_prevConnection)
00261         item->_prevConnection->_nextConnection = item;
00262     else
00263         _firstQuery = item; 
00264 }
00265 
00266 void DOConnection::RemoveQuery(DOQuery* item)
00267 {
00268     
00269     assert(this);
00270 
00271     assert(item);
00272     assert(item->_refConnection == this);
00273 
00274     DOConnection::QueryIterator::Check(item);
00275 
00276     _countQuery--;
00277 
00278     if (item->_nextConnection)
00279         item->_nextConnection->_prevConnection = item->_prevConnection;
00280     else
00281         _lastQuery = item->_prevConnection;
00282 
00283     if (item->_prevConnection)
00284         item->_prevConnection->_nextConnection = item->_nextConnection;
00285     else
00286         _firstQuery = item->_nextConnection;
00287 
00288     item->_prevConnection = (DOQuery*)0;
00289     item->_nextConnection = (DOQuery*)0;
00290     item->_refConnection = (DOConnection*)0; 
00291 }
00292 
00293 void DOConnection::DeleteAllQuery()
00294 {
00295     
00296     assert(this);
00297 
00298     for (DOQuery* item = GetFirstQuery(); item; item = GetFirstQuery())
00299           delete item; 
00300 }
00301 
00302 void DOConnection::ReplaceQuery(DOQuery* item, DOQuery* newItem)
00303 {
00304     
00305     assert(this);
00306 
00307     assert(item);
00308     assert(item->_refConnection == this);
00309 
00310     assert(newItem);
00311     assert(newItem->_refConnection == (DOConnection*)0);
00312 
00313     DOConnection::QueryIterator::Check(item, newItem);
00314 
00315     if (item->_nextConnection)
00316         item->_nextConnection->_prevConnection = newItem;
00317     else
00318         _lastQuery = newItem;
00319 
00320     if (item->_prevConnection)
00321         item->_prevConnection->_nextConnection = newItem;
00322     else
00323         _firstQuery = newItem;
00324 
00325     newItem->_nextConnection = item->_nextConnection;
00326     newItem->_prevConnection = item->_prevConnection;
00327     item->_nextConnection = (DOQuery*)0;
00328     item->_prevConnection = (DOQuery*)0;
00329 
00330     item->_refConnection = (DOConnection*)0;
00331     newItem->_refConnection = this; 
00332 }
00333 
00334 DOQuery* DOConnection::GetFirstQuery() const
00335 {
00336     
00337     assert(this);
00338     return _firstQuery; 
00339 }
00340 
00341 DOQuery* DOConnection::GetLastQuery() const
00342 {
00343     
00344     assert(this);
00345     return _lastQuery; 
00346 }
00347 
00348 DOQuery* DOConnection::GetNextQuery(DOQuery* pos) const
00349 {
00350     
00351     assert(this);
00352 
00353     if (pos == (DOQuery*)0)
00354         return _firstQuery;
00355 
00356     assert(pos);
00357     assert(pos->_refConnection == this);
00358 
00359     return pos->_nextConnection; 
00360 }
00361 
00362 DOQuery* DOConnection::GetPrevQuery(DOQuery* pos) const
00363 {
00364     
00365     assert(this);
00366 
00367     if (pos == (DOQuery*)0)
00368         return _lastQuery;
00369 
00370     assert(pos);
00371     assert(pos->_refConnection == this);
00372 
00373     return pos->_prevConnection; 
00374 }
00375 
00376 int DOConnection::GetQueryCount() const
00377 {
00378     
00379     assert(this);
00380     return _countQuery; 
00381 }
00382 
00383 void DOConnection::MoveQueryFirst(DOQuery* item)
00384 {
00385     
00386     assert(item);
00387     assert(item->_refConnection);
00388     item->_refConnection->RemoveQuery(item);
00389     AddQueryFirst(item); 
00390 }
00391 
00392 void DOConnection::MoveQueryLast(DOQuery* item)
00393 {
00394     
00395     assert(item);
00396     assert(item->_refConnection);
00397     item->_refConnection->RemoveQuery(item);
00398     AddQueryLast(item); 
00399 }
00400 
00401 void DOConnection::MoveQueryAfter(DOQuery* item, DOQuery* pos)
00402 {
00403     
00404     assert(item);
00405     assert(item->_refConnection);
00406     item->_refConnection->RemoveQuery(item);
00407     AddQueryAfter(item, pos); 
00408 }
00409 
00410 void DOConnection::MoveQueryBefore(DOQuery* item, DOQuery* pos)
00411 {
00412     
00413     assert(item);
00414     assert(item->_refConnection);
00415     item->_refConnection->RemoveQuery(item);
00416     AddQueryBefore(item, pos); 
00417 }
00418 
00419 void DOConnection::SortQuery(int (*comp)(DOQuery*, DOQuery*))
00420 {
00421     
00422     for (DOQuery* a = GetFirstQuery(); a; a = GetNextQuery(a))
00423     {
00424         DOQuery* b = GetNextQuery(a);
00425 
00426         while (b && (comp(a, b) > 0))
00427         {
00428             DOQuery* c = GetPrevQuery(a);
00429             while (c && (comp(c, b) > 0))
00430                 c = GetPrevQuery(c);
00431 
00432             if (c)
00433                 MoveQueryAfter(b, c);
00434             else
00435                 MoveQueryFirst(b);
00436 
00437             b = GetNextQuery(a);
00438         }
00439     } 
00440 }
00441 // METHODS_ITERATOR_MULTI_ACTIVE(DOConnection, Connection, DOQuery, Query)
00442 DOConnection::QueryIterator* DOConnection::QueryIterator::_first = 0;
00443 DOConnection::QueryIterator* DOConnection::QueryIterator::_last = 0;
00444 
00445 DOConnection::QueryIterator::QueryIterator(
00446     const DOConnection* iterConnection,
00447     int (DOQuery::*method)() const,
00448     DOQuery* refQuery)
00449 {
00450     assert(iterConnection);
00451 
00452     _iterConnection = iterConnection;
00453     _refQuery = _prevQuery = _nextQuery = refQuery;
00454     _prev = (QueryIterator*)0;
00455     _next = (QueryIterator*)0;
00456     _method = method;
00457     if (_last)
00458     {
00459         _last->_next = this;
00460         _prev = _last;
00461         _last = this;
00462     }
00463     else
00464         _first = _last = this;
00465 }
00466 
00467 DOConnection::QueryIterator::QueryIterator(
00468     const DOConnection& iterConnection,
00469     int (DOQuery::*method)() const,
00470     DOQuery* refQuery)
00471 {
00472     assert(&iterConnection);
00473 
00474     _iterConnection = &iterConnection;
00475     _refQuery = _prevQuery = _nextQuery = refQuery;
00476     _prev = (QueryIterator*)0;
00477     _next = (QueryIterator*)0;
00478     _method = method;
00479     if (_last)
00480     {
00481         _last->_next = this;
00482         _prev = _last;
00483         _last = this;
00484     }
00485     else
00486         _first = _last = this;
00487 }
00488 
00489 DOConnection::QueryIterator::QueryIterator(
00490     const QueryIterator& iterator,
00491     int (DOQuery::*method)() const)
00492 {
00493     _iterConnection = iterator._iterConnection;
00494     _refQuery = iterator._refQuery;
00495     _prevQuery = iterator._prevQuery;
00496     _nextQuery = iterator._nextQuery;
00497     _prev = (QueryIterator*)0;
00498     _next = (QueryIterator*)0;
00499     _method = method;
00500     if (_last)
00501     {
00502         _last->_next = this;
00503         _prev = _last;
00504         _last = this;
00505     }
00506     else
00507         _first = _last = this;
00508 }
00509 
00510 DOConnection::QueryIterator::~QueryIterator()
00511 {
00512     if (_next)
00513         _next->_prev = _prev;
00514     else
00515         _last = _prev;
00516 
00517     if (_prev)
00518         _prev->_next = _next;
00519     else
00520         _first = _next;
00521 }
00522 
00523 void DOConnection::QueryIterator::Check(DOQuery* itemQuery)
00524 {
00525     for (QueryIterator* item = _first; item; item = item->_next)
00526     {
00527         if (item->_prevQuery == itemQuery)
00528         {
00529             item->_prevQuery = item->_iterConnection->GetNextQuery(item->_prevQuery);
00530             item->_refQuery = 0;
00531         }
00532         if (item->_nextQuery == itemQuery)
00533         {
00534             item->_nextQuery = item->_iterConnection->GetPrevQuery(item->_nextQuery);
00535             item->_refQuery = 0;
00536         }
00537     }
00538 }
00539 
00540 void DOConnection::QueryIterator::Check(DOQuery* itemQuery, DOQuery* newItemQuery)
00541 {
00542     for (QueryIterator* item = _first; item; item = item->_next)
00543     {
00544         if (item->_refQuery == itemQuery)
00545         {
00546             item->_refQuery = item->_prevQuery = item->_nextQuery = newItemQuery;
00547         }
00548         if (item->_prevQuery == itemQuery)
00549         {
00550             item->_prevQuery = newItemQuery;
00551             item->_refQuery = 0;
00552         }
00553         if (item->_nextQuery == itemQuery)
00554         {
00555             item->_nextQuery = newItemQuery;
00556             item->_refQuery = 0;
00557         }
00558     }
00559 }
00560 
00561 //}}AFX DO NOT EDIT CODE ABOVE THIS LINE !!!
00562 
00563 //@START_USER3
00564 

This documentation is part of the "SOAP to CORBA bridge" project
Copyright © 2000 by Lifeline Networks bv.
All rights are reserved.