fintp_udal
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OracleDatabase.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 ORACLEDATABASE_H
22 #define ORACLEDATABASE_H
23 
24 #include "../Database.h"
25 #include "../ConnectionString.h"
26 
27 #ifdef WIN32
28 #define __MSXML_LIBRARY_DEFINED__
29 #include <windows.h>
30 #define sleep(x) Sleep( (x)*1000 )
31 #else
32 #include <unistd.h>
33 #endif
34 
35 #include <string>
36 #include <oci.h>
37 using namespace std;
38 
39 #define MAX_DOCUMENT_LENGTH 8000
40 
41 namespace FinTP
42 {
63  class OracleDatabase : public Database
64  {
65  public :
66 
68  ~OracleDatabase();
69 
74  void BeginTransaction( const bool readonly );
75  void EndTransaction( const TransactionType::TRANSACTION_TYPE transactionType, const bool throwOnError );
76 
84  void Connect( const ConnectionString& connectionString );
85 
92  void Disconnect();
93 
94  // Gets the connected/disconnected status
95  bool IsConnected();
96 
104  void ExecuteNonQuery( const DataCommand::COMMAND_TYPE commType, const string& stringStatement, bool onCursor )
105  {
106  DataCommand nonquery( commType, DataCommand::NONQUERY, stringStatement, false );
107  ParametersVector tempParams;
108  (void)innerExecuteCommand( nonquery, tempParams, onCursor, 0 );
109  }
110 
118  void ExecuteNonQueryCached( const DataCommand::COMMAND_TYPE commType, const string& stringStatement, bool onCursor )
119  {
120  DataCommand nonquery( commType, DataCommand::NONQUERY, stringStatement, true );
121  ParametersVector tempParams;
122  (void)innerExecuteCommand( nonquery, tempParams, onCursor, 0 );
123  }
124 
133  void ExecuteNonQuery( const DataCommand::COMMAND_TYPE commType, const string& stringStatement, const ParametersVector& vectorOfParameters, bool onCursor )
134  {
135  DataCommand nonquery( commType, DataCommand::NONQUERY, stringStatement, false );
136  (void)innerExecuteCommand( nonquery, vectorOfParameters, onCursor, 0 );
137  }
138 
147  void ExecuteNonQueryCached( const DataCommand::COMMAND_TYPE commType, const string& stringStatement, const ParametersVector& vectorOfParameters, bool onCursor )
148  {
149  DataCommand nonquery( commType, DataCommand::NONQUERY, stringStatement, true );
150  (void)innerExecuteCommand( nonquery, vectorOfParameters, onCursor, 0 );
151  }
152 
161  DataSet* ExecuteQuery( const DataCommand::COMMAND_TYPE commType, const string& stringStatement, bool onCursor, const unsigned int fetchRows )
162  {
163  DataCommand query( commType, DataCommand::QUERY, stringStatement, false );
164  ParametersVector tempParams;
165  return innerExecuteCommand( query, tempParams, onCursor, fetchRows );
166  }
167 
177  DataSet* ExecuteQuery( const DataCommand::COMMAND_TYPE commType, const string& stringStatement, const ParametersVector& vectorOfParameters, bool onCursor, const unsigned int fetchRows )
178  {
179  DataCommand query( commType, DataCommand::QUERY, stringStatement, false );
180  return innerExecuteCommand( query, vectorOfParameters, onCursor, fetchRows );
181  }
182 
191  DataSet* ExecuteQueryCached( const DataCommand::COMMAND_TYPE commType, const string& stringStatement, const bool onCursor, const unsigned int fetchRows )
192  {
193  DataCommand queryCached( commType, DataCommand::QUERY, stringStatement, true );
194  ParametersVector tempParams;
195  return innerExecuteCommand( queryCached, tempParams, onCursor, fetchRows );
196  }
197 
207  DataSet* ExecuteQueryCached( const DataCommand::COMMAND_TYPE commType, const string& stringStatement, const ParametersVector& vectorOfParameters, const bool onCursor, const unsigned int fetchRows )
208  {
209  DataCommand queryCached( commType, DataCommand::QUERY, stringStatement, true );
210  return innerExecuteCommand( queryCached, vectorOfParameters, onCursor, fetchRows );
211 
217  }
218 
219  void ReleaseStatement( const bool isCommandCached, const string& key );
220  void ReleaseCursor( const bool checkConn );
221  void RewindCursor() {}
222 
223  private :
224 
225  bool m_IsConnected, m_IsReconnecting;
226 
228 
229  OCIEnv *m_hEnv; // environment handle
230  OCIError *m_hError; // error handle
231  OCISvcCtx *m_hServiceContext; // ServiceContext handle
232  OCISession *m_hSession; // session handle
233  OCIServer *m_hServer; // server handle
234  OCITrans *m_hTransaction; // transaction handle
235  OCIStmt *m_StatementHandle; // statement handle
236  OCIStmt *m_hCursor; // cursor handle
237  OCIRowid *m_HoldCursorRowId; // held rowid
238  xmlctx *m_XmlContext; // XML context required by XDB
239 
240  OCIClobLocator *m_ClobLocator;
241  OCIBlobLocator *m_BlobLocator;
242  OCIClobLocator *m_FetchClobLocator;
243  OCIClobLocator *m_FetchBlobLocator;
244  OCIType *m_ArrayType;
245  // binds for date/timestamp columns in a returned dataset
246  vector< OCIDate** > m_Date;
247  vector< OCIDateTime** > m_Timestamp;
248 
249  CacheManager< string, OCIType* > m_TypeCache;
250 
256  void BindParams( const ParametersVector& vectorOfParameters, const unsigned int startIndex = 1 );
257 
258  DataSet* innerExecuteCommand( const DataCommand& command, const ParametersVector& vectorOfParameters, const bool useCursor = false, const unsigned int fetchRows = 0 );
259 
267  DataSet* executeQuery( DataCommand& command, const bool isCommandCached, const bool useCursor );
268  DataSet* getDataSet( DataCommand& command, const bool isCommandCached, OCIStmt *statementHandle, const bool useCursor );
269 
276  void executeNonQuery( DataCommand& command, const bool isCommandCached, const bool useCursor );
277 
278  // translates transaction type to a Oracle specific value
279  static int getOracleTransactionType( TransactionType::TRANSACTION_TYPE type );
280 
289  string getErrorInformation( dvoid *errorHandle, sword status, ub4 handleType = OCI_HTYPE_ERROR, const bool connCheck = true );
290 
291  OCIType* getMessageType( const string& typeName, const string& userName = "" );
292 
293  void freeOCIArrays( const ParametersVector& vectorOfParameters );
294 
295  void initXmlContext();
296 
297  string RawToString( const OCIRaw* value );
298  OCIRaw* StringToRaw( const string& value );
299 
300  // clears the m_Date, m_Timestamp vectors
301  void ClearDateTimestampBinds();
302  };
303 }
304 
305 #endif // ORACLEDATABASE_H