OdbcStore.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* -*- C++ -*- */
  2. /****************************************************************************
  3. ** Copyright (c) 2001-2014
  4. **
  5. ** This file is part of the QuickFIX FIX Engine
  6. **
  7. ** This file may be distributed under the terms of the quickfixengine.org
  8. ** license as defined by quickfixengine.org and appearing in the file
  9. ** LICENSE included in the packaging of this file.
  10. **
  11. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  12. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  13. **
  14. ** See http://www.quickfixengine.org/LICENSE for licensing information.
  15. **
  16. ** Contact ask@quickfixengine.org if any conditions of this licensing are
  17. ** not clear to you.
  18. **
  19. ****************************************************************************/
  20. #ifndef HAVE_ODBC
  21. #error OdbcStore.h included, but HAVE_ODBC not defined
  22. #endif
  23. #ifdef HAVE_ODBC
  24. #ifndef FIX_ODBCSTORE_H
  25. #define FIX_ODBCSTORE_H
  26. #ifdef _MSC_VER
  27. #pragma warning( disable : 4503 4355 4786 4290 )
  28. #endif
  29. #include "OdbcConnection.h"
  30. #include "MessageStore.h"
  31. #include "SessionSettings.h"
  32. #include <fstream>
  33. #include <string>
  34. namespace FIX
  35. {
  36. /// Creates a Odbc based implementation of MessageStore.
  37. class OdbcStoreFactory : public MessageStoreFactory
  38. {
  39. public:
  40. static const std::string DEFAULT_USER;
  41. static const std::string DEFAULT_PASSWORD;
  42. static const std::string DEFAULT_CONNECTION_STRING;
  43. OdbcStoreFactory( const SessionSettings& settings )
  44. : m_settings( settings ), m_useSettings( true ), m_useDictionary( false ) {}
  45. OdbcStoreFactory( const Dictionary& dictionary )
  46. : m_dictionary( dictionary ), m_useSettings( false ), m_useDictionary( true ) {}
  47. OdbcStoreFactory( const std::string& user, const std::string& password,
  48. const std::string& connectionString )
  49. : m_user( user ), m_password( password ), m_connectionString( connectionString ),
  50. m_useSettings( false ), m_useDictionary( false ) {}
  51. OdbcStoreFactory()
  52. : m_user( DEFAULT_USER ), m_password( DEFAULT_PASSWORD ),
  53. m_connectionString( DEFAULT_CONNECTION_STRING ), m_useSettings( false ), m_useDictionary( false ) {}
  54. MessageStore* create( const SessionID& );
  55. void destroy( MessageStore* );
  56. private:
  57. MessageStore* create( const SessionID& s, const Dictionary& );
  58. Dictionary m_dictionary;
  59. SessionSettings m_settings;
  60. std::string m_user;
  61. std::string m_password;
  62. std::string m_connectionString;
  63. bool m_useSettings;
  64. bool m_useDictionary;
  65. };
  66. /*! @} */
  67. /// Odbc based implementation of MessageStore.
  68. class OdbcStore : public MessageStore
  69. {
  70. public:
  71. OdbcStore( const SessionID& s, const std::string& user, const std::string& password,
  72. const std::string& connectionString );
  73. ~OdbcStore();
  74. bool set( int, const std::string& ) throw ( IOException );
  75. void get( int, int, std::vector < std::string > & ) const throw ( IOException );
  76. int getNextSenderMsgSeqNum() const throw ( IOException );
  77. int getNextTargetMsgSeqNum() const throw ( IOException );
  78. void setNextSenderMsgSeqNum( int value ) throw ( IOException );
  79. void setNextTargetMsgSeqNum( int value ) throw ( IOException );
  80. void incrNextSenderMsgSeqNum() throw ( IOException );
  81. void incrNextTargetMsgSeqNum() throw ( IOException );
  82. UtcTimeStamp getCreationTime() const throw ( IOException );
  83. void reset() throw ( IOException );
  84. void refresh() throw ( IOException );
  85. private:
  86. void populateCache();
  87. OdbcConnection* m_pConnection;
  88. MemoryStore m_cache;
  89. SessionID m_sessionID;
  90. };
  91. }
  92. #endif
  93. #endif