00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 #ifndef LIBLOOKDB_DBCONNECTION_H
00019 #define LIBLOOKDB_DBCONNECTION_H
00020 
00021 
00022 
00023 #include "lookdblibrary.h"
00024 #include "lookdbinterface.h"
00025 #include "lkstring.h"
00026 #include "t_list.h"
00027 
00028 namespace look {
00029 
00030 class DbConnection;
00031 
00032 #ifdef WIN32
00033 template class LOOKDBLIBRARY_DLL LookTLList<DbConnection*>;
00034 #endif
00035 typedef LookTLList<DbConnection*> ConnectionList;
00036 
00038 
00043 class LOOKDBLIBRARY_DLL DbConnection
00044 {
00045 public:
00046 
00048         enum ConnectionStyle
00049         {
00050                 DEFAULT,                 
00051                 AUTO_COMMIT,             
00052                 PERSISTENT_READ_ONLY     
00061         };
00062 
00063         DbConnection( const LookString& theDatabaseName = "",
00064                 const LookString& theUser = "",
00065                 const LookString& thePassword = "");
00066 
00067         DbConnection( const DbConnection& theConnection );
00068 
00069         virtual ~DbConnection();
00070 
00071         bool Connect(void);
00072         void Disconnect(void);
00073 
00074         bool Commit(void) const;
00075         bool Rollback(void) const;
00076 
00077         void SetConnectionStyle( ConnectionStyle theConnectionStyle )
00078         {
00079                 itsConnectionStyle = theConnectionStyle;
00080         }
00081 
00082         ConnectionStyle GetConnectionStyle( void )
00083         {
00084                 return itsConnectionStyle;
00085         }
00086 
00088         LOOK_DBC GetSession( void )
00089         {
00090                 return itsSessionNumber;
00091         }
00092 
00093         static void TerminateConnections( void );
00094 
00095         static DbConnection* GetGlobalConnection( void );
00096         static void SetGlobalConnection( DbConnection* theConnection );
00097 
00098 protected:
00099         LookString itsDatabaseName;
00100         LookString itsUser;
00101         LookString itsPassword;
00102         LOOK_DBC itsSessionNumber;
00103         bool itIsConnected;
00104 
00105         ConnectionStyle itsConnectionStyle; 
00106 
00107         static DbConnection* itsGlobalConnection;
00108 
00109         static ConnectionList itsConnections;
00110 };
00111 
00112 
00113 } 
00114 #endif