DCL 3.7.4
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 49 of file SQLDriver.h.

Constructor & Destructor Documentation

◆ SQLDriver()

SQLDriver::SQLDriver ( const String & _name)

Definition at line 100 of file SQLDriver.cpp.

102{
103 __refCount = 0;
105 open(_name);
106}
#define NULL
Definition Config.h:312
SQL::DRIVER_MODULE * __pModuleEntryPoint
Definition SQLDriver.h:79
void open(const String &_name) __DCL_THROWS1(SQLDriverException *)

◆ ~SQLDriver()

SQLDriver::~SQLDriver ( )
virtual

Definition at line 108 of file SQLDriver.cpp.

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

Member Function Documentation

◆ addRef()

long SQLDriver::addRef ( )

◆ close()

void SQLDriver::close ( )

Definition at line 212 of file SQLDriver.cpp.

214{
215 Exception* e = NULL;
216 try {
217 __DCL_ASSERT(refCount() == 0);
219
220 SQL::DRIVER_MODULE* pEntryPoint = __pModuleEntryPoint;
222
223 if (!pEntryPoint->pfnCleanup()) {
224 throw new SQLDriverException(__driverName,
225 SQLDriverException::eCleanupFail,
227 );
228 }
229 }
230 catch (Exception* _e) {
231 e = _e;
232 }
233
234 try {
235 Dll::close();
236 }
237 catch (Exception* _e) {
238 if (e != NULL) {
239 __DCL_TRACE1(L"%ls", _e->toString().data());
240 throw e;
241 }
242 else {
243 throw new SQLDriverException(__driverName, _e);
244 }
245 }
246}
#define __DCL_ASSERT(expr)
Definition Object.h:394
virtual String toString() const
Definition Exception.cpp:40
String getDriverSummary() const
String __driverName
Definition SQLDriver.h:80
long refCount() const
Definition SQLDriver.h:56
bool(* pfnCleanup)()
Definition SQLCore.h:474

◆ closeDriver()

void SQLDriver::closeDriver ( SQLDriver * _pSQLDriver)
static

Definition at line 465 of file SQLDriver.cpp.

467{
468 __DCL_ASSERT(_driver);
469 __DCL_ASSERT(_driver->refCount() == 0);
470 __DCL_ASSERT(__DriverPool__ != NULL);
471
472 Exception* e = NULL;
473
475 try {
476 __DriverPool__->clear(_driver);
477 }
478 catch (Exception* _e) {
479 e = _e;
480 }
482
483 if (e != NULL) {
484 throw e;
485 }
486}
__DCL_BEGIN_NAMESPACE LibState * __LibState__
Definition LibMain.cpp:64
void unlock()
Definition LibState.cpp:64
void clear(SQLDriver *pDriver) __DCL_THROWS1(SQLDriverException *)
InternalMutex lockSQLDriverPool
Definition LibState.h:186

◆ createConnection()

SQL::Connection * SQLDriver::createConnection ( )

Definition at line 248 of file SQLDriver.cpp.

249{
251 SQL::Connection* pNewConnection =
252 __pModuleEntryPoint->pfnCreateConnectionInstance();
253 addRef();
254 return pNewConnection;
255}
long addRef()

◆ destroyConnection()

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

Definition at line 257 of file SQLDriver.cpp.

258{
259 pConnection->destroy();
260 release();
261}
virtual void destroy()=0
long release()
Definition SQLDriver.cpp:93

◆ driverName()

const String & SQLDriver::driverName ( ) const
inline

Definition at line 72 of file SQLDriver.h.

72{ return __driverName; };

◆ getDriver()

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

Definition at line 437 of file SQLDriver.cpp.

439{
440 SQLDriver* r = NULL;
441 Exception* e = NULL;
442
444 try {
445 if (__DriverPool__ == NULL) {
446 __DriverPool__ = new SQLDriverPool();
447 __LibState__->pfnSQLCleanup = cleanupDriverContext;
448 }
449 __DCL_ASSERT(__DriverPool__ != NULL);
450
451 r = __DriverPool__->getDriver(_name);
452 }
453 catch (Exception* _e) {
454 e = _e;
455 }
457
458 if (e != NULL) {
459 throw e;
460 }
461
462 return r;
463}
IOException *size_t r
Definition MediaInfo.cpp:82
SQLDriver(const String &_name) __DCL_THROWS1(SQLDriverException *)
SQLDriver * getDriver(const String &_name) __DCL_THROWS1(SQLDriverException *)
DCLCleanupCallback pfnSQLCleanup
Definition LibState.h:187

◆ getDriverSummary()

String SQLDriver::getDriverSummary ( ) const

Definition at line 263 of file SQLDriver.cpp.

264{
266
267 StringBuilder r = __T("DriverName:") + __driverName;
268 r += __T(", FileName:") + Dll::__filename;
269
270 r += __T(", DCLCVersion:");
271 r.format(L"%u.%u",
274 );
275
276 r += __T(", SQLVersion:");
277 r.format(L"%u.%u",
280 );
281
282 r += L", Build:";
283 r += __pModuleEntryPoint->uBuildFlag ? L"Debug" : L"Release";
284 if (__pModuleEntryPoint->pszBuildTimeStamp) {
285 r += L" ";
286 r += __pModuleEntryPoint->pszBuildTimeStamp;
287 }
288
289 if (__pModuleEntryPoint->pfnInitialize == NULL)
290 r += L", pfnInitialize: (null)";
291 if (__pModuleEntryPoint->pfnInitialize == NULL)
292 r += L", pfnCleanup: (null)";
293 if (__pModuleEntryPoint->pfnCreateConnectionInstance == NULL)
294 r += L", pfnCreateConnectionInstance: (null)";
295
296 if (__pModuleEntryPoint->pszFileVersion) {
297 r += L", FileVersion:";
298 r += __pModuleEntryPoint->pszFileVersion;
299 }
300
301 if (__pModuleEntryPoint->pszServerTitle) {
302 r += L", ServerTitle:";
303 r += __pModuleEntryPoint->pszServerTitle;
304 }
305
306 if (__pModuleEntryPoint->pszDescription) {
307 r += L", Description:";
308 r += __pModuleEntryPoint->pszDescription;
309 }
310 return r;
311}
#define __T(str)
Definition Object.h:60
String __filename
Definition Dll.h:57
#define __VERSION_MINOR(_x)
#define __VERSION_MAJOR(_x)

◆ open()

void SQLDriver::open ( const String & _name)

Definition at line 122 of file SQLDriver.cpp.

124{
126
127 StringBuilder filename = _name
128#ifdef __DCL_DEBUG
129 + __T("D")
130#elif defined(_DEBUG)
131 + __T("Dd")
132#endif
133 ;
134
135 filename +=
136#ifdef __WINNT__
137 __T(".dll")
138#elif defined(__APPLE__)
139 __T(".dylib")
140#else
141 __T(".so")
142#endif
143 ;
144
145 int flags = Dll::DEFAULT
146 #ifdef RTLD_LAZY
147 | RTLD_LAZY
148 #endif
149 ;
150
151 try {
152 Dll::open(filename.toString(), flags);
153 }
154 catch (Exception* _cause) {
155 throw new SQLDriverException(_name, _cause);
156 }
157
158 try {
159 SQL::DRIVER_MODULE* entryPoint = NULL;
160 try {
161 entryPoint = (SQL::DRIVER_MODULE*)getAddress(
163 }
164 catch (Exception* _cause) {
165 throw new SQLDriverException(_name, _cause);
166 }
167
168 if (entryPoint->uSize != sizeof(SQL::DRIVER_MODULE)) {
169 throw new SQLDriverException(_name,
170 SQLDriverException::eInvalidDriverModule);
171 }
172
173 if (__VERSION_MAJOR_MINOR(entryPoint->uVersion)
175 throw new SQLDriverException(_name,
176 SQLDriverException::eInvalidVersion);
177 }
178
179 if (entryPoint->pfnInitialize == NULL
180 || entryPoint->pfnCleanup == NULL
181 || entryPoint->pfnCreateConnectionInstance == NULL) {
182 throw new SQLDriverException(_name,
183 SQLDriverException::eInvalidDriverModule);
184 }
185
186 if (!entryPoint->pfnInitialize()) {
187 throw new SQLDriverException(_name,
188 SQLDriverException::eInitializeFail
189 );
190 }
191
192 __pModuleEntryPoint = entryPoint;
193 __driverName = _name;
194
195 __DCL_TRACE3(__T("Open SQLDriver: %ls (%ls, %ls)\n"),
196 _name.data(),
197 filename.data(),
198 getDriverSummary().data()
199 );
200 }
201 catch (Exception* e) {
202 try {
203 Dll::close();
204 }
205 catch (Exception* _nt) {
206 _nt->destroy();
207 }
208 throw e;
209 }
210}
#define DCL_DSO_ENTRY_POINT_STRING
Definition Config.h:357
#define __DCL_TRACE3(fmt, arg1, arg2, arg3)
Definition Object.h:401
#define DCL_SQL_VERSION
#define __VERSION_MAJOR_MINOR(_x)
uint32_t uVersion
Definition SQLCore.h:470
Connection *(* pfnCreateConnectionInstance)()
Definition SQLCore.h:475
bool(* pfnInitialize)()
Definition SQLCore.h:473

◆ refCount()

long SQLDriver::refCount ( ) const
inline

Definition at line 56 of file SQLDriver.h.

56{ return __refCount; }

◆ release()

long SQLDriver::release ( )

Definition at line 93 of file SQLDriver.cpp.

94{
95 __DCL_ASSERT(__refCount > 0); // __DCL_ASSERT_VALID(this);
96 long n = Thread::decrementAndGet(__refCount);
97 return n;
98}
static long decrementAndGet(volatile long &_n)

Member Data Documentation

◆ __driverName

String SQLDriver::__driverName
protected

Definition at line 80 of file SQLDriver.h.

◆ __pModuleEntryPoint

SQL::DRIVER_MODULE* SQLDriver::__pModuleEntryPoint
protected

Definition at line 79 of file SQLDriver.h.


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