QuickFIX: /home/omiller/Development/autobuild/quickfix/src/C++/PostgreSQLStore.h Source File

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

# PostgreSQLStore.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_POSTGRESQL
    00023 #error PostgreSQLStore.h included, but HAVE_POSTGRESQL not defined
    00024 #endif
    00025
    00026 #ifdef HAVE_POSTGRESQL
    00027 #ifndef FIX_POSTGRESQLSTORE_H
    00028 #define FIX_POSTGRESQLSTORE_H
    00029
    00030 #ifdef _MSC_VER
    00031 #pragma warning( disable : 4503 4355 4786 4290 )
    00032 #endif
    00033
    00034 #include "MessageStore.h"
    00035 #include "SessionSettings.h"
    00036 #include "PostgreSQLConnection.h"
    00037 #include <fstream>
    00038 #include <string>
    00039
    00040 namespace FIX
    00041 {
    00043 class PostgreSQLStoreFactory : public MessageStoreFactory
    00044 {
    00045 public:
    00046   static const std::string DEFAULT_DATABASE;
    00047   static const std::string DEFAULT_USER;
    00048   static const std::string DEFAULT_PASSWORD;
    00049   static const std::string DEFAULT_HOST;
    00050   static const short DEFAULT_PORT;
    00051
    00052   PostgreSQLStoreFactory( const SessionSettings& settings )
    00053 : m_settings( settings ), m_useSettings( true ), m_useDictionary( false )
    00054   {
    00055     bool poolConnections = false;
    00056     try { poolConnections = settings.get().getBool(POSTGRESQL_STORE_USECONNECTIONPOOL); }
    00057     catch( ConfigError& ) {}
    00058
    00059     m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
    00060       ( new PostgreSQLConnectionPool(poolConnections) );
    00061   }
    00062
    00063   PostgreSQLStoreFactory( const Dictionary& dictionary )
    00064 : m_dictionary( dictionary ), m_useSettings( false ), m_useDictionary( true )
    00065   {
    00066     m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
    00067       ( new PostgreSQLConnectionPool(false) );
    00068   }
    00069
    00070   PostgreSQLStoreFactory( const std::string& database, const std::string& user,
    00071                           const std::string& password, const std::string& host,
    00072                           short port )
    00073 : m_database( database ), m_user( user ), m_password( password ), m_host( host ), m_port( port ),
    00074   m_useSettings( false ), m_useDictionary( false )
    00075   {
    00076     m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
    00077       ( new PostgreSQLConnectionPool(false) );
    00078   }
    00079
    00080   PostgreSQLStoreFactory()
    00081 : m_database( DEFAULT_DATABASE ), m_user( DEFAULT_USER ), m_password( DEFAULT_PASSWORD ),
    00082   m_host( DEFAULT_HOST ), m_port( DEFAULT_PORT ), m_useSettings( false ), m_useDictionary( false )
    00083   {
    00084     m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
    00085       ( new PostgreSQLConnectionPool(false) );
    00086   }
    00087
    00088   MessageStore* create( const SessionID& );
    00089   void destroy( MessageStore* );
    00090 private:
    00091   MessageStore* create( const SessionID& s, const Dictionary& );
    00092
    00093   PostgreSQLConnectionPoolPtr m_connectionPoolPtr;
    00094   SessionSettings m_settings;
    00095   Dictionary m_dictionary;
    00096   std::string m_database;
    00097   std::string m_user;
    00098   std::string m_password;
    00099   std::string m_host;
    00100   short m_port;
    00101   bool m_useSettings;
    00102   bool m_useDictionary;
    00103 };
    00106
    00107 class PostgreSQLStore : public MessageStore
    00108 {
    00109 public:
    00110   PostgreSQLStore( const SessionID& s, const DatabaseConnectionID& d, PostgreSQLConnectionPool* p );
    00111   PostgreSQLStore( const SessionID& s, const std::string& database, const std::string& user,
    00112                    const std::string& password, const std::string& host, short port );
    00113   ~PostgreSQLStore();
    00114
    00115   bool set( int, const std::string& ) throw ( IOException );
    00116   void get( int, int, std::vector < std::string > & ) const throw ( IOException );
    00117
    00118   int getNextSenderMsgSeqNum() const throw ( IOException );
    00119   int getNextTargetMsgSeqNum() const throw ( IOException );
    00120   void setNextSenderMsgSeqNum( int value ) throw ( IOException );
    00121   void setNextTargetMsgSeqNum( int value ) throw ( IOException );
    00122   void incrNextSenderMsgSeqNum() throw ( IOException );
    00123   void incrNextTargetMsgSeqNum() throw ( IOException );
    00124
    00125   UtcTimeStamp getCreationTime() const throw ( IOException );
    00126
    00127   void reset() throw ( IOException );
    00128   void refresh() throw ( IOException );
    00129
    00130 private:
    00131   void populateCache();
    00132
    00133   MemoryStore m_cache;
    00134   PostgreSQLConnection* m_pConnection;
    00135   PostgreSQLConnectionPool* m_pConnectionPool;
    00136   SessionID m_sessionID;
    00137 };
    00138 }
    00139
    00140 #endif //FIX_POSTGRESQLSTORE_H
    00141 #endif //HAVE_POSTGRESQL