Index Source Files Annotated Class List Alphabetical Class List Class Hierarchy Graphical Class Hierarchy

# MySQLStore.h

Go to the documentation of this file.

    00001 /* -*- C++ -*- */
    00002
    00003 /****************************************************************************
    00004 ** Copyright (c) quickfixengine.org  All rights reserved.
    00005 **
    00006 ** This file is part of the QuickFIX FIX Engine
    00007 **
    00008 ** This file may be distributed under the terms of the quickfixengine.org
    00009 ** license as defined by quickfixengine.org and appearing in the file
    00010 ** LICENSE included in the packaging of this file.
    00011 **
    00012 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
    00013 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    00014 **
    00015 ** See http://www.quickfixengine.org/LICENSE for licensing information.
    00016 **
    00017 ** Contact ask@quickfixengine.org if any conditions of this licensing are
    00018 ** not clear to you.
    00019 **
    00020 ****************************************************************************/
    00021
    00022 #ifndef HAVE_MYSQL
    00023 #error MySQLStore.h included, but HAVE_MYSQL not defined
    00024 #endif
    00025
    00026 #ifdef HAVE_MYSQL
    00027 #ifndef FIX_MYSQLSTORE_H
    00028 #define FIX_MYSQLSTORE_H
    00029
    00030 #ifdef _MSC_VER
    00031 #pragma warning( disable : 4503 4355 4786 4290 )
    00032 #pragma comment( lib, "libMySQL" )
    00033 #endif
    00034
    00035 #include "MessageStore.h"
    00036 #include "SessionSettings.h"
    00037 #include "MySQLConnection.h"
    00038 #include <fstream>
    00039 #include <string>
    00040
    00041 namespace FIX
    00042 {
    00044 class MySQLStoreFactory : public MessageStoreFactory
    00045 {
    00046 public:
    00047   static const std::string DEFAULT_DATABASE;
    00048   static const std::string DEFAULT_USER;
    00049   static const std::string DEFAULT_PASSWORD;
    00050   static const std::string DEFAULT_HOST;
    00051   static const short DEFAULT_PORT;
    00052
    00053   MySQLStoreFactory( const SessionSettings& settings )
    00054 : m_settings( settings ), m_useSettings( true ), m_useDictionary( false )
    00055   {
    00056     bool poolConnections = false;
    00057     try { poolConnections = settings.get().getBool(MYSQL_STORE_USECONNECTIONPOOL); }
    00058     catch( ConfigError& ) {}
    00059
    00060     m_connectionPoolPtr = MySQLConnectionPoolPtr
    00061       ( new MySQLConnectionPool(poolConnections) );
    00062   }
    00063
    00064   MySQLStoreFactory( const Dictionary& dictionary )
    00065 : m_dictionary( dictionary ), m_useSettings( false ), m_useDictionary( true )
    00066   {
    00067     m_connectionPoolPtr = MySQLConnectionPoolPtr
    00068       ( new MySQLConnectionPool(false) );
    00069   }
    00070
    00071   MySQLStoreFactory( const std::string& database, const std::string& user,
    00072                      const std::string& password, const std::string& host,
    00073                      short port )
    00074 : m_database( database ), m_user( user ), m_password( password ), m_host( host ), m_port( port ),
    00075   m_useSettings( false ), m_useDictionary( false )
    00076   {
    00077     m_connectionPoolPtr = MySQLConnectionPoolPtr
    00078       ( new MySQLConnectionPool(false) );
    00079   }
    00080
    00081   MySQLStoreFactory()
    00082 : m_database( DEFAULT_DATABASE ), m_user( DEFAULT_USER ), m_password( DEFAULT_PASSWORD ),
    00083   m_host( DEFAULT_HOST ), m_port( DEFAULT_PORT ), m_useSettings( false ), m_useDictionary( false )
    00084   {
    00085     m_connectionPoolPtr = MySQLConnectionPoolPtr
    00086       ( new MySQLConnectionPool(false) );
    00087   }
    00088
    00089   MessageStore* create( const SessionID& );
    00090   void destroy( MessageStore* );
    00091 private:
    00092   MessageStore* create( const SessionID& s, const Dictionary& );
    00093
    00094   MySQLConnectionPoolPtr m_connectionPoolPtr;
    00095   SessionSettings m_settings;
    00096   Dictionary m_dictionary;
    00097   std::string m_database;
    00098   std::string m_user;
    00099   std::string m_password;
    00100   std::string m_host;
    00101   short m_port;
    00102   bool m_useSettings;
    00103   bool m_useDictionary;
    00104 };
    00107
    00108 class MySQLStore : public MessageStore
    00109 {
    00110 public:
    00111   MySQLStore( const SessionID& s, const DatabaseConnectionID& d, MySQLConnectionPool* p );
    00112   MySQLStore( const SessionID& s, const std::string& database, const std::string& user,
    00113                    const std::string& password, const std::string& host, short port );
    00114   ~MySQLStore();
    00115
    00116   bool set( int, const std::string& ) throw ( IOException );
    00117   void get( int, int, std::vector < std::string > & ) const throw ( IOException );
    00118
    00119   int getNextSenderMsgSeqNum() const throw ( IOException );
    00120   int getNextTargetMsgSeqNum() const throw ( IOException );
    00121   void setNextSenderMsgSeqNum( int value ) throw ( IOException );
    00122   void setNextTargetMsgSeqNum( int value ) throw ( IOException );
    00123   void incrNextSenderMsgSeqNum() throw ( IOException );
    00124   void incrNextTargetMsgSeqNum() throw ( IOException );
    00125
    00126   UtcTimeStamp getCreationTime() const throw ( IOException );
    00127
    00128   void reset() throw ( IOException );
    00129   void refresh() throw ( IOException );
    00130
    00131 private:
    00132   void populateCache();
    00133
    00134   MemoryStore m_cache;
    00135   MySQLConnection* m_pConnection;
    00136   MySQLConnectionPool* m_pConnectionPool;
    00137   SessionID m_sessionID;
    00138 };
    00139 }
    00140
    00141 #endif //FIX_MYSQLSTORE_H
    00142 #endif //HAVE_MYSQL