DCL 4.0
Loading...
Searching...
No Matches
SQLDriver Class Reference

#include <SQLDriver.h>

Inheritance diagram for SQLDriver:
Dll Object

Public Member Functions

long refCount () const
long addRef ()
long release ()
 SQLDriver (const String &_name) __DCL_THROWS1(SQLDriverException *)
virtual ~SQLDriver ()
void open (const String &_name) __DCL_THROWS1(SQLDriverException *)
void close () __DCL_THROWS1(SQLDriverException *)
const String & driverName () const
String getDriverSummary () const
SQL::ConnectioncreateConnection ()
void destroyConnection (SQL::Connection *pConnection)
Public Member Functions inherited from Object
virtual String toString () const
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Static Public Member Functions

static SQLDrivergetDriver (const String &_name) __DCL_THROWS1(SQLDriverException *)
static void closeDriver (SQLDriver *_pSQLDriver) __DCL_THROWS1(SQLDriverException *)

Protected Attributes

SQL::DRIVER_MODULE__pModuleEntryPoint
String __driverName
Protected Attributes inherited from Dll
void * __handle
String __filename

Additional Inherited Members

Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()

Detailed Description

Definition at line 44 of file SQLDriver.h.

Constructor & Destructor Documentation

◆ SQLDriver()

SQLDriver::SQLDriver ( const String & _name)

Definition at line 101 of file SQLDriver.cpp.

103{
104 __refCount = 0;
106 open(_name);
107}
#define NULL
Definition Config.h:340
SQL::DRIVER_MODULE * __pModuleEntryPoint
Definition SQLDriver.h:74
void open(const String &_name) __DCL_THROWS1(SQLDriverException *)

◆ ~SQLDriver()

SQLDriver::~SQLDriver ( )
virtual

Definition at line 109 of file SQLDriver.cpp.

110{
112 try {
113 close();
114 }
115 catch (SQLDriverException* e) {
116 __DCL_TRACE1(L"Warning SQLDriver::close fail! %ls\n",
117 e->toString().data());
118 e->destroy();
119 }
120 }
121}
#define __DCL_TRACE1(fmt, arg1)
Definition Object.h:376
virtual void destroy()
Definition Exception.cpp:74
virtual String toString() const
Definition SQLDriver.cpp:52
void close() __DCL_THROWS1(SQLDriverException *)

Member Function Documentation

◆ addRef()

long SQLDriver::addRef ( )

◆ close()

void SQLDriver::close ( )

Definition at line 216 of file SQLDriver.cpp.

218{
219 Exception* e = NULL;
220 try {
221 __DCL_ASSERT(refCount() == 0);
223
224 SQL::DRIVER_MODULE* pEntryPoint = __pModuleEntryPoint;
226
227 if (!pEntryPoint->pfnCleanup()) {
228 throw new SQLDriverException(__driverName,
229 SQLDriverException::eCleanupFail,
231 );
232 }
233 }
234 catch (Exception* _e) {
235 e = _e;
236 }
237
238 try {
239 Dll::close();
240 }
241 catch (Exception* _e) {
242 if (e != NULL) {
243 __DCL_TRACE1(L"%ls", _e->toString().data());
244 throw e;
245 }
246 else {
247 throw new SQLDriverException(__driverName, _e);
248 }
249 }
250}
#define __DCL_ASSERT(expr)
Definition Object.h:371
virtual String toString() const
Definition Exception.cpp:40
String getDriverSummary() const
String __driverName
Definition SQLDriver.h:75
long refCount() const
Definition SQLDriver.h:51
bool(* pfnCleanup)()
Definition SQLCore.h:422

◆ closeDriver()

void SQLDriver::closeDriver ( SQLDriver * _pSQLDriver)
static

Definition at line 469 of file SQLDriver.cpp.

471{
472 __DCL_ASSERT(_pSQLDriver);
473 __DCL_ASSERT(_pSQLDriver->refCount() == 0);
474 __DCL_ASSERT(__pDriverPool != NULL);
475
476 Exception* e = NULL;
477
479 try {
480 __pDriverPool->clear(_pSQLDriver);
481 }
482 catch (Exception* _e) {
483 e = _e;
484 }
486
487 if (e != NULL) {
488 throw e;
489 }
490}
__DCL_BEGIN_NAMESPACE LibState * __pLibState
Definition LibMain.cpp:62
void unlock()
Definition LibState.cpp:62
void clear(SQLDriver *pDriver) __DCL_THROWS1(SQLDriverException *)
InternalMutex lockSQLDriverPool
Definition LibState.h:187

◆ createConnection()

SQL::Connection * SQLDriver::createConnection ( )

Definition at line 252 of file SQLDriver.cpp.

253{
255 SQL::Connection* pNewConnection =
256 __pModuleEntryPoint->pfnCreateConnectionInstance();
257 addRef();
258 return pNewConnection;
259}
long addRef()

◆ destroyConnection()

void SQLDriver::destroyConnection ( SQL::Connection * pConnection)

Definition at line 261 of file SQLDriver.cpp.

262{
263 pConnection->destroy();
264 release();
265}
virtual void destroy()=0
long release()
Definition SQLDriver.cpp:94

◆ driverName()

const String & SQLDriver::driverName ( ) const
inline

Definition at line 67 of file SQLDriver.h.

67{ return __driverName; };

◆ getDriver()

SQLDriver * SQLDriver::getDriver ( const String & _name)
static

Definition at line 441 of file SQLDriver.cpp.

443{
444 SQLDriver* r = NULL;
445 Exception* e = NULL;
446
448 try {
449 if (__pDriverPool == NULL) {
450 __pDriverPool = new SQLDriverPool();
451 __pLibState->pfnSQLCleanup = cleanupDriverContext;
452 }
453 __DCL_ASSERT(__pDriverPool != NULL);
454
455 r = __pDriverPool->getDriver(_name);
456 }
457 catch (Exception* _e) {
458 e = _e;
459 }
461
462 if (e != NULL) {
463 throw e;
464 }
465
466 return r;
467}
ByteString r
SQLDriver(const String &_name) __DCL_THROWS1(SQLDriverException *)
SQLDriver * getDriver(const String &_name) __DCL_THROWS1(SQLDriverException *)
DCLCleanupCallback pfnSQLCleanup
Definition LibState.h:188

◆ getDriverSummary()

String SQLDriver::getDriverSummary ( ) const

Definition at line 267 of file SQLDriver.cpp.

268{
270
271 StringBuilder r = __T("DriverName:") + __driverName;
272 r += __T(", FileName:") + Dll::__filename;
273
274 r += __T(", DCLVersion:");
275 r.format(L"%u.%u",
278 );
279
280 r += __T(", InterfaceVersion:");
281 r.format(L"%u.%u",
284 );
285
286 r += L", Build:";
287 r += __pModuleEntryPoint->uBuildFlag ? L"Debug" : L"Release";
288 if (__pModuleEntryPoint->pszBuildTimeStamp) {
289 r += L" ";
290 r += __pModuleEntryPoint->pszBuildTimeStamp;
291 }
292
293 if (__pModuleEntryPoint->pfnInitialize == NULL)
294 r += L", pfnInitialize: (null)";
295 if (__pModuleEntryPoint->pfnInitialize == NULL)
296 r += L", pfnCleanup: (null)";
297 if (__pModuleEntryPoint->pfnCreateConnectionInstance == NULL)
298 r += L", pfnCreateConnectionInstance: (null)";
299
300 if (__pModuleEntryPoint->pszFileVersion) {
301 r += L", FileVersion:";
302 r += __pModuleEntryPoint->pszFileVersion;
303 }
304
305 if (__pModuleEntryPoint->pszServerTitle) {
306 r += L", ServerTitle:";
307 r += __pModuleEntryPoint->pszServerTitle;
308 }
309
310 if (__pModuleEntryPoint->pszDescription) {
311 r += L", Desc:";
312 r += __pModuleEntryPoint->pszDescription;
313 }
314 return r;
315}
#define DCL_MINOR_VERSION(uVersion)
Definition Config.h:373
#define DCL_MAJOR_VERSION(uVersion)
Definition Config.h:372
#define __T(str)
Definition Object.h:44
String __filename
Definition Dll.h:58

◆ open()

void SQLDriver::open ( const String & _name)

Definition at line 123 of file SQLDriver.cpp.

125{
127
128 StringBuilder filename = _name
129#ifdef __DCL_DEBUG
130 + __T("d")
131#elif defined(_DEBUG)
132 + __T("dd")
133#endif
134 ;
135
136 filename +=
137#if __DCL_WINDOWS
138 __T(".dll")
139#else
140 __T(".so")
141#endif
142 ;
143
144 int flags = Dll::DEFAULT
145 #ifdef RTLD_LAZY
146 | RTLD_LAZY
147 #endif
148 ;
149
150 try {
151 Dll::open(filename.toString(), flags);
152 }
153 catch (Exception* cause) {
154 throw new SQLDriverException(_name, cause);
155 }
156
157 try {
158 SQL::DRIVER_MODULE* pEntryPoint = NULL;
159 try {
160 pEntryPoint = (SQL::DRIVER_MODULE*)getAddress(
162 }
163 catch (Exception* cause) {
164 throw new SQLDriverException(_name, cause);
165 }
166
167 if (pEntryPoint->uSize != sizeof(SQL::DRIVER_MODULE)) {
168 throw new SQLDriverException(_name,
169 SQLDriverException::eInvalidDriverModule);
170 }
171
172 if (pEntryPoint->uDCLVersion != DCL_VERSION
173 || pEntryPoint->uBuildFlag != DCL_BUILD_FLAG) {
174 throw new SQLDriverException(_name,
175 SQLDriverException::eInvalidDriverModule);
176 }
177
178 if (pEntryPoint->uVersion != DCL_SQL_VERSION) {
179 throw new SQLDriverException(_name,
180 SQLDriverException::eInvalidVersion);
181 }
182
183 if (pEntryPoint->pfnInitialize == NULL
184 || pEntryPoint->pfnCleanup == NULL
185 || pEntryPoint->pfnCreateConnectionInstance == NULL) {
186 throw new SQLDriverException(_name,
187 SQLDriverException::eInvalidDriverModule);
188 }
189
190 if (!pEntryPoint->pfnInitialize()) {
191 throw new SQLDriverException(_name,
192 SQLDriverException::eInitializeFail
193 );
194 }
195
196 __pModuleEntryPoint = pEntryPoint;
197 __driverName = _name;
198
199 __DCL_TRACE3(__T("Open SQLDriver: %ls (%ls, %ls)\n"),
200 _name.data(),
201 filename.data(),
202 getDriverSummary().data()
203 );
204 }
205 catch (Exception* e) {
206 try {
207 Dll::close();
208 }
209 catch (Exception* _nt) {
210 _nt->destroy();
211 }
212 throw e;
213 }
214}
#define DCL_BUILD_FLAG
Definition Config.h:399
#define DCL_DSO_ENTRY_POINT_STRING
Definition Config.h:394
#define DCL_SQL_VERSION
Definition Config.h:381
#define DCL_VERSION
Definition Config.h:376
#define __DCL_TRACE3(fmt, arg1, arg2, arg3)
Definition Object.h:378
uint32_t uDCLVersion
Definition SQLCore.h:411
uint32_t uBuildFlag
Definition SQLCore.h:413
uint32_t uVersion
Definition SQLCore.h:418
Connection *(* pfnCreateConnectionInstance)()
Definition SQLCore.h:423
bool(* pfnInitialize)()
Definition SQLCore.h:421

◆ refCount()

long SQLDriver::refCount ( ) const
inline

Definition at line 51 of file SQLDriver.h.

51{ return __refCount; }

◆ release()

long SQLDriver::release ( )

Definition at line 94 of file SQLDriver.cpp.

95{
96 __DCL_ASSERT(__refCount > 0); // __DCL_ASSERT_VALID(this);
97 long n = Thread::decrementAndGet(__refCount);
98 return n;
99}
void CharsetConvertException *size_t n
Definition SQLField.cpp:253
static long decrementAndGet(volatile long &_n)

Member Data Documentation

◆ __driverName

String SQLDriver::__driverName
protected

Definition at line 75 of file SQLDriver.h.

◆ __pModuleEntryPoint

SQL::DRIVER_MODULE* SQLDriver::__pModuleEntryPoint
protected

Definition at line 74 of file SQLDriver.h.


The documentation for this class was generated from the following files: