39 #ifndef _QORE_MANAGEDDATASOURCE_H
40 #define _QORE_MANAGEDDATASOURCE_H
42 #include "qore/intern/DatasourceStatementHelper.h"
43 #include "qore/intern/QoreSQLStatement.h"
48 #define DEFAULT_TL_TIMEOUT 120000
51 friend class DatasourceActionHelper;
52 friend class DatasourceLockHelper;
65 DLLLOCAL
int startDBAction(
ExceptionSink* xsink,
bool& new_transaction);
67 DLLLOCAL
bool endDBActionIntern(
char cmd = DAH_NOCHANGE,
bool new_transaction =
false);
69 DLLLOCAL
bool endDBAction(
char cmd = DAH_NOCHANGE,
bool new_transaction =
false);
72 DLLLOCAL
int grabLockIntern();
73 DLLLOCAL
void grabLockUnconditionalIntern();
76 DLLLOCAL
void releaseLock();
77 DLLLOCAL
void releaseLockIntern();
78 DLLLOCAL
void forceReleaseLockIntern();
79 DLLLOCAL
void finish_transaction();
82 DLLLOCAL
virtual ~ManagedDatasource() {
86 DLLLOCAL ManagedDatasource(
DBIDriver *ndsl) :
Datasource(ndsl, this), tl_timeout_ms(DEFAULT_TL_TIMEOUT) {
89 DLLLOCAL ManagedDatasource(
const ManagedDatasource& old) :
Datasource(old, this), tl_timeout_ms(old.tl_timeout_ms) {
95 DLLLOCAL
virtual void deref();
111 DLLLOCAL
void setPendingUsername(
const char* u);
112 DLLLOCAL
void setPendingPassword(
const char* p);
113 DLLLOCAL
void setPendingDBName(
const char* d);
114 DLLLOCAL
void setPendingDBEncoding(
const char* c);
115 DLLLOCAL
void setPendingHostName(
const char* h);
116 DLLLOCAL
void setPendingPort(
int port);
122 DLLLOCAL
int getPendingPort()
const;
123 DLLLOCAL
void setTransactionLockTimeout(
int t_ms);
124 DLLLOCAL
int getTransactionLockTimeout()
const;
128 using Datasource::setAutoCommit;
132 DLLLOCAL ManagedDatasource*
copy();
141 DLLLOCAL
int transactionTid()
const {
145 DLLLOCAL
bool currentThreadInTransaction()
const {
156 DLLLOCAL
virtual DatasourceStatementHelper* helperRefSelfImpl() {
162 DLLLOCAL
virtual void helperDestructorImpl(QoreSQLStatement* s,
ExceptionSink* xsink) {
167 if (!startDBAction(xsink, new_transaction))
171 return tid ==
q_gettid() ? this : 0;
177 if (cmd == DAH_RELEASE) {
180 return endDBAction(cmd, new_transaction) ? this : 0;
184 class DatasourceActionHelper {
186 ManagedDatasource& ds;
187 bool ok, new_transaction;
191 DLLLOCAL DatasourceActionHelper(ManagedDatasource& n_ds,
ExceptionSink* xsink,
char n_cmd = DAH_NOCHANGE) :
192 ds(n_ds), ok(n_cmd == DAH_NOCONN ? !ds.acquireLock(xsink) : !ds.startDBAction(xsink, new_transaction)), cmd(n_cmd) {
193 if (cmd == DAH_NOCONN) {
194 new_transaction =
false;
198 DLLLOCAL ~DatasourceActionHelper();
200 DLLLOCAL
bool newTransaction()
const {
return new_transaction; }
202 DLLLOCAL
operator bool()
const {
return ok; }
205 class DatasourceLockHelper {
207 ManagedDatasource& ds;
208 bool valid, had_lock;
211 DLLLOCAL DatasourceLockHelper(ManagedDatasource& n_ds,
ExceptionSink* xsink) : ds(n_ds) {
214 valid = !ds.grabLock(xsink);
219 DLLLOCAL ~DatasourceLockHelper() {
222 ds.releaseLockIntern();
227 DLLLOCAL
operator bool()
const {
return valid; }
DLLLOCAL void ref() const
increments the reference count of the object
Definition: AbstractPrivateData.h:51
base class for saving data using Qore's thread resource management system
Definition: AbstractThreadResource.h:51
this class provides the internal link to the database driver for Qore's DBI layer
Definition: DBI.h:354
the base class for accessing databases in Qore through a Qore DBI driver
Definition: Datasource.h:55
DLLEXPORT QoreStringNode * getConfigString() const
returns a string representing the configuration of the current object
DLLEXPORT Datasource * copy() const
returns a copy of this object with the same DBIDriver and pending connection values
DLLEXPORT int autoCommit(ExceptionSink *xsink)
called from subclasses when releasing the transaction lock
DLLEXPORT QoreHashNode * getOptionHash() const
returns the valid options for this driver with descriptions and current values for the current dataso...
DLLEXPORT int close()
closes the connection
DLLEXPORT QoreValue execRaw(const QoreString *query_str, const QoreListNode *args, ExceptionSink *xsink)
executes SQL throught the "execRaw" function of the DBI driver and returns the result,...
DLLEXPORT QoreHashNode * getConfigHash() const
returns a hash representing the configuration of the current object
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
a thread condition class implementing a wrapper for pthread_cond_t
Definition: QoreCondition.h:45
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
provides a mutually-exclusive thread lock
Definition: QoreThreadLock.h:49
DLLEXPORT int q_gettid() noexcept
returns the current TID number
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275