fintp_connectors
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
DbPublisher.h
Go to the documentation of this file.
1 /*
2 * FinTP - Financial Transactions Processing Application
3 * Copyright (C) 2013 Business Information Systems (Allevo) S.R.L.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>
17 * or contact Allevo at : 031281 Bucuresti, 23C Calea Vitan, Romania,
18 * phone +40212554577, office@allevo.ro <mailto:office@allevo.ro>, www.allevo.ro.
19 */
20 
21 #ifndef DBPUBLISHER_H
22 #define DBPUBLISHER_H
23 
24 #include "MQ/MqWatcher.h"
25 #include "DB/DbWatcher.h"
26 #include "Database.h"
27 #include "DatabaseProvider.h"
28 #include "DB/DbDad.h"
29 #include "XPathHelper.h"
30 
31 #include "CacheManager.h"
32 
33 #include "../Endpoint.h"
34 
35 // holds information about conenctors and duplicate detection settings
37 {
38  private:
39 
40  map< string, string > m_Services;
41  bool m_Active;
42 
43  public:
44 
45  ConnectorsDDInfo() : m_Active( false ) {};
46 
47  void GetDuplicateServices( DatabaseProviderFactory *databaseProvider, const string& databaseName, const string& user, const string& password );
48 
49  bool IsDDActive( const string& connectorName )
50  {
51  if ( !m_Active )
52  return false;
53  else
54  {
55  if ( m_Services.find( connectorName ) == m_Services.end() )
56  return false;
57  return ( m_Services[ connectorName ].length() > 0 );
58  }
59  }
60 
61  const string Hash( const string& connectorName, const string& payload );
62 };
63 
64 //Mq to Database
66 {
67  protected :
68 
69  // methods for controlling the endpoint
70  void internalStart();
71  void internalStop();
72 
73  public:
74 
75  // constructor
76  DbPublisher();
77 
78  //destructor
79  ~DbPublisher();
80 
81  // called before start. allows the endpoint to prepare environment
82  void Init();
83 
84  // methods for transactional execution
87  //Connect to database
88  string Prepare();
89 
91  void Commit();
92 
94  void Abort();
95 
97  void Rollback();
98 
101  void Process( const string& correlationId );
102  pthread_t getWatcherThreadId() { return m_Watcher.getThreadId(); }
103 
104  bool moreMessages() const { return !m_IsLast; }
105 
106  private:
107 
109 
110  MqWatcher m_Watcher; // MQSeries watcher
111 
112  string m_WatchQueue;
116 
120 
121  string m_BlobLocator; // simplified xpath to locate the blob in the payload ( ex. /root/IDIMAGINE )
122  string m_BlobFilePattern; // folder+filename containing {xpats}s ( ex : c:\blobs\{/root/BATCHID}_{/root/IMAGEREF}.tiff )
124 
126  string m_DatabaseName; // QPI Database name
127  string m_TableName; // QPI Table name
128  string m_RepliesTableName; // QPI Table name
129  string m_UserName; // QPI database user
130  string m_UserPassword; // QPI user password
131 
132  DbDad::DadOptions m_DadOptions; // Dad options : choose if we use a dad, if we generate the param vectors or insert with values statement
133  string m_AckDadFileName; // Ack dad, file describe how to put ack
134  string m_SPinsertXmlData; // Stored procedure that insert XML into QPI tables
135 
138  unsigned long m_CurrentMessageLength;
139 
140  CacheManager< string, string > m_DadCache;
141 
142  string getDad( const string& dadFilename );
143 
144  Database *m_CurrentDatabase;
145  DatabaseProviderFactory *m_CurrentProvider;
146  DbDad *m_Dad;
147 
150 
153 
154  void UploadMessage( const string& theDadFileName, const string& xmlData, const string& xmlTable, const string& hash );
155  string SaveBlobToFile( const string& xmlData );
156 };
157 
158 #endif