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

PostgreSQLLog.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 PostgreSQLLog.h included, but HAVE_POSTGRESQL not defined
00024 #endif
00025 
00026 #ifdef HAVE_POSTGRESQL
00027 #ifndef FIX_POSTGRESQLLOG_H
00028 #define FIX_POSTGRESQLLOG_H
00029 
00030 #ifdef _MSC_VER
00031 #pragma warning( disable : 4503 4355 4786 4290 )
00032 #endif
00033 
00034 #include "Log.h"
00035 #include "SessionSettings.h"
00036 #include "PostgreSQLConnection.h"
00037 #include <fstream>
00038 #include <string>
00039 
00040 namespace FIX
00041 {
00043 class PostgreSQLLog : public Log
00044 {
00045 public:
00046   PostgreSQLLog( const SessionID& s, const DatabaseConnectionID& d, PostgreSQLConnectionPool* p );
00047   PostgreSQLLog( const DatabaseConnectionID& d, PostgreSQLConnectionPool* p );
00048   PostgreSQLLog( const SessionID& s, const std::string& database, const std::string& user,
00049                  const std::string& password, const std::string& host, short port );
00050   PostgreSQLLog( const std::string& database, const std::string& user,
00051                  const std::string& password, const std::string& host, short port );
00052 
00053   ~PostgreSQLLog();
00054 
00055   void clear();
00056   void backup();
00057   void setIncomingTable( const std::string& incomingTable )
00058   { m_incomingTable = incomingTable; }
00059   void setOutgoingTable( const std::string& outgoingTable )
00060   { m_outgoingTable = outgoingTable; }
00061   void setEventTable( const std::string& eventTable )
00062   { m_eventTable = eventTable; }
00063 
00064   void onIncoming( const std::string& value )
00065   { insert( m_incomingTable, value ); }
00066   void onOutgoing( const std::string& value )
00067   { insert( m_outgoingTable, value ); }
00068   void onEvent( const std::string& value )
00069   { insert( m_eventTable, value ); }
00070 
00071 private:
00072   void init();
00073   void insert( const std::string& table, const std::string value );
00074 
00075   std::string m_incomingTable;
00076   std::string m_outgoingTable;
00077   std::string m_eventTable;
00078   PostgreSQLConnection* m_pConnection;
00079   PostgreSQLConnectionPool* m_pConnectionPool;
00080   SessionID* m_pSessionID;
00081 };
00082 
00084 class PostgreSQLLogFactory : public LogFactory
00085 {
00086 public:
00087   static const std::string DEFAULT_DATABASE;
00088   static const std::string DEFAULT_USER;
00089   static const std::string DEFAULT_PASSWORD;
00090   static const std::string DEFAULT_HOST;
00091   static const short DEFAULT_PORT;
00092 
00093   PostgreSQLLogFactory( const SessionSettings& settings )
00094 : m_settings( settings ), m_useSettings( true ) 
00095   {
00096     bool poolConnections = false;
00097     try { poolConnections = settings.get().getBool(POSTGRESQL_LOG_USECONNECTIONPOOL); }
00098     catch( ConfigError& ) {}
00099 
00100     m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
00101       ( new PostgreSQLConnectionPool(poolConnections) );
00102   }
00103 
00104   PostgreSQLLogFactory( const std::string& database, const std::string& user,
00105                         const std::string& password, const std::string& host,
00106                         short port )
00107 : m_database( database ), m_user( user ), m_password( password ), m_host( host ), m_port( port ),
00108   m_useSettings( false ) 
00109   {
00110     m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
00111       ( new PostgreSQLConnectionPool(false) );
00112   }
00113 
00114   PostgreSQLLogFactory()
00115 : m_database( DEFAULT_DATABASE ), m_user( DEFAULT_USER ), m_password( DEFAULT_PASSWORD ),
00116   m_host( DEFAULT_HOST ), m_port( DEFAULT_PORT ), m_useSettings( false ) 
00117   {
00118     m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
00119       ( new PostgreSQLConnectionPool(false) );
00120   }
00121 
00122   Log* create();
00123   Log* create( const SessionID& );
00124   void destroy( Log* );
00125 private:
00126   void init( const Dictionary& settings, std::string& database,
00127              std::string& user, std::string& password,
00128              std::string& host, short& port );
00129 
00130   void initLog( const Dictionary& settings, PostgreSQLLog& log );
00131 
00132   PostgreSQLConnectionPoolPtr m_connectionPoolPtr;
00133   SessionSettings m_settings;
00134   std::string m_database;
00135   std::string m_user;
00136   std::string m_password;
00137   std::string m_host;
00138   short m_port;
00139   bool m_useSettings;
00140 };
00141 }
00142 
00143 #endif //FIX_POSTGRESQLLOG_H
00144 #endif //HAVE_POSTGRESQL

Generated on Mon Apr 5 20:59:51 2010 for QuickFIX by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2001