MySQLStore.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 MySQLStore.h included, but HAVE_MYSQL not defined
24#endif
25
26#ifdef HAVE_MYSQL
27#ifndef FIX_MYSQLSTORE_H
28#define FIX_MYSQLSTORE_H
29
30#ifdef _MSC_VER
31#pragma warning( disable : 4503 4355 4786 4290 )
32#pragma comment( lib, "libMySQL" )
33#endif
34
35#include "MessageStore.h"
36#include "SessionSettings.h"
37#include "MySQLConnection.h"
38#include <fstream>
39#include <string>
40
41namespace FIX
42{
44class MySQLStoreFactory : public MessageStoreFactory
45{
46public:
47 static const std::string DEFAULT_DATABASE;
48 static const std::string DEFAULT_USER;
49 static const std::string DEFAULT_PASSWORD;
50 static const std::string DEFAULT_HOST;
51 static const short DEFAULT_PORT;
52
53 MySQLStoreFactory( const SessionSettings& settings )
54: m_settings( settings ), m_useSettings( true ), m_useDictionary( false )
55 {
56 bool poolConnections = false;
57 try { poolConnections = settings.get().getBool(MYSQL_STORE_USECONNECTIONPOOL); }
58 catch( ConfigError& ) {}
59
60 m_connectionPoolPtr = MySQLConnectionPoolPtr
61 ( new MySQLConnectionPool(poolConnections) );
62 }
63
64 MySQLStoreFactory( const Dictionary& dictionary )
65: m_dictionary( dictionary ), m_useSettings( false ), m_useDictionary( true )
66 {
67 m_connectionPoolPtr = MySQLConnectionPoolPtr
68 ( new MySQLConnectionPool(false) );
69 }
70
71 MySQLStoreFactory( const std::string& database, const std::string& user,
72 const std::string& password, const std::string& host,
73 short port )
74: m_database( database ), m_user( user ), m_password( password ), m_host( host ), m_port( port ),
75 m_useSettings( false ), m_useDictionary( false )
76 {
77 m_connectionPoolPtr = MySQLConnectionPoolPtr
78 ( new MySQLConnectionPool(false) );
79 }
80
81 MySQLStoreFactory()
82: m_database( DEFAULT_DATABASE ), m_user( DEFAULT_USER ), m_password( DEFAULT_PASSWORD ),
83 m_host( DEFAULT_HOST ), m_port( DEFAULT_PORT ), m_useSettings( false ), m_useDictionary( false )
84 {
85 m_connectionPoolPtr = MySQLConnectionPoolPtr
86 ( new MySQLConnectionPool(false) );
87 }
88
89 MessageStore* create( const SessionID& );
90 void destroy( MessageStore* );
91private:
92 MessageStore* create( const SessionID& s, const Dictionary& );
93
94 MySQLConnectionPoolPtr m_connectionPoolPtr;
95 SessionSettings m_settings;
96 Dictionary m_dictionary;
97 std::string m_database;
98 std::string m_user;
99 std::string m_password;
100 std::string m_host;
101 short m_port;
102 bool m_useSettings;
103 bool m_useDictionary;
104};
108class MySQLStore : public MessageStore
109{
110public:
111 MySQLStore( const SessionID& s, const DatabaseConnectionID& d, MySQLConnectionPool* p );
112 MySQLStore( const SessionID& s, const std::string& database, const std::string& user,
113 const std::string& password, const std::string& host, short port );
114 ~MySQLStore();
115
116 bool set( int, const std::string& ) throw ( IOException );
117 void get( int, int, std::vector < std::string > & ) const throw ( IOException );
118
119 int getNextSenderMsgSeqNum() const throw ( IOException );
120 int getNextTargetMsgSeqNum() const throw ( IOException );
121 void setNextSenderMsgSeqNum( int value ) throw ( IOException );
122 void setNextTargetMsgSeqNum( int value ) throw ( IOException );
123 void incrNextSenderMsgSeqNum() throw ( IOException );
124 void incrNextTargetMsgSeqNum() throw ( IOException );
125
126 UtcTimeStamp getCreationTime() const throw ( IOException );
127
128 void reset() throw ( IOException );
129 void refresh() throw ( IOException );
130
131private:
132 void populateCache();
133
134 MemoryStore m_cache;
135 MySQLConnection* m_pConnection;
136 MySQLConnectionPool* m_pConnectionPool;
137 SessionID m_sessionID;
138};
139}
140
141#endif //FIX_MYSQLSTORE_H
142#endif //HAVE_MYSQL

Generated on Sun Mar 31 2024 07:07:24 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001