• Main Page
  • Classes
  • Files
  • File List

session.h

00001 //-< SESSION.H >-----------------------------------------------------*--------*
00002 // GigaBASE                  Version 1.0         (c) 1999  GARRET    *     ?  *
00003 // (Post Relational Database Management System)                      *   /\|  *
00004 //                                                                   *  /  \  *
00005 //                          Created:     28-Jul-2009  K.A. Knizhnik  * / [] \ *
00006 //                          Last update: 28-Jul-2009  K.A. Knizhnik  * GARRET *
00007 //-------------------------------------------------------------------*--------*
00008 // Remote C++ interface to database 
00009 //-------------------------------------------------------------------*--------*
00010 
00011 #ifndef __SESSION_H__
00012 #define __SESSION_H__
00013 
00014 #include "class.h"
00015 #include "reference.h"
00016 #include "array.h"
00017 #include "query.h"
00018 #include "sockio.h"
00019 #include "exception.h"
00020 
00021 BEGIN_GIGABASE_NAMESPACE
00022 
00026 class ConnectionException : public dbException {
00027   public:
00028     ConnectionException(char const* op, socket_t* s);
00029 };
00030 
00034 class CursorException : public dbException {
00035   public:
00036     CursorException(char const* msg);
00037 };
00038 
00039 
00040 const size_t SOCKET_BUFFER_SIZE = 64*1024;    
00041 
00045 class GIGABASE_DLL_ENTRY dbSession 
00046 {
00047   public:
00056     dbSession(char const* address, 
00057               int max_connect_attempts = 10,
00058               int reconnect_timeout_sec = 1, 
00059               char_t const* user_name = _T(""),
00060               char_t const* password = _T(""));
00061 
00065     ~dbSession();
00066 
00072     template <class T>
00073     void select(dbQuery const& query, size_t limit = 0) {
00074         select(&T::dbDescriptor, query, limit);
00075     }
00076     
00080     void reset();
00081 
00087     template <class T>
00088     dbReference<T> next(T& record) {
00089         return dbReference<T>(next(&T::dbDescriptor, &record));
00090     }
00091 
00099     template <class T>
00100     dbReference<T> insert(T const& record, bool batch = false) {
00101         return dbReference<T>(insert(&T::dbDescriptor, &record, batch));
00102     }
00103 
00109     template <class T>
00110     bool update(T const& record, dbReference<T> ref)
00111     {
00112         return update(&T::dbDescriptor, &record, ref.getOid());
00113     }
00114 
00119     template <class T>
00120     void remove(dbReference<T> ref)
00121     {
00122         remove(&T::dbDescriptor, ref.getOid());
00123     }
00124 
00131     template <class T>
00132     size_t remove(dbQuery const& condition, size_t limit = 0)
00133     {
00134         return remove(&T::dbDescriptor, condition, limit);
00135     }
00136     
00137 
00141     void commit();
00142 
00146     void lock();
00147 
00151     void unlock();
00152 
00156     void rollback();
00157 
00158   private:
00159     oid_t  insert(dbTableDescriptor* table, void const* record, bool batch);
00160     bool   update(dbTableDescriptor* table, void const* record, oid_t oid);
00161     void   remove(dbTableDescriptor* table, oid_t oid);
00162     oid_t  next(dbTableDescriptor* table, void* record);
00163     void   select(dbTableDescriptor* table, dbQuery const& query, size_t limit);
00164     size_t remove(dbTableDescriptor* table, dbQuery const& query, size_t limit);
00165 
00166     void   fillBuffer(size_t size);
00167     void   sendCommand(int cmd);
00168     void   sendQuery(dbTableDescriptor* table, dbQuery const& query, size_t limit, int cmd);
00169     void   reloadSchema();
00170     void   login(char_t const* user_name, char_t const* password);
00171 
00172     socket_t* socket;
00173     char      sockBuf[SOCKET_BUFFER_SIZE];
00174     size_t    bufUsed;
00175     size_t    bufPos;
00176     byte*     currObj;
00177     dbTableDescriptor** tables;
00178     bool      selected;
00179 };
00180 
00181 END_GIGABASE_NAMESPACE
00182 
00183 #endif
00184 

Generated on Mon Aug 23 2010 00:04:01 for GigaBASE by  doxygen 1.7.1