From: <ibr...@us...> - 2012-08-12 21:28:36
|
Revision: 4412 http://tora.svn.sourceforge.net/tora/?rev=4412&view=rev Author: ibre5041 Date: 2012-08-12 21:28:22 +0000 (Sun, 12 Aug 2012) Log Message: ----------- new toeventquery Modified Paths: -------------- branches/tora3/src/connection/tooracleconnection.cpp branches/tora3/src/connection/tooracleconnection.h branches/tora3/src/connection/tooraclequery.h branches/tora3/src/core/tocodemodel.cpp branches/tora3/src/core/tocodemodel.h branches/tora3/src/core/toconnectionsubloan.h branches/tora3/src/core/toeventquery.cpp branches/tora3/src/core/toeventquery.h branches/tora3/src/core/toeventquerytask.cpp branches/tora3/src/core/toeventquerytask.h branches/tora3/src/core/toquery.cpp branches/tora3/src/core/toquery.h branches/tora3/src/core/toresultbar.cpp branches/tora3/src/core/toresultbar.h branches/tora3/src/core/toresultcombo.cpp branches/tora3/src/core/toresultcombo.h branches/tora3/src/core/toresultdepend.cpp branches/tora3/src/core/toresultdepend.h branches/tora3/src/core/toresultfield.cpp branches/tora3/src/core/toresultfield.h branches/tora3/src/core/toresultitem.cpp branches/tora3/src/core/toresultitem.h branches/tora3/src/core/toresultmodel.cpp branches/tora3/src/core/toresultmodel.h branches/tora3/src/core/toresultplan.cpp branches/tora3/src/core/toresultplan.h branches/tora3/src/core/toresultschema.cpp branches/tora3/src/core/toresultschema.h branches/tora3/src/core/toresultstats.cpp branches/tora3/src/core/toresultstats.h branches/tora3/src/core/toresulttableview.cpp branches/tora3/src/core/toresulttableview.h branches/tora3/src/tools/toanalyze.cpp branches/tora3/src/tools/toanalyze.h branches/tora3/src/tools/tocurrent.cpp branches/tora3/src/tools/tocurrent.h branches/tora3/src/tools/toer.cpp branches/tora3/src/tools/toer.h branches/tora3/src/tools/toresultstorage.cpp branches/tora3/src/tools/toresultstorage.h branches/tora3/src/tools/tosession.h branches/tora3/src/tools/toworksheet.cpp branches/tora3/src/tounittest.cpp branches/tora3/src/ts_log/critical_section.h Added Paths: ----------- branches/tora3/src/toresultlong.cpp branches/tora3/src/toresultlong.h Removed Paths: ------------- branches/tora3/src/core/toresultlong.cpp branches/tora3/src/core/toresultlong.h Modified: branches/tora3/src/connection/tooracleconnection.cpp =================================================================== --- branches/tora3/src/connection/tooracleconnection.cpp 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/connection/tooracleconnection.cpp 2012-08-12 21:28:22 UTC (rev 4412) @@ -295,6 +295,13 @@ { } +void toOracleConnectionSub::cancel() +{ + _conn->cancel(); + _conn->reset(); + TLOG(0, toDecorator, __HERE__) << ":oracleConn::cancel(conn=" <<_conn << ", this=" << Query << ")" << std::endl; +} + void toOracleConnectionSub::close() { } Modified: branches/tora3/src/connection/tooracleconnection.h =================================================================== --- branches/tora3/src/connection/tooracleconnection.h 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/connection/tooracleconnection.h 2012-08-12 21:28:22 UTC (rev 4412) @@ -90,6 +90,7 @@ toOracleConnectionSub(::trotl::OciConnection *, ::trotl::OciLogin *); virtual ~toOracleConnectionSub(); + virtual void cancel(); virtual void close(); virtual void commit(); virtual void rollback(); Modified: branches/tora3/src/connection/tooraclequery.h =================================================================== --- branches/tora3/src/connection/tooraclequery.h 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/connection/tooraclequery.h 2012-08-12 21:28:22 UTC (rev 4412) @@ -167,28 +167,22 @@ int datatypearg1 = 0; int datatypearg2 = 0; - TLOG(0, toDecorator, __HERE__) << "TODO describe:" << std::endl; - - // TODO trotl should return const iterator - const std::vector<trotl::DescribeColumn*> &col = Query->get_columns(); if(col.empty()) return ret; std::vector<trotl::DescribeColumn*>::const_iterator it = col.begin(); - ++it; // starts with 1st - //TLOG(0,toDecorator,__HERE__) << "Columns: " << q1.get_column_count() << std::endl; + ++it; // starts with 1st column for(; it != col.end(); ++it) { - TLOG(0, toDecorator, __HERE__) << "Var: " << (*it)->typeName() << std::endl; - toCache::ColumnDescription desc; - desc.AlignRight = false; - desc.Name = QString::fromUtf8( (*it)->_name.c_str() ); - desc.Datatype = QString::fromUtf8( (*it)->typeName().c_str() ); + toCache::ColumnDescription desc; + desc.AlignRight = false; + desc.Name = QString::fromUtf8( (*it)->_name.c_str() ); + desc.Datatype = QString::fromUtf8( (*it)->typeName().c_str() ); - //datatypearg1 = description[i].char_size; - desc.Datatype.sprintf(desc.Datatype.toUtf8().constData(), datatypearg1, datatypearg2); - //desc.Null = description[i].nullok; + //datatypearg1 = description[i].char_size; + desc.Datatype.sprintf(desc.Datatype.toUtf8().constData(), datatypearg1, datatypearg2); + //desc.Null = description[i].nullok; - ret.insert(ret.end(), desc); + ret.insert(ret.end(), desc); } return ret; Modified: branches/tora3/src/core/tocodemodel.cpp =================================================================== --- branches/tora3/src/core/tocodemodel.cpp 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/tocodemodel.cpp 2012-08-12 21:28:22 UTC (rev 4412) @@ -444,10 +444,11 @@ try { - query = new toEventQuery(conn + query = new toEventQueryNew(this + , conn , toSQL::sql(SQLListObjects, conn) , param - , toEventQuery::READ_FIRST); // really? + , toEventQueryNew::READ_FIRST); // really? connect(query, SIGNAL(dataAvailable()), @@ -509,7 +510,7 @@ { disconnect(query, 0, this, 0); // TODO - here we directly call QObject's slot - query->slotStop(); + query->stop(); delete query; } @@ -554,5 +555,5 @@ return; } - query->readAll(); + query->setFetchMode(toEventQueryNew::READ_ALL); } Modified: branches/tora3/src/core/tocodemodel.h =================================================================== --- branches/tora3/src/core/tocodemodel.h 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/tocodemodel.h 2012-08-12 21:28:22 UTC (rev 4412) @@ -49,7 +49,7 @@ #include <QModelIndex> #include <QVariant> -class toEventQuery; +class toEventQueryNew; /*! \brief A leaf item for toCodeModel. @@ -150,7 +150,7 @@ toCodeModelItem *funcItem; toCodeModelItem *macroItem; toCodeModelItem *typeItem; - toEventQuery *query; + toEventQueryNew *query; QString m_owner; }; Modified: branches/tora3/src/core/toconnectionsubloan.h =================================================================== --- branches/tora3/src/core/toconnectionsubloan.h 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toconnectionsubloan.h 2012-08-12 21:28:22 UTC (rev 4412) @@ -5,11 +5,11 @@ class toConnection; class toConnectionSub; -class toEventQuery; +class toEventQueryNew; class toConnectionSubLoan { - friend class toEventQuery; + friend class toEventQueryNew; public: toConnectionSubLoan(toConnection &con); Modified: branches/tora3/src/core/toeventquery.cpp =================================================================== --- branches/tora3/src/core/toeventquery.cpp 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toeventquery.cpp 2012-08-12 21:28:22 UTC (rev 4412) @@ -51,215 +51,251 @@ #include "core/toconnectionsub.h" #include "core/toconnectionsubloan.h" -toEventQuery::toEventQuery(toConnection &conn - , QString const& sql - , toQueryParams const& param - , MODE mode - , toResultStats *stats - ) - : SQL(sql) - , Param(param) - , Statistics(stats) - , Task(NULL) +toEventQueryNew::toEventQueryNew(QObject *parent + , toConnection &conn + , QString const& sql + , toQueryParams const& param + , FETCH_MODE mode + //, toResultStats *stats + ) + : QObject(parent) + , SQL(sql) + , Param(param) + , ColumnCount(0) + , Processed(0L) + //, Statistics(stats) + , Thread(NULL) + , Worker(NULL) + , Started(NULL) + , TaskDone(false) , Connection(conn) - , Processed(0) - , ColumnCount(0) - , TaskDone(false) , Mode(mode) { + Thread = new QThread(this); + Thread->setObjectName("toEventQuery"); + TLOG(1, toDecorator, __HERE__) << "toEventQueryNew created" << std::endl; } -toEventQuery::toEventQuery(toConnectionSubLoan &conn - , QString const& sql - , toQueryParams const& param - , MODE mode - , toResultStats *stats - ) - : SQL(sql) +toEventQueryNew::toEventQueryNew(QObject *parent + , toConnectionSubLoan &conn + , QString const& sql + , toQueryParams const& param + , FETCH_MODE mode + //, toResultStats *stats + ) + : QObject(parent) + , SQL(sql) , Param(param) - , Statistics(stats) - , Task(NULL) + , ColumnCount(0) + , Processed(0L) + //, Statistics(stats) + , Thread(NULL) + , Worker(NULL) + , Started(NULL) + , TaskDone(false) , Connection(conn.Connection) - , Processed(0) - , ColumnCount(0) - , TaskDone(false) - , Mode(mode) + , Mode(mode) { - throw toConnection::exception("Not implemented yet: toEventQuery::toEventQuery(toConnectionSubLoan &conn..."); + throw toConnection::exception("Not implemented yet: toEventQueryNew::toEventQueryNew(toConnectionSubLoan &conn..."); } + +toEventQueryNew::~toEventQueryNew() +{ + TLOG(1, toDecorator, __HERE__) << "~toEventQueryNew a" << std::endl; + // try + // { + // if(Task) + // { + // Task->disconnect(); + // //disconnect(Task, 0, 0, 0); + // if(Task->thread()) + // //Task->thread()->exit(); + // Task->thread()->wait(); + // //Task->ThreadAlive.unlock(); + // } + // } + // catch(...) + // { + // TLOG(1, toDecorator, __HERE__) << " Ignored exception." << std::endl; + // ; // ignored + // } + // //Task->ThreadAlive.unlock(); +} -/* Call stask for this function - * Async thread toEventQueryTask emits signal data - * the rest is processed in the main thread - * the slot taskData receives data (run within the main thread context) - * taskData emits signal dataAvailable - * toEventQuery parent(toResulModel for example) receives signal - * and then calls toEventQeury::readValue - */ -toQValue toEventQuery::readValue() +void toEventQueryNew::start() { - if(Values.isEmpty()) - throw tr("Read past end of query"); + Worker = new toEventQueryWorker(this, Connection, SQL, Param); + Worker->moveToThread(Thread); - if((Values.size() < ColumnCount) && !eof()) - { - if(Task) - Task->read(); // getting close to end, request read - } + // Connect to Worker's API + connect(Worker, SIGNAL(headers(toQColumnDescriptionList &, int)), // BG -> main + this, SLOT(slotDesc(toQColumnDescriptionList &, int))); - return Values.takeFirst(); -} + connect(Worker, SIGNAL(data(ValuesList &)), + this, SLOT(slotData(ValuesList &))); + + connect(Worker, SIGNAL(error(const toConnection::exception &)), // BG -> main + this, SLOT(slotError(const toConnection::exception &))); + connect(Worker, SIGNAL(workDone()), // BG -> main + this, SLOT(slotFinished())); + + connect(Worker, SIGNAL(rowsProcessed(unsigned long)), // BG -> main + this, SLOT(slotRowsProcessed(unsigned long))); -//toEventQuery::toEventQuery(toConnection &conn -//// , toQuery::queryMode mode -// , QString const& sql -// , toQueryParams const& param -// , toResultStats *stats -// ) -// : SQL(sql) -// , Param(param) -// , Statistics(stats) -// , Task(0) { -// -// Connection = &conn; -// Processed = 0; -// Columns = 0; -// TaskDone = false; -//} + // Connect to QThread's API + // error handling + connect(Worker, SIGNAL(error(toConnection::exception const &)) // BG -> main + , this, SLOT(slotError(toConnection::exception const &))); + // initization + connect(Thread, SIGNAL(started()), Worker, SLOT(init())); // main -> BG + connect(this, SIGNAL(dataRequested()), Worker, SLOT(slotRead())); // main -> BG + if(Mode = READ_ALL) + connect(this, SIGNAL(consumed()), Worker, SLOT(slotRead())); // main -> BG + // finish + connect(Worker, SIGNAL(finished()), Thread, SLOT(quit())); // BG -> main + connect(Worker, SIGNAL(finished()), Worker, SLOT(deleteLater())); // BG -> BG + connect(Thread, SIGNAL(finished()), Thread, SLOT(deleteLater())); // BG -> main + connect(Thread, SIGNAL(destroyed()), this, SLOT(slotThreadEnd())); // main -> main + TLOG(1, toDecorator, __HERE__) << "toEventQueryNew start" << std::endl; + // finally start the thread + Thread->start(); +} -void toEventQuery::start() +void toEventQueryNew::setFetchMode(FETCH_MODE m) { - Task = new toEventQueryTask(*this, Connection, SQL, Param //stat , Statistics - ); - ///Task->ThreadAlive.lock(); + Mode = m; +} - connect(Task, - SIGNAL(headers(toQColumnDescriptionList &, int)), - this, - SLOT(slotDesc(toQColumnDescriptionList &, int)), - Qt::QueuedConnection); +toQColumnDescriptionList const& toEventQueryNew::describe(void) const +{ + return Description; +} - connect(Task, - SIGNAL(data(ValuesList &)), - this, - SLOT(slotData(ValuesList &)), - Qt::QueuedConnection); +unsigned toEventQueryNew::columnCount(void) const +{ + return ColumnCount; +} - connect(Task, - SIGNAL(error(const toConnection::exception &)), - this, - SLOT(slotError(const toConnection::exception &)), - Qt::QueuedConnection); +unsigned long toEventQueryNew::rowsProcessed(void) const +{ + return Processed; +} - connect(Task, - SIGNAL(done()), - this, - SLOT(slotFinished()), - Qt::QueuedConnection); +/* Call stask for this function + * Async thread toEventQueryNewTask emits signal data + * the rest is processed in the main thread + * the slot taskData receives data (run within the main thread context) + * taskData emits signal dataAvailable + * toEventQueryNew parent(toResulModel for example) receives signal + * and then calls toEventQeury::readValue + */ +toQValue toEventQueryNew::readValue() +{ + // if(Values.isEmpty()) + // throw tr("Read past end of query"); - connect(Task, - SIGNAL(rowsProcessed(unsigned long)), - this, - SLOT(slotRowsProcessed(unsigned long)), - Qt::QueuedConnection); + // if((Values.size() < ColumnCount) && !eof()) + // { + // if(Task) + // Task->read(); // getting close to end, request read + // } - (new toRunnableThread(Task))->start(); + return Values.takeFirst(); } - -toEventQuery::~toEventQuery() +bool toEventQueryNew::eof(void) const { - try - { - if(Task) - { - Task->disconnect(); - //disconnect(Task, 0, 0, 0); - if(Task->thread()) - //Task->thread()->exit(); - Task->thread()->wait(); - //Task->ThreadAlive.unlock(); - } - } - catch(...) - { - TLOG(1, toDecorator, __HERE__) << " Ignored exception." << std::endl; - ; // ignored - } - //Task->ThreadAlive.unlock(); + if(hasMore()) + return false; + return TaskDone; } - -bool toEventQuery::eof(void) const +QString const& toEventQueryNew::sql(void) const { - if(hasMore()) - return false; - return TaskDone; + return SQL; } - -void toEventQuery::slotStop(void) +bool toEventQueryNew::hasMore(void) const { - if(!TaskDone && Task) - Task->close(); + return !Values.isEmpty(); } - -void toEventQuery::slotData(ValuesList &values) +void toEventQueryNew::stop(void) { - Values += values; - emit dataAvailable(this); + TLOG(1, toDecorator, __HERE__) << "toEventQueryNew stop a" << std::endl; + if(TaskDone) + return; - try - { -//stat if(Statistics) -//stat Statistics->refreshStats(false); - } - catch(...) - { - TLOG(1, toDecorator, __HERE__) << " Ignored exception." << std::endl; - // ignored - } + if(Worker && Thread && Thread->isRunning()) + { + TLOG(1, toDecorator, __HERE__) << "toEventQueryNew stop Thread is running" << std::endl; + Worker->CancelMutex.lock(); + emit stopRequested(); + bool succeeded = Worker->CancelCond.wait(&Worker->CancelMutex, 1000); // wait for 1 sec + Worker->CancelMutex.unlock(); + if(!succeeded) + { + TLOG(1, toDecorator, __HERE__) << "toEventQueryNew stop bg did not respond" << std::endl; + Worker->asyncCancel(); + } + } + // if(!TaskDone && Task) + // Task->close(); } - -void toEventQuery::slotDesc(toQColumnDescriptionList &desc, int column) +// private slots +void toEventQueryNew::slotData(ValuesList &values) { - Description = desc; - ColumnCount = column; - emit descriptionAvailable(); + TLOG(1, toDecorator, __HERE__) << "toEventQueryNew slot data" << std::endl; + Values += values; + emit dataAvailable(this); + emit consumed(); + + try + { +//stat if(Statistics) +//stat Statistics->refreshStats(false); + } + catch(...) + { + TLOG(1, toDecorator, __HERE__) << " Ignored exception." << std::endl; + // ignored + } } - -void toEventQuery::slotError(const toConnection::exception &msg) +void toEventQueryNew::slotDesc(toQColumnDescriptionList &desc, int column) { - emit error(msg); + TLOG(1, toDecorator, __HERE__) << "toEventQueryNew slot desc" << std::endl; + Started = true; + Description = desc; + ColumnCount = column; + emit descriptionAvailable(this); + emit dataRequested(); // request 1st chunk of rows } - -void toEventQuery::slotFinished() +void toEventQueryNew::slotError(const toConnection::exception &msg) { - TaskDone = true; - Task = NULL; - emit done(this); + TLOG(1, toDecorator, __HERE__) << "toEventQueryNew slot error" << std::endl; + emit error(this, msg); } - -void toEventQuery::slotRowsProcessed(unsigned long rows) +void toEventQueryNew::slotFinished() { - Processed = rows; + TLOG(1, toDecorator, __HERE__) << "toEventQueryNew slot finish" << std::endl; + TaskDone = true; + emit done(this); } -void toEventQuery::readAll(void) +void toEventQueryNew::slotRowsProcessed(unsigned long rows) { - if(Task) - Task->read(true); + TLOG(1, toDecorator, __HERE__) << "toEventQueryNew slot rows" << std::endl; + Processed = rows; } -void toEventQuery::slotReadAll(void) +void toEventQueryNew::slotThreadEnd() { - if(Task) - Task->read(true); + Thread = NULL; + Worker = NULL; } Modified: branches/tora3/src/core/toeventquery.h =================================================================== --- branches/tora3/src/core/toeventquery.h 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toeventquery.h 2012-08-12 21:28:22 UTC (rev 4412) @@ -46,235 +46,199 @@ #include "core/toconnection.h" #include "core/toconnectionsub.h" #include "core/toconnectionsubloan.h" -#include "core/toresultstats.h" +//#include "core/toresultstats.h" #include "core/toqvalue.h" #include <QObject> #include <QPointer> class toResultStats; -class toEventQueryTask; -class toEventQueryTaskNew; +class toEventQueryWorker; /** * Run a query in the background without blocking. This class should - * always be in the main thread, it uses toEventQueryTask to actually + * always be in the main thread, it uses toEventQueryWorker to actually * run the sql. - * */ -class toEventQuery : public QObject +class toEventQueryNew : public QObject { - Q_OBJECT; + Q_OBJECT; - friend class toEventQueryTask; + friend class toEventQueryWorker; public: - enum MODE { - READ_FIRST, - READ_ALL - }; - /** - * Create a new query. - * - * @param conn Connection to run on. - * @param sql SQL to execute. - * @param param Parameters to pass to query. - * @param statistics Optional statistics widget to update with values from query. - */ - toEventQuery(toConnection &conn - , QString const& sql - , toQueryParams const& param - , MODE - , toResultStats *statistics = NULL - ); + enum FETCH_MODE { + READ_FIRST, + READ_ALL + }; - /** - * Create a new query. - * - * @param conn Connection to run on. - * @param mode Query mode to execute query in. - * @param sql SQL to execute. - * @param param Parameters to pass to query. - * @param statistics Optional statistics widget to update with - * values from query. - */ -// toEventQuery(toConnection &conn -//// , toQuery::queryMode mode -// , QString const& sql -// , toQueryParams const& param -// , toResultStats *statistics = NULL -// ); + /** + * Create a new query. + * + * @param conn Connection to run on. + * @param sql SQL to execute. + * @param param Parameters to pass to query. + * @param statistics Optional statistics widget to update with values from query. + */ + toEventQueryNew(QObject *parent + , toConnection &conn + , QString const &sql + , toQueryParams const ¶m + , FETCH_MODE + //, toResultStats *statistics = NULL + ); - toEventQuery(toConnectionSubLoan &conn - , QString const& sql - , toQueryParams const& param - , MODE - , toResultStats *statistics = NULL - ); + /** + * Create a new query. + * + * @param conn Connection Loan to run on. + * @param mode Query mode to execute query in. + * @param sql SQL to execute. + * @param param Parameters to pass to query. + * @param statistics Optional statistics widget to update with values from query. + */ + toEventQueryNew(QObject *parent + , toConnectionSubLoan &conn + , QString const& sql + , toQueryParams const& param + , FETCH_MODE + //, toResultStats *statistics = NULL + ); - virtual ~toEventQuery(); + virtual ~toEventQueryNew(); - /** - * Start the query. - * First connect all the slots and then call start - * Must be called prior to any other function, - */ - void start(void); + /** + * Start the query. + * First connect all the slots and then call start + * Must be called prior to any other function, + */ + void start(void); - /** - * Get description of columns. - * @return Description of columns list. - */ - inline toQColumnDescriptionList const& describe(void) const - { - return Description; - } + void setFetchMode(FETCH_MODE); - /** - * Get column count - */ - inline unsigned columns(void) const - { - return ColumnCount; - } + /** + * Get description of columns. + * @return Description of columns list. + */ + toQColumnDescriptionList const& describe(void) const; - /** - * Read the next value from the query. - * @return The next available value. - */ - toQValue readValue(void); + /** + * Get column count + */ + unsigned columnCount(void) const; - /** - * Get the number of rows processed. - * @return Number of rows processed. - */ - inline unsigned long rowsProcessed(void) const - { - return Processed; - } + /** + * Get the number of rows processed. + * @return Number of rows processed. + */ + unsigned long rowsProcessed(void) const; + /** + * Read the next value from the query. + * @return The next available value. + */ + toQValue readValue(void); - /** - * Check if at end of query. - * @return True if query is done. - */ - bool eof(void) const; + /** + * Check if at end of query. + * @return True if query is done. + */ + bool eof(void) const; - /** - * return query's sql command - */ - inline QString const& sql(void) const - { - return SQL; - } + /** + * return query's sql command + */ + QString const& sql(void) const; + /** + * Returns true if more data is available for readValue() + */ + bool hasMore(void) const; - /** - * Returns true if more data is available for readValue() - */ - inline bool hasMore(void) const - { - return !Values.isEmpty(); - } + /** + * Stop reading query + */ + void stop(void); - void readAll(void); +signals: + /** + * Emitted when header descriptions are available + */ + void descriptionAvailable(toEventQueryNew*); + + /** + * Emitted when data has been read. + * @param rows Number of rows to be read + */ + void dataAvailable(toEventQueryNew*); -private slots: + /** + * Emitted with error string + */ + void error(toEventQueryNew*, const toConnection::exception &); - // handle tasks's data() signal. emits dataAvailable() - void slotData(ValuesList &values); + /** + * Emitted when done + */ + void done(toEventQueryNew*); - // handle tasks's headers() signal emits descriptionAvailable() - void slotDesc(toQColumnDescriptionList &desc, int columns); - - // handle tasks's error() signal - void slotError(const toConnection::exception &msg); - - // handle task finished - void slotFinished(void); - - // sets Processed. signal is sent if > 0 - void slotRowsProcessed(unsigned long rows); - -public slots: - - /** - * Stop reading query - */ - void slotStop(void); - + /** + * Signals to be sent to Worker + */ + void consumed(void); + void dataRequested(); + void stopRequested(); + private slots: - /** - * Read all data - */ - void slotReadAll(void); + // handle tasks's data() signal. emits dataAvailable() + void slotData(ValuesList &values); -signals: + // handle tasks's headers() signal emits descriptionAvailable() + void slotDesc(toQColumnDescriptionList &desc, int columns); - /** - * Emitted when header descriptions are available - */ - void descriptionAvailable(); + // handle tasks's error() signal + void slotError(const toConnection::exception &msg); - /** - * Emitted when data has been read. - * @param rows Number of rows to be read - */ - void dataAvailable(toEventQuery* e = NULL); + // handle task finished + void slotFinished(void); - /** - * Emitted with error string - */ - void error(const toConnection::exception &); + // sets Processed. signal is sent if > 0 + void slotRowsProcessed(unsigned long rows); - /** - * Emitted when done - */ - void done(toEventQuery* e = NULL); - + // emitted immediately before the Thread is destroyed + void slotThreadEnd(); + private: - /** Undefined copy contructor. Don't copy me. */ - toEventQuery(toEventQuery const& other); + /** Undefined copy contructor.Don't clone me. */ + toEventQueryNew(toEventQueryNew const& other); - ValuesList Values; + ValuesList Values; - // SQL to execute. - QString SQL; + // SQL to execute. + QString SQL; - // Bind parameters - toQueryParams Param; + // Bind parameters + toQueryParams Param; - // Number of rows processed. - unsigned long Processed; + // Number of columns in Description + unsigned ColumnCount; + + // Number of rows processed. + unsigned long Processed; - // Statistics to be used if any. - QPointer<toResultStats> Statistics; + // Description of result + toQColumnDescriptionList Description; - // Description of result - toQColumnDescriptionList Description; + // reference to a BG producer thread + QThread *Thread; + toEventQueryWorker *Worker; - // Number of columns in Description - unsigned ColumnCount; + bool Started; + bool TaskDone; - // QThread instance that will do actual reading - // Note: this pointer is NOT deleted by me, but by toRunnableThread::run/delete Runner - // This can not be guarded by QPointer until QT is fixed, - // see http://qt.gitorious.org/~varlucian/qt/varlucians-qt/commit/18e3cd65980e1bc01e6af4807cae0bceca25288c - toEventQueryTask *Task; + // connection for this query + toConnection &Connection; - QThread BackgroundTread; - toEventQueryTaskNew *BackgroundTask; - - // true when task finishes. this set from a slot called by a - // queued message. the problem is that sometimes the thread can - // finish before it's messages have all been processed, making - // Task->isRunning() useless for detecting if there's data - // waiting. - volatile bool TaskDone; - - // connection for this query - toConnection &Connection; - - MODE Mode; + FETCH_MODE Mode; }; #endif Modified: branches/tora3/src/core/toeventquerytask.cpp =================================================================== --- branches/tora3/src/core/toeventquerytask.cpp 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toeventquerytask.cpp 2012-08-12 21:28:22 UTC (rev 4412) @@ -55,9 +55,6 @@ #include <QTimer> -static const int FIREWALL_TIMEOUT = 240000; - - #define CATCH_ALL \ catch(const toConnection::exception &str) { \ TLOG(1,toDecorator,__HERE__) << "What: " << str << std::endl;\ @@ -88,184 +85,287 @@ } \ } - -toEventQueryTask::toEventQueryTask(toEventQuery &parent - , toConnection &conn - , QString const& sql - , toQueryParams const& param - //stat, toResultStats *stats - ) - : toRunnable() - , SQL(sql) - , Params(param) - , ParentQuery(parent) - , Query(0) +toEventQueryWorker::toEventQueryWorker(toEventQueryNew *c + , toConnection &conn + , QString &sql + , toQueryParams ¶ms) + : Query(NULL) + , Consumer(c) + , SQL(sql) + , Params(params) + , Connection(conn) , ColumnCount(0) - , Connection(conn) - , Closed(false) -//stat , Statistics(stats) + , CancelRequested(false) + , Stopped(false) { - setObjectName("toEventQueryTask"); + TLOG(1, toDecorator, __HERE__) << "toEventQueryWorker created" << std::endl; + connect(this, SIGNAL(readRequested()), this, SLOT(slotRead())); } +toEventQueryWorker::~toEventQueryWorker() +{ + TLOG(1, toDecorator, __HERE__) << "~toEventQueryWorker" << std::endl; +} -void toEventQueryTask::run(void) +void toEventQueryWorker::init() { - try - { - Query = new toQuery(Connection, SQL, Params); - //Query->execute(SQL, Params); + TLOG(1, toDecorator, __HERE__) << "toEventQueryWorker init a" << std::endl; + try + { + Query = new toQuery(Connection, SQL, Params); - connect(this, - SIGNAL(readRequested(bool)), - this, - SLOT(pread(bool)), - Qt::QueuedConnection); + toQColumnDescriptionList desc = Query->describe(); + ColumnCount = Query->columns(); + emit headers(desc, ColumnCount); - toQColumnDescriptionList desc = Query->describe(); - ColumnCount = Query->columns(); - emit headers(desc, ColumnCount); + if(Query->eof()) + { + // emit empty result + // ValuesList values; + // emit data(values); + Stopped = true; + close(); + } + } + TOCATCH; + TLOG(1, toDecorator, __HERE__) << "toEventQueryWorker init b" << std::endl; +} - if(Query->eof()) - { - // emit empty result - ValuesList values; - emit data(values); - } - else - { - read(); +void toEventQueryWorker::syncStop() +{ + TLOG(1, toDecorator, __HERE__) << "toEventQueryWorker syncStop" << std::endl; + close(); +} - if(toConfigurationSingle::Instance().firewallMode()) - QTimer::singleShot(FIREWALL_TIMEOUT, this, SLOT(timeout())); +void toEventQueryWorker::close() +{ + TLOG(1, toDecorator, __HERE__) << "toEventQueryWorker close a" << std::endl; + Q_ASSERT_X(Query!=NULL, "toEventQueryWorker::close", "Query == NULL"); - // begin thread's event loop - thread()->exec(); - } - } - CATCH_ALL; + if(Query) + { + unsigned long p = Query->rowsProcessed(); + if(p > 0) + emit rowsProcessed(p); - close(); + delete Query; Query = NULL; + } + emit workDone(); + emit finished(); + TLOG(1, toDecorator, __HERE__) << "toEventQueryWorker close b" << std::endl; +} - try - { - //stat if(Statistics) - //stat Statistics->changeSession(*Query); - } - catch(...) - { - TLOG(1, toDecorator, __HERE__) << " Ignored exception." << std::endl; - // ignored - } +void toEventQueryWorker::asyncCancel() +{ + TLOG(1, toDecorator, __HERE__) << "toEventQueryWorker aclose a" << std::endl; + Query->cancel(); +} - try - { - QMutexLocker lock(&CloseLock); - Closed = true; - delete Query; - Query = 0; - } - catch(...) - { - TLOG(1, toDecorator, __HERE__) << " Ignored exception." << std::endl; - // ignored - } +void toEventQueryWorker::slotRead() +{ + TLOG(1, toDecorator, __HERE__) << "toEventQueryWorker slot read" << std::endl; + if(!Query || ColumnCount == 0 || Stopped) + { + close(); + return; + } - //ThreadAlive.lock(); + unsigned maxRead = toConfigurationSingle::Instance().maxNumber(); + ValuesList values; + //for(unsigned row = 0; row < maxRead; row++) + { + for(unsigned i = 0; i < ColumnCount && !Query->eof(); i++) + values.append(Query->readValue()); + } + + if(values.size() > 0) + emit data(values); // must not access after this line + + if(Query->eof()) + { + emit workDone(); + emit finished(); + } } +// static const int FIREWALL_TIMEOUT = 240000; +// toEventQueryTask::toEventQueryTask(toEventQuery &parent +// , toConnection &conn +// , QString const& sql +// , toQueryParams const& param +// //stat, toResultStats *stats +// ) +// : toRunnable() +// , SQL(sql) +// , Params(param) +// , ParentQuery(parent) +// , Query(0) +// , ColumnCount(0) +// , Connection(conn) +// , Closed(false) +// //stat , Statistics(stats) +// { +// setObjectName("toEventQueryTask"); +// } -toEventQueryTask::~toEventQueryTask() -{ - ParentQuery.Task = NULL; -} +// void toEventQueryTask::run(void) +// { +// try +// { +// Query = new toQuery(Connection, SQL, Params); +// //Query->execute(SQL, Params); -void toEventQueryTask::close() -{ - QMutexLocker lock(&CloseLock); - try - { - if(Query) - { - unsigned long p = Query->rowsProcessed(); - if(p > 0) - emit rowsProcessed(p); - } +// connect(this, +// SIGNAL(readRequested(bool)), +// this, +// SLOT(pread(bool)), +// Qt::QueuedConnection); - emit done(); +// toQColumnDescriptionList desc = Query->describe(); +// ColumnCount = Query->columns(); +// emit headers(desc, ColumnCount); - disconnect(this, 0, 0, 0); +// if(Query->eof()) +// { +// // emit empty result +// ValuesList values; +// emit data(values); +// } +// else +// { +// read(); - if(Query && !Closed) - Query->cancel(); - } - catch(...) - { - TLOG(1, toDecorator, __HERE__) << " Ignored exception." << std::endl; - // noop - } +// if(toConfigurationSingle::Instance().firewallMode()) +// QTimer::singleShot(FIREWALL_TIMEOUT, this, SLOT(timeout())); - Closed = true; +// // begin thread's event loop +// thread()->exec(); +// } +// } +// CATCH_ALL; - // exit thread event loop. safe to call before event loop starts. - if(thread()) - thread()->exit(); -} +// close(); +// try +// { +// //stat if(Statistics) +// //stat Statistics->changeSession(*Query); +// } +// catch(...) +// { +// TLOG(1, toDecorator, __HERE__) << " Ignored exception." << std::endl; +// // ignored +// } -void toEventQueryTask::read(bool all) -{ - emit readRequested(all); -} +// try +// { +// QMutexLocker lock(&CloseLock); +// Closed = true; +// delete Query; +// Query = 0; +// } +// catch(...) +// { +// TLOG(1, toDecorator, __HERE__) << " Ignored exception." << std::endl; +// // ignored +// } +// //ThreadAlive.lock(); +// } -void toEventQueryTask::pread(bool all) -{ - if(!Query || ColumnCount == 0) - { - close(); - return; - } - int maxRead = toConfigurationSingle::Instance().maxNumber(); +// toEventQueryTask::~toEventQueryTask() +// { +// ParentQuery.Task = NULL; +// } - try - { - do - { - ValuesList values; - for(int row = 0; row < maxRead; row++) - { - for(unsigned i = 0; i < ColumnCount && !Query->eof(); i++) - values.append(Query->readValue()); - } +// void toEventQueryTask::close() +// { +// QMutexLocker lock(&CloseLock); +// try +// { +// if(Query) +// { +// unsigned long p = Query->rowsProcessed(); +// if(p > 0) +// emit rowsProcessed(p); +// } - if(values.size() > 0) - emit data(values); // must not access after this line - } - while(all && !Query->eof()); - } - CATCH_ALL; +// emit done(); - try - { - if(!Query || Query->eof()) - close(); - } - CATCH_ALL; -} +// disconnect(this, 0, 0, 0); +// if(Query && !Closed) +// Query->cancel(); +// } +// catch(...) +// { +// TLOG(1, toDecorator, __HERE__) << " Ignored exception." << std::endl; +// // noop +// } -void toEventQueryTask::timeout() -{ - if(Closed) - return; +// Closed = true; - pread(false); +// // exit thread event loop. safe to call before event loop starts. +// if(thread()) +// thread()->exit(); +// } - // check again in case config changes - if(toConfigurationSingle::Instance().firewallMode()) - QTimer::singleShot(FIREWALL_TIMEOUT, this, SLOT(timeout())); -} + +// void toEventQueryTask::read(bool all) +// { +// emit readRequested(all); +// } + + +// void toEventQueryTask::pread(bool all) +// { +// if(!Query || ColumnCount == 0) +// { +// close(); +// return; +// } + +// int maxRead = toConfigurationSingle::Instance().maxNumber(); + +// try +// { +// do +// { +// ValuesList values; + +// for(int row = 0; row < maxRead; row++) +// { +// for(unsigned i = 0; i < ColumnCount && !Query->eof(); i++) +// values.append(Query->readValue()); +// } + +// if(values.size() > 0) +// emit data(values); // must not access after this line +// } +// while(all && !Query->eof()); +// } +// CATCH_ALL; + +// try +// { +// if(!Query || Query->eof()) +// close(); +// } +// CATCH_ALL; +// } + + +// void toEventQueryTask::timeout() +// { +// if(Closed) +// return; + +// pread(false); + +// // check again in case config changes +// if(toConfigurationSingle::Instance().firewallMode()) +// QTimer::singleShot(FIREWALL_TIMEOUT, this, SLOT(timeout())); +// } Modified: branches/tora3/src/core/toeventquerytask.h =================================================================== --- branches/tora3/src/core/toeventquerytask.h 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toeventquerytask.h 2012-08-12 21:28:22 UTC (rev 4412) @@ -50,6 +50,7 @@ #include "core/toqvalue.h" #include "core/tocache.h" +#include <QObject> #include <QThread> #include <QPointer> #include <QMetaType> @@ -57,9 +58,92 @@ #include <QMutex> #include <QList> + class toResultStats; -class toEventQuery; +class toEventQueryNew; +class toEventQueryWorker : public QObject +{ + friend class toEventQueryNew; + Q_OBJECT; +public: + toEventQueryWorker(toEventQueryNew* , toConnection &, QString &, toQueryParams&); + + virtual ~toEventQueryWorker(); + + void close(void); + + /** This only method should be called from the main thread + * if connection provider's traits do support async cancel + */ + void asyncCancel(); + +public slots: + void init(void); + + void syncStop(void); + +signals: + // must be careful when defining signals. passing by reference + // will share memory between threads. + // also QObject's will have it's affinity set to background thread + // and should be disposed within the context of the main thread + /** + * A read was requested + */ + void readRequested(); + + /** + * Error message + */ + void error(toConnection::exception const &msg); + + /** + * Result headers + * + * @param desc list of header values + * @param columns number of columns in result + */ + void headers(toQColumnDescriptionList &desc, int columns); + + /** + * Data read from query + */ + void data(ValuesList &values); + + /** + * Emitted when sql query is done + */ + void workDone(); + void finished(); + + /** + * Emitted if query.rowsProcessed() > 0. Number of affected rows. + */ + void rowsProcessed(unsigned long rows); + +private slots: + void slotRead(); + +private: + // the real query object + toQuery *Query; + + toEventQueryNew *Consumer; + // sql and bind parameters + QString SQL; + toQueryParams Params; + + toConnection &Connection; + + unsigned ColumnCount; + + bool CancelRequested, Stopped; + QMutex CancelMutex; + QWaitCondition CancelCond; +}; + + /** * Threaded class used by toEventQuery. Internal to toEventQuery only. * @@ -67,108 +151,108 @@ * Qt::QueuedConnection except to read() and stop() * */ -class toEventQueryTask : public toRunnable -{ -private: - friend class toEventQuery; - Q_OBJECT; +/* class toEventQueryTask : public toRunnable */ +/* { */ +/* private: */ +/* friend class toEventQuery; */ +/* Q_OBJECT; */ - // the real query object - QPointer<toQuery> Query; +/* // the real query object */ +/* QPointer<toQuery> Query; */ - // sql and bind parameters - QString SQL; - toQueryParams Params; +/* // sql and bind parameters */ +/* QString SQL; */ +/* toQueryParams Params; */ - unsigned ColumnCount; +/* unsigned ColumnCount; */ - // Statistics to be used if any. - //stat QPointer<toResultStats> Statistics; +/* // Statistics to be used if any. */ +/* //stat QPointer<toResultStats> Statistics; */ - toConnection &Connection; +/* toConnection &Connection; */ - // object was closed - volatile bool Closed; +/* // object was closed */ +/* volatile bool Closed; */ - toEventQuery &ParentQuery; +/* toEventQuery &ParentQuery; */ - // can't synchronize on query or cancel wouldn't work, but need to - // protect access during close() which may be called from the main - // thread - QMutex CloseLock; +/* // can't synchronize on query or cancel wouldn't work, but need to */ +/* // protect access during close() which may be called from the main */ +/* // thread */ +/* QMutex CloseLock; */ - // keeps thread from exiting until toEventQuery exits. this - // prevents many race conditions and the caller can always assume - // task is alive. - ///QMutex ThreadAlive; +/* // keeps thread from exiting until toEventQuery exits. this */ +/* // prevents many race conditions and the caller can always assume */ +/* // task is alive. */ +/* ///QMutex ThreadAlive; */ - toEventQueryTask(toEventQuery &parent - , toConnection &conn - , QString const& sql - , toQueryParams const& param - // , toResultStats *stats = NULL - ); - virtual ~toEventQueryTask(); +/* toEventQueryTask(toEventQuery &parent */ +/* , toConnection &conn */ +/* , QString const& sql */ +/* , toQueryParams const& param */ +/* // , toResultStats *stats = NULL */ +/* ); */ +/* virtual ~toEventQueryTask(); */ -protected: - /** - * Overrides toRunnable::run. Create toRunnableThread to start - */ - virtual void run(void); +/* protected: */ +/* /\** */ +/* * Overrides toRunnable::run. Create toRunnableThread to start */ +/* *\/ */ +/* virtual void run(void); */ -private slots: - void pread(bool all); - void timeout(void); +/* private slots: */ +/* void pread(bool all); */ +/* void timeout(void); */ -public slots: - /** - * Queues a read request. Emits readRequested() - */ - void read(bool all = false); +/* public slots: */ +/* /\** */ +/* * Queues a read request. Emits readRequested() */ +/* *\/ */ +/* void read(bool all = false); */ - /** - * Closes this class. Good idea to call this. - */ - void close(void); +/* /\** */ +/* * Closes this class. Good idea to call this. */ +/* *\/ */ +/* void close(void); */ -signals: - // must be careful when defining signals. passing by reference - // will share memory between threads. +/* signals: */ +/* // must be careful when defining signals. passing by reference */ +/* // will share memory between threads. */ - /** - * A read was requested - */ - void readRequested(bool all); +/* /\** */ +/* * A read was requested */ +/* *\/ */ +/* void readRequested(bool all); */ - /** - * Error message - */ - void error(const toConnection::exception &msg); +/* /\** */ +/* * Error message */ +/* *\/ */ +/* void error(const toConnection::exception &msg); */ - /** - * Result headers - * - * @param desc list of header values - * @param columns number of columns in result - */ - void headers(toQColumnDescriptionList &desc, int columns); +/* /\** */ +/* * Result headers */ +/* * */ +/* * @param desc list of header values */ +/* * @param columns number of columns in result */ +/* *\/ */ +/* void headers(toQColumnDescriptionList &desc, int columns); */ - /** - * Data read from query - */ - void data(ValuesList &values); +/* /\** */ +/* * Data read from query */ +/* *\/ */ +/* void data(ValuesList &values); */ - /** - * Emitted when sql query is done - */ - void done(); +/* /\** */ +/* * Emitted when sql query is done */ +/* *\/ */ +/* void done(); */ - /** - * Emitted if query.rowsProcessed() > 0. Number of affected rows. - */ - void rowsProcessed(unsigned long rows); -}; +/* /\** */ +/* * Emitted if query.rowsProcessed() > 0. Number of affected rows. */ +/* *\/ */ +/* void rowsProcessed(unsigned long rows); */ +/* }; */ #endif Modified: branches/tora3/src/core/toquery.cpp =================================================================== --- branches/tora3/src/core/toquery.cpp 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toquery.cpp 2012-08-12 21:28:22 UTC (rev 4412) @@ -279,10 +279,10 @@ return m_Query->readValue(); } -void toQuery::cancel(void) -{ - m_Query->cancel(); -} +//void toQuery::cancel(void) +//{ +// m_Query->cancel(); +//} toQColumnDescriptionList toQuery::describe(void) { Modified: branches/tora3/src/core/toquery.h =================================================================== --- branches/tora3/src/core/toquery.h 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toquery.h 2012-08-12 21:28:22 UTC (rev 4412) @@ -211,7 +211,7 @@ /** Cancel the current execution of a query. */ - void cancel(void); + //void cancel(void); /** Specify if busy cursor must be displayed while a query is running */ inline void setShowBusy(bool busy) Modified: branches/tora3/src/core/toresultbar.cpp =================================================================== --- branches/tora3/src/core/toresultbar.cpp 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toresultbar.cpp 2012-08-12 21:28:22 UTC (rev 4412) @@ -102,7 +102,7 @@ try { First = first; - Query = new toEventQuery(connection(), sql, param, toEventQuery::READ_ALL); + Query = new toEventQueryNew(this, connection(), sql, param, toEventQueryNew::READ_ALL); connect(Query, SIGNAL(dataAvailable()), this, SLOT(poll())); connect(Query, SIGNAL(done()), this, SLOT(queryDone())); Query->start(); Modified: branches/tora3/src/core/toresultbar.h =================================================================== --- branches/tora3/src/core/toresultbar.h 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toresultbar.h 2012-08-12 21:28:22 UTC (rev 4412) @@ -50,7 +50,7 @@ #include <list> -class toEventQuery; +class toEventQueryNew; class toSQL; /** Display the result of a query in a piechart. The first column of the query should @@ -73,7 +73,7 @@ */ std::list<double> LastValues; bool First; - toEventQuery *Query; + toEventQueryNew *Query; unsigned int Columns; void query(const QString &sql, toQueryParams const& param, bool first); Modified: branches/tora3/src/core/toresultcombo.cpp =================================================================== --- branches/tora3/src/core/toresultcombo.cpp 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toresultcombo.cpp 2012-08-12 21:28:22 UTC (rev 4412) @@ -49,15 +49,15 @@ #include "core/totool.h" toResultCombo::toResultCombo(QWidget *parent, const char *name) - : QComboBox(parent), Query(0), SelectionPolicy(None) + : QComboBox(parent) + , Query(0) + , SelectionPolicy(None) { setObjectName(name); connect(this, SIGNAL(activated(int)), this, SLOT(slotChangeSelected(void))); setSizeAdjustPolicy(QComboBox::AdjustToContents); //queryingUserlist = false; - - connect(&(connection().getCache()), SIGNAL(userListRefreshed()), this, SLOT(slotUsersFromCache())); } toResultCombo::~toResultCombo() @@ -78,33 +78,12 @@ for (int i = 0; i < Additional.count(); i++) if (Additional[i] == Selected) setCurrentIndex(i); - - // NOTE: delete this block. It is just a runtime check. - // It should find all the instances of toResultCombo who use q TOSQL_USERLIST. - // All those should be migrated into toResultSchema - toResultSchema* d = dynamic_cast<toResultSchema*>(this); - if ( d == NULL) - { - if (sql == toSQL::string(toSQL::TOSQL_USERLIST, connection())) - { - throw QString::fromLatin1("Illegal usage"); - } - } - - if (sql != toSQL::string(toSQL::TOSQL_USERLIST, connection()) || - !connection().getCache().userListExists(toCache::USERS)) { - //queryingUserlist = true; - userList.clear(); - Query = new toEventQuery(connection(), sql, param, toEventQuery::READ_ALL); - connect(Query, SIGNAL(dataAvailable()), this, SLOT(slotPoll())); - connect(Query, SIGNAL(done()), this, SLOT(slotQueryDone())); + Query = new toEventQueryNew(this, connection(), sql, param, toEventQueryNew::READ_ALL); + connect(Query, SIGNAL(dataAvailable(toEventQueryNew*)), this, SLOT(slotPoll())); + connect(Query, SIGNAL(done(toEventQueryNew*)), this, SLOT(slotQueryDone())); Query->start(); } - else - { - slotUsersFromCache(); - } } TOCATCH } @@ -144,20 +123,6 @@ toResult::refresh(); } -// NOTE: this is nonsense too. This should be moved into toResultSchema -void toResultCombo::slotUsersFromCache(void) -{ - QStringList users = connection().getCache().userList(toCache::USERS); - for (QStringList::iterator i = users.begin(); i != users.end(); i++) - { - QString t = (*i); - addItem(t); - if (t == Selected) - setCurrentIndex(count() - 1); - } - slotQueryDone(); -} - void toResultCombo::slotPoll(void) { try @@ -215,7 +180,7 @@ setFont(font()); // Small hack to invalidate size hint of combobox which should resize to needed size. updateGeometry(); - // If we were querying user list - save it to cache +// If we were querying user list - save it to cache // if (queryingUserlist) // { // connection().getCache().updateUserList(userList, toCache::USERS); Modified: branches/tora3/src/core/toresultcombo.h =================================================================== --- branches/tora3/src/core/toresultcombo.h 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toresultcombo.h 2012-08-12 21:28:22 UTC (rev 4412) @@ -50,7 +50,7 @@ #include <QStringList> #include <QPointer> -class toEventQuery; +class toEventQueryNew; class toSQL; /** This widget displays the result of a query where each field is added as an item @@ -117,19 +117,16 @@ */ virtual void refresh(void); - void slotUsersFromCache(void); - -private slots: +protected slots: void slotPoll(void); void slotQueryDone(void); void slotChangeSelected(void); -private: +protected: selectionPolicy SelectionPolicy; QString Selected; QStringList Additional; - QPointer<toEventQuery> Query; - QList<toCache::CacheEntry*> userList; + toEventQueryNew *Query; }; #endif Modified: branches/tora3/src/core/toresultdepend.cpp =================================================================== --- branches/tora3/src/core/toresultdepend.cpp 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toresultdepend.cpp 2012-08-12 21:28:22 UTC (rev 4412) @@ -114,7 +114,11 @@ try { - Query = new toEventQuery(connection(), toSQL::string(SQLResultDepend, connection()), param, toEventQuery::READ_ALL); + Query = new toEventQueryNew(this + , connection() + , toSQL::string(SQLResultDepend, connection()) + , param + , toEventQueryNew::READ_ALL); connect(Query, SIGNAL(dataAvailable()), this, SLOT(slotPoll())); connect(Query, SIGNAL(done()), this, SLOT(slotQueryDone())); Query->start(); @@ -194,7 +198,11 @@ toQueryParams param; param << Current->text(0); param << Current->text(1); - Query = new toEventQuery(connection(), toSQL::string(SQLResultDepend, connection()), param, toEventQuery::READ_ALL); + Query = new toEventQueryNew(this + , connection() + , toSQL::string(SQLResultDepend, connection()) + , param + , toEventQueryNew::READ_ALL); connect(Query, SIGNAL(dataAvailable()), this, SLOT(slotPoll())); connect(Query, SIGNAL(done()), this, SLOT(slotQueryDone())); Query->start(); Modified: branches/tora3/src/core/toresultdepend.h =================================================================== --- branches/tora3/src/core/toresultdepend.h 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toresultdepend.h 2012-08-12 21:28:22 UTC (rev 4412) @@ -44,7 +44,7 @@ #include "core/toresultview.h" -class toEventQuery; +class toEventQueryNew; /** This widget displays information about the dependencies of an object * specified by the first and second parameter in the query. The sql is not @@ -88,7 +88,7 @@ */ bool exists(const QString &owner, const QString &name); - toEventQuery *Query; + toEventQueryNew *Query; toTreeWidgetItem *Current; }; Modified: branches/tora3/src/core/toresultfield.cpp =================================================================== --- branches/tora3/src/core/toresultfield.cpp 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toresultfield.cpp 2012-08-12 21:28:22 UTC (rev 4412) @@ -81,7 +81,11 @@ Query = NULL; } - Query = new toEventQuery(connection(), sql, param, toEventQuery::READ_ALL); + Query = new toEventQueryNew(this + , connection() + , sql + , param + , toEventQueryNew::READ_ALL); connect(Query, SIGNAL(dataAvailable()), this, SLOT(slotPoll())); connect(Query, SIGNAL(done()), this, SLOT(slotQueryDone())); Query->start(); Modified: branches/tora3/src/core/toresultfield.h =================================================================== --- branches/tora3/src/core/toresultfield.h 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toresultfield.h 2012-08-12 21:28:22 UTC (rev 4412) @@ -46,7 +46,7 @@ #include "core/tohighlightedtext.h" #include "core/toresult.h" -class toEventQuery; +class toEventQueryNew; class toSQL; /** This widget displays the result of a query where each item in the stream @@ -59,7 +59,7 @@ Q_OBJECT QString Unapplied; - toEventQuery *Query; + toEventQueryNew *Query; int whichResultField; // Shows which field from result should be used (for MySQL only), used for calls to "show create ..." public: Modified: branches/tora3/src/core/toresultitem.cpp =================================================================== --- branches/tora3/src/core/toresultitem.cpp 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toresultitem.cpp 2012-08-12 21:28:22 UTC (rev 4412) @@ -273,7 +273,11 @@ delete Query; Query = NULL; } - Query = new toEventQuery(connection(), sql, param, toEventQuery::READ_ALL); + Query = new toEventQueryNew(this + , connection() + , sql + , param + , toEventQueryNew::READ_ALL); connect(Query, SIGNAL(dataAvailable()), this, SLOT(slotPoll())); connect(Query, SIGNAL(done()), this, SLOT(slotQueryDone())); Query->start(); Modified: branches/tora3/src/core/toresultitem.h =================================================================== --- branches/tora3/src/core/toresultitem.h 2012-08-11 00:01:23 UTC (rev 4411) +++ branches/tora3/src/core/toresultitem.h 2012-08-12 21:28:22 UTC (rev 4412) @@ -51,7 +51,7 @@ #include <vector> class toSQL; -class toEventQuery; +class toEventQueryNew; /** Display the first row of a query with each column with a separate label. * If the label of the item is a single '-' character the data is treated as @@ -194,7 +194,7 @@ */ QFont DataFont; - toEventQuery *Query; + toEventQueryNew *Query; }; #endif Deleted: branches/tora3/src/core/toresultlong.cpp =================================================================== --- branches/to... [truncated message content] |