MySQLLog.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_MYSQL
23 #error MySQLLog.h included, but HAVE_MYSQL not defined
24 #endif
25 
26 #ifdef HAVE_MYSQL
27 #ifndef FIX_MYSQLLOG_H
28 #define FIX_MYSQLLOG_H
29 
30 #ifdef _MSC_VER
31 #pragma warning( disable : 4503 4355 4786 4290 )
32 #pragma comment( lib, "libMySQL" )
33 #endif
34 
35 #include "Log.h"
36 #include "SessionSettings.h"
37 #include "MySQLConnection.h"
38 #include <fstream>
39 #include <string>
40 
41 namespace FIX
42 {
44 class MySQLLog : public Log
45 {
46 public:
47  MySQLLog( const SessionID& s, const DatabaseConnectionID& d, MySQLConnectionPool* p );
48  MySQLLog( const DatabaseConnectionID& d, MySQLConnectionPool* p );
49  MySQLLog( const SessionID& s, const std::string& database, const std::string& user,
50  const std::string& password, const std::string& host, short port );
51  MySQLLog( const std::string& database, const std::string& user,
52  const std::string& password, const std::string& host, short port );
53 
54  ~MySQLLog();
55 
56  void clear();
57  void backup();
58  void setIncomingTable( const std::string& incomingTable )
59  { m_incomingTable = incomingTable; }
60  void setOutgoingTable( const std::string& outgoingTable )
61  { m_outgoingTable = outgoingTable; }
62  void setEventTable( const std::string& eventTable )
63  { m_eventTable = eventTable; }
64 
65  void onIncoming( const std::string& value )
66  { insert( m_incomingTable, value ); }
67  void onOutgoing( const std::string& value )
68  { insert( m_outgoingTable, value ); }
69  void onEvent( const std::string& value )
70  { insert( m_eventTable, value ); }
71 
72 private:
73  void init();
74  void insert( const std::string& table, const std::string value );
75 
76  std::string m_incomingTable;
77  std::string m_outgoingTable;
78  std::string m_eventTable;
79  MySQLConnection* m_pConnection;
80  MySQLConnectionPool* m_pConnectionPool;
81  SessionID* m_pSessionID;
82 };
83 
85 class MySQLLogFactory : public LogFactory
86 {
87 public:
88  static const std::string DEFAULT_DATABASE;
89  static const std::string DEFAULT_USER;
90  static const std::string DEFAULT_PASSWORD;
91  static const std::string DEFAULT_HOST;
92  static const short DEFAULT_PORT;
93 
94  MySQLLogFactory( const SessionSettings& settings )
95 : m_settings( settings ), m_useSettings( true )
96  {
97  bool poolConnections = false;
98  try { poolConnections = settings.get().getBool(MYSQL_LOG_USECONNECTIONPOOL); }
99  catch( ConfigError& ) {}
100 
101  m_connectionPoolPtr = MySQLConnectionPoolPtr
102  ( new MySQLConnectionPool(poolConnections) );
103  }
104 
105  MySQLLogFactory( const std::string& database, const std::string& user,
106  const std::string& password, const std::string& host,
107  short port )
108 : m_database( database ), m_user( user ), m_password( password ), m_host( host ), m_port( port ),
109  m_useSettings( false )
110  {
111  m_connectionPoolPtr = MySQLConnectionPoolPtr
112  ( new MySQLConnectionPool(false) );
113  }
114 
115  MySQLLogFactory()
116 : m_database( DEFAULT_DATABASE ), m_user( DEFAULT_USER ), m_password( DEFAULT_PASSWORD ),
117  m_host( DEFAULT_HOST ), m_port( DEFAULT_PORT ), m_useSettings( false )
118  {
119  m_connectionPoolPtr = MySQLConnectionPoolPtr
120  ( new MySQLConnectionPool(false) );
121  }
122 
123  Log* create();
124  Log* create( const SessionID& );
125  void destroy( Log* );
126 private:
127  void init( const Dictionary& settings, std::string& database,
128  std::string& user, std::string& password,
129  std::string& host, short& port );
130 
131  void initLog( const Dictionary& settings, MySQLLog& log );
132 
133  MySQLConnectionPoolPtr m_connectionPoolPtr;
134  SessionSettings m_settings;
135  std::string m_database;
136  std::string m_user;
137  std::string m_password;
138  std::string m_host;
139  short m_port;
140  bool m_useSettings;
141 };
142 }
143 
144 #endif //FIX_MYSQLLOG_H
145 #endif //HAVE_MYSQL
SessionSettings.h
MySQLConnection.h
FIX::MYSQL_LOG_USECONNECTIONPOOL
const char MYSQL_LOG_USECONNECTIONPOOL[]
Definition: SessionSettings.h:118
FIX
Definition: Acceptor.cpp:34
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