1 #ifndef _CEGODBHANDLER_H_INCLUDED_
2 #define _CEGODBHANDLER_H_INCLUDED_
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 // CegoDbHandler.h
6 // ---------------
7 // Cego db handler class definition
8 //
9 // Design and Implementation by Bjoern Lemke
10 //
11 // (C)opyright 2000-2019 Bjoern Lemke
12 //
13 // INTERFACE MODULE
14 //
15 // Class: CegoDbHandler
16 //
17 // Description: Database handler class to the access the database backend via network
18 //
19 // Status: CLEAN
20 //
21 ///////////////////////////////////////////////////////////////////////////////
22 
23 // LFC INCLUDES
24 #include <lfcbase/Logger.h>
25 #include <lfcbase/NetHandler.h>
26 #include <lfcxml/XMLSuite.h>
27 
28 // CEGO INCLUDES
29 #include "CegoSerial.h"
30 #include "CegoObject.h"
31 #include "CegoTableObject.h"
32 #include "CegoProcVar.h"
33 #include "CegoBlob.h"
34 #include "CegoClob.h"
35 #include "CegoModule.h"
36 
37 class CegoDbHandler {
38 
39 public:
40 
41     enum ProtocolType { XML, SERIAL, FASTSERIAL };
42 
43     enum RequestType { QUERY,
44 		       QUERYABORT,
45 		       DBPRODINFO,
46 		       INSERT,
47 		       DELETETABLE,
48 		       UPDATE,
49 		       CREATETABLE,
50 		       CREATEVIEW,
51 		       CREATEPROCEDURE,
52 		       ALTERTABLE,
53 		       DROPOBJECT,
54 		       CREATEINDEX,
55 		       CREATECHECK,
56 		       OBJECTINFO,
57 		       GETTABLE,
58 		       GETOBJLIST,
59 		       GETOBJLISTBYTABLE,
60 		       OBJRENAME,
61 		       REORGOBJ,
62 		       SYNC,
63 		       GETPAGECOUNT,
64 		       PUTBLOB,
65 		       GETBLOB,
66 		       DELBLOB,
67 		       PUTCLOB,
68 		       GETCLOB,
69 		       DELCLOB,
70 		       STARTTRANSACTION,
71 		       COMMITTRANSACTION,
72 		       ROLLBACKTRANSACTION,
73 		       GETTID,
74 		       SESSION_CLOSE,
75 		       REQTIMEOUT,
76 		       UNKNOWN };
77 
78     enum ResultType { DB_OK, DB_ERROR, DB_DATA, DB_INFO, DB_FIN };
79 
80 
81     CegoDbHandler(NetHandler *pN, ProtocolType pt, CegoModule *pModule);
82     ~CegoDbHandler();
83 
84     ////////////////////////////////////
85     // client and client node methods //
86     ////////////////////////////////////
87 
88     ResultType requestSession(const Chain& tableSet, const Chain& user, const Chain& password, bool doEncrypt = true);
89     ResultType closeSession();
90     ResultType reqQueryOp(const Chain& cmd);
91     ResultType reqQueryAbort(unsigned long long idx);
92 
93     CegoObject::ObjectType getObjType();
94     Element* getObjElement();
95 
96     const Chain& getMsg();
97     unsigned long long getTid() const;
98 
99     const Chain& getDbName() const;
100     const Chain& getDbVersion() const;
101     const Chain& getDateFormat() const;
102     char getQuoteEscapeFlag() const;
103 
104     unsigned long long getAffected();
105     const ListT<CegoField>& getSchema();
106     const Chain& getFormat();
107 
108     void getProcResult(ListT<CegoProcVar>& outParamList, CegoFieldValue& retValue);
109     ResultType receiveTableData(const ListT<CegoField>& schema);
110     ResultType receiveTableData(const ListT<CegoField>& schema, ListT<CegoFieldValue>& fvl);
111     void abortQuery();
112     void resetQuery();
113     bool wasReset();
114 
115     /////////////////////////
116     // server node methods //
117     /////////////////////////
118 
119     bool acceptSession();
120     RequestType acceptRequest();
121 
122     Chain getQueryArg();
123 
124     void collectSchema(const ListT<CegoField>& schema, const Chain& format = Chain(""));
125     void collectData(const ListT<CegoField>& schema);
126     void collectData(const ListT<CegoField>& schema, const ListT<CegoFieldValue>& fvl);
127 
128     int numCollected() const;
129 
130     void sendCollectedData();
131     void sendFinishData();
132     void sendErrorData(const Chain& msg);
133     void sendProdInfo();
134     void sendObjInfo(CegoDecodableObject& oe);
135 
136     void sendSessionConfirm(const Chain& msg,
137 			    unsigned long long tid,
138 			    const Chain& dbName,
139 			    const Chain& dbVersion,
140 			    const Chain& dateTimeFormat,
141 			    char quoteEscapeFlag);
142 
143     void sendResponse(const Chain& msg, unsigned long long affected = 0 );
144     void sendError(const Chain& msg );
145 
146     void sendBlobInfo(PageIdType pageId);
147     void sendBlobSize(unsigned long long blobSize);
148 
149     ResultType putBlob(CegoBlob& blob);
150     ResultType getBlob(CegoBlob& blob);
151     ResultType delBlob(CegoBlob& blob);
152 
153     void getPutBlobArg(Chain& tableSet, unsigned long long& blobSize);
154     void getGetBlobArg(Chain& tableSet, PageIdType& pageId);
155 
156     void sendClobInfo(PageIdType pageId);
157     void sendClobSize(unsigned long long blobSize);
158 
159     ResultType putClob(CegoClob& clob);
160     ResultType getClob(CegoClob& clob);
161     ResultType delClob(CegoClob& clob);
162 
163     void getPutClobArg(Chain& tableset, unsigned long long& clobSize);
164     void getGetClobArg(Chain& tableset, PageIdType& pageId);
165 
166     void sendProcResult(const Chain& msg, const ListT<CegoProcVar>& outParamList, CegoFieldValue *pRetVal);
167 
168     const Chain& getTableSet();
169     const Chain& getUser();
170     const Chain& getPassword();
171 
172     NetHandler* getNetHandler();
173 
174 protected:
175 
176     ProtocolType _protType;
177 
178     // xml request
179     ResultType sendXMLReq(const Chain& reqType, Element* pRoot);
180 
181     // native serial request
182     ResultType sendSerialReq();
183 
184     ResultType getMoreTableData();
185 
186     NetHandler *_pN;
187     CegoModule *_pModule;
188 
189     Chain _tableSet;
190     Chain _user;
191     Chain _password;
192 
193     // for xml protocol
194     XMLSuite _xml;
195     Element **_pRow;
196     ListT<Element*> _rowList;
197 
198     // for native protocol
199     CegoSerial* _pSer;
200     Chain _serQueryCmd;
201     unsigned long long  _serTid;
202     unsigned long long  _serAffected;
203     Chain _serMsg;
204     Chain _serFormat;
205 
206     Chain _serTableSet;
207     unsigned long long _serBlobSize;
208     unsigned long long _serClobSize;
209 
210     PageIdType _serPageId;
211 
212     bool _serSync;
213     Chain _serDbName;
214     Chain _serDbVersion;
215     Chain _serDateFormat;
216     char _serQuoteEscapeFlag;
217 
218     ListT<CegoField> _serSchema;
219 
220     ListT<CegoProcVar> _outParamList;
221     CegoFieldValue _retValue;
222 
223     bool _wasReset;
224 
225     unsigned long _modId;
226 };
227 
228 #endif
229