PostgreSQLLog.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 
3 /****************************************************************************
4 ** Copyright (c) 2001-2014
5 **
6 ** This file is part of the QuickFIX FIX Engine
7 **
8 ** This file may be distributed under the terms of the quickfixengine.org
9 ** license as defined by quickfixengine.org and appearing in the file
10 ** LICENSE included in the packaging of this file.
11 **
12 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 **
15 ** See http://www.quickfixengine.org/LICENSE for licensing information.
16 **
17 ** Contact ask@quickfixengine.org if any conditions of this licensing are
18 ** not clear to you.
19 **
20 ****************************************************************************/
21 
22 #ifndef HAVE_POSTGRESQL
23 #error PostgreSQLLog.h included, but HAVE_POSTGRESQL not defined
24 #endif
25 
26 #ifdef HAVE_POSTGRESQL
27 #ifndef FIX_POSTGRESQLLOG_H
28 #define FIX_POSTGRESQLLOG_H
29 
30 #ifdef _MSC_VER
31 #pragma warning( disable : 4503 4355 4786 4290 )
32 #endif
33 
34 #include "Log.h"
35 #include "SessionSettings.h"
36 #include "PostgreSQLConnection.h"
37 #include <fstream>
38 #include <string>
39 
40 namespace FIX
41 {
43 class PostgreSQLLog : public Log
44 {
45 public:
46  PostgreSQLLog( const SessionID& s, const DatabaseConnectionID& d, PostgreSQLConnectionPool* p );
47  PostgreSQLLog( const DatabaseConnectionID& d, PostgreSQLConnectionPool* p );
48  PostgreSQLLog( const SessionID& s, const std::string& database, const std::string& user,
49  const std::string& password, const std::string& host, short port );
50  PostgreSQLLog( const std::string& database, const std::string& user,
51  const std::string& password, const std::string& host, short port );
52 
53  ~PostgreSQLLog();
54 
55  void clear();
56  void backup();
57  void setIncomingTable( const std::string& incomingTable )
58  { m_incomingTable = incomingTable; }
59  void setOutgoingTable( const std::string& outgoingTable )
60  { m_outgoingTable = outgoingTable; }
61  void setEventTable( const std::string& eventTable )
62  { m_eventTable = eventTable; }
63 
64  void onIncoming( const std::string& value )
65  { insert( m_incomingTable, value ); }
66  void onOutgoing( const std::string& value )
67  { insert( m_outgoingTable, value ); }
68  void onEvent( const std::string& value )
69  { insert( m_eventTable, value ); }
70 
71 private:
72  void init();
73  void insert( const std::string& table, const std::string value );
74 
75  std::string m_incomingTable;
76  std::string m_outgoingTable;
77  std::string m_eventTable;
78  PostgreSQLConnection* m_pConnection;
79  PostgreSQLConnectionPool* m_pConnectionPool;
80  SessionID* m_pSessionID;
81 };
82 
84 class PostgreSQLLogFactory : public LogFactory
85 {
86 public:
87  static const std::string DEFAULT_DATABASE;
88  static const std::string DEFAULT_USER;
89  static const std::string DEFAULT_PASSWORD;
90  static const std::string DEFAULT_HOST;
91  static const short DEFAULT_PORT;
92 
93  PostgreSQLLogFactory( const SessionSettings& settings )
94 : m_settings( settings ), m_useSettings( true )
95  {
96  bool poolConnections = false;
97  try { poolConnections = settings.get().getBool(POSTGRESQL_LOG_USECONNECTIONPOOL); }
98  catch( ConfigError& ) {}
99 
100  m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
101  ( new PostgreSQLConnectionPool(poolConnections) );
102  }
103 
104  PostgreSQLLogFactory( const std::string& database, const std::string& user,
105  const std::string& password, const std::string& host,
106  short port )
107 : m_database( database ), m_user( user ), m_password( password ), m_host( host ), m_port( port ),
108  m_useSettings( false )
109  {
110  m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
111  ( new PostgreSQLConnectionPool(false) );
112  }
113 
114  PostgreSQLLogFactory()
115 : m_database( DEFAULT_DATABASE ), m_user( DEFAULT_USER ), m_password( DEFAULT_PASSWORD ),
116  m_host( DEFAULT_HOST ), m_port( DEFAULT_PORT ), m_useSettings( false )
117  {
118  m_connectionPoolPtr = PostgreSQLConnectionPoolPtr
119  ( new PostgreSQLConnectionPool(false) );
120  }
121 
122  Log* create();
123  Log* create( const SessionID& );
124  void destroy( Log* );
125 private:
126  void init( const Dictionary& settings, std::string& database,
127  std::string& user, std::string& password,
128  std::string& host, short& port );
129 
130  void initLog( const Dictionary& settings, PostgreSQLLog& log );
131 
132  PostgreSQLConnectionPoolPtr m_connectionPoolPtr;
133  SessionSettings m_settings;
134  std::string m_database;
135  std::string m_user;
136  std::string m_password;
137  std::string m_host;
138  short m_port;
139  bool m_useSettings;
140 };
141 }
142 
143 #endif //FIX_POSTGRESQLLOG_H
144 #endif //HAVE_POSTGRESQL
FIX::POSTGRESQL_LOG_USECONNECTIONPOOL
const char POSTGRESQL_LOG_USECONNECTIONPOOL[]
Definition: SessionSettings.h:127
SessionSettings.h
FIX
Definition: Acceptor.cpp:34
PostgreSQLConnection.h
Log.h

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001