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

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