diff --git a/skeema/gradido_login/pending_tasks.sql b/skeema/gradido_login/pending_tasks.sql index 702db8484..fc98be56f 100644 --- a/skeema/gradido_login/pending_tasks.sql +++ b/skeema/gradido_login/pending_tasks.sql @@ -1,5 +1,5 @@ CREATE TABLE `pending_tasks` ( - `id` int UNSIGNED NOT NULL, + `id` int UNSIGNED NOT NULL AUTO_INCREMENT, `user_id` int UNSIGNED DEFAULT '0', `request` varbinary(2048) NOT NULL, `created` datetime NOT NULL, diff --git a/src/cpp/model/table/ModelBase.cpp b/src/cpp/model/table/ModelBase.cpp index 417c1caf1..376de1065 100644 --- a/src/cpp/model/table/ModelBase.cpp +++ b/src/cpp/model/table/ModelBase.cpp @@ -42,7 +42,8 @@ namespace model { { //printf("ModelBase::insertIntoDB with table: %s\n", getTableName()); auto cm = ConnectionManager::getInstance(); - Poco::ScopedLock _lock(mWorkMutex); + Poco::ScopedLock _poco_lock(mWorkMutex); + UNIQUE_LOCK; auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); Poco::Data::Statement insert = _insertIntoDB(session); @@ -85,7 +86,8 @@ namespace model { bool ModelBase::isExistInDB() { auto cm = ConnectionManager::getInstance(); - Poco::ScopedLock _lock(mWorkMutex); + Poco::ScopedLock _poco_lock(mWorkMutex); + UNIQUE_LOCK; auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); Poco::Data::Statement select = _loadIdFromDB(session); @@ -102,7 +104,8 @@ namespace model { bool ModelBase::deleteFromDB() { - Poco::ScopedLock _lock(mWorkMutex); + Poco::ScopedLock _poco_lock(mWorkMutex); + UNIQUE_LOCK; if (mID == 0) { addError(new Error(getTableName(), "id is zero, couldn't delete from db")); return false; @@ -116,10 +119,8 @@ namespace model { return deleteStmt.execute() == 1; } catch (Poco::Exception& ex) { - lock(); addError(new ParamError(getTableName(), "mysql error by delete", ex.displayText().data())); addError(new ParamError(getTableName(), "id: ", mID)); - unlock(); } return false; } diff --git a/src/cpp/model/table/ModelBase.h b/src/cpp/model/table/ModelBase.h index df83e4fb4..2d4e499f5 100644 --- a/src/cpp/model/table/ModelBase.h +++ b/src/cpp/model/table/ModelBase.h @@ -63,8 +63,8 @@ namespace model { bool deleteFromDB(); - inline void setID(int id) { lock(); mID = id; unlock(); } - inline int getID() { lock(); int id = mID; unlock(); return id; } + inline void setID(int id) { UNIQUE_LOCK; mID = id; } + inline int getID() const { SHARED_LOCK; return mID; } static Poco::DateTime parseElopageDate(std::string dateString); @@ -95,7 +95,8 @@ namespace model { size_t ModelBase::loadFromDB(const std::string& fieldName, const T& fieldValue) { auto cm = ConnectionManager::getInstance(); - Poco::ScopedLock _lock(mWorkMutex); + Poco::ScopedLock _poco_lock(mWorkMutex); + UNIQUE_LOCK; auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); Poco::Data::Statement select = _loadFromDB(session, fieldName); select, Poco::Data::Keywords::useRef(fieldValue); @@ -115,7 +116,7 @@ namespace model { size_t ModelBase::countColumns(const std::string& fieldName, const T& fieldValue) { auto cm = ConnectionManager::getInstance(); - Poco::ScopedLock _lock(mWorkMutex); + //Poco::ScopedLock _lock(mWorkMutex); auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); Poco::Data::Statement select(session); size_t count = 0; @@ -140,7 +141,7 @@ namespace model { bool ModelBase::isExistInDB(const std::string& fieldName, const T& fieldValue) { auto cm = ConnectionManager::getInstance(); - Poco::ScopedLock _lock(mWorkMutex); + //Poco::ScopedLock _lock(mWorkMutex); auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); Poco::Data::Statement select(session); int id; @@ -167,7 +168,8 @@ namespace model { { //printf("ModelBase::loadFromDB multi\n"); std::vector results; - Poco::ScopedLock _lock(mWorkMutex); + Poco::ScopedLock _poco_lock(mWorkMutex); + UNIQUE_LOCK; //return results; if (expectedResults > 0) { results.reserve(expectedResults); @@ -194,8 +196,8 @@ namespace model { std::vector ModelBase::loadAllFromDB() { std::vector results; - Poco::ScopedLock _lock(mWorkMutex); - + Poco::ScopedLock _poco_lock(mWorkMutex); + UNIQUE_LOCK; auto cm = ConnectionManager::getInstance(); try { Poco::Data::Statement select = _loadAllFromDB(cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER)); @@ -221,7 +223,8 @@ namespace model { std::vector ModelBase::loadFromDB(const std::vector& fieldNames, const std::vector& fieldValues, MysqlConditionType conditionType/* = MYSQL_CONDITION_AND*/, int expectedResults/* = 0*/) { std::vector results; - Poco::ScopedLock _lock(mWorkMutex); + Poco::ScopedLock _poco_lock(mWorkMutex); + UNIQUE_LOCK; if (fieldNames.size() != fieldValues.size() || fieldNames.size() <= 1) { lock(); addError(new Error(getTableName(), "fieldNames and fieldValues size don't match or smaller as 1")); @@ -244,12 +247,10 @@ namespace model { resultCount = select.execute(); } catch (Poco::Exception& ex) { - lock(); addError(new ParamError(getTableName(), "mysql error by multi selecting", ex.displayText().data())); for (auto it = fieldNames.begin(); it != fieldNames.end(); it++) { addError(new ParamError(getTableName(), "field name for select: ", (*it).data())); } - unlock(); } return results; } @@ -258,7 +259,8 @@ namespace model { size_t ModelBase::loadFromDB(const std::vector& fieldNames, const T1& field1Value, const T2& field2Value, MysqlConditionType conditionType/* = MYSQL_CONDITION_AND*/) { auto cm = ConnectionManager::getInstance(); - Poco::ScopedLock _lock(mWorkMutex); + Poco::ScopedLock _poco_lock(mWorkMutex); + UNIQUE_LOCK; auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); Poco::Data::Statement select = _loadFromDB(session, fieldNames, conditionType); select, Poco::Data::Keywords::useRef(field1Value), Poco::Data::Keywords::useRef(field2Value); @@ -268,7 +270,6 @@ namespace model { resultCount = select.execute(); } catch (Poco::Exception& ex) { - lock(); addError(new ParamError(getTableName(), "mysql error by selecting, maybe more than one result?", ex.displayText())); int count = 0; for (auto it = fieldNames.begin(); it != fieldNames.end(); it++) { @@ -276,7 +277,6 @@ namespace model { } //addError(new ParamError(getTableName(), "field name for select: ", fieldName.data())); - unlock(); } return resultCount; } @@ -286,7 +286,8 @@ namespace model { size_t ModelBase::updateIntoDB(const std::string& fieldName, const T& fieldValue) { auto cm = ConnectionManager::getInstance(); - Poco::ScopedLock _lock(mWorkMutex); + Poco::ScopedLock _poco_lock(mWorkMutex); + UNIQUE_LOCK; auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); Poco::Data::Statement update(session); @@ -303,10 +304,9 @@ namespace model { resultCount = update.execute(); } catch (Poco::Exception& ex) { - lock(); addError(new ParamError(getTableName(), "mysql error by update", ex.displayText().data())); addError(new ParamError(getTableName(), "field name for update: ", fieldName.data())); - unlock(); + } return resultCount; @@ -315,7 +315,8 @@ namespace model { size_t ModelBase::updateIntoDB(std::string fieldNames[2], const T1& fieldValue1, const T2& fieldValue2) { auto cm = ConnectionManager::getInstance(); - Poco::ScopedLock _lock(mWorkMutex); + Poco::ScopedLock _poco_lock(mWorkMutex); + UNIQUE_LOCK; auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); Poco::Data::Statement update(session); @@ -339,13 +340,10 @@ namespace model { resultCount = update.execute(); } catch (Poco::Exception& ex) { - lock(); addError(new ParamError(getTableName(), "mysql error by update 2", ex.displayText())); for (int i = 0; i < 2; i++) { addError(new ParamError(getTableName(), "field name for update: ", fieldNames[i])); } - - unlock(); } return resultCount; } @@ -353,7 +351,8 @@ namespace model { size_t ModelBase::updateIntoDB(std::string fieldNames[3], const T1& fieldValue1, const T2& fieldValue2, const T3& fieldValue3) { auto cm = ConnectionManager::getInstance(); - Poco::ScopedLock _lock(mWorkMutex); + Poco::ScopedLock _poco_lock(mWorkMutex); + UNIQUE_LOCK; auto session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER); Poco::Data::Statement update(session); @@ -377,13 +376,11 @@ namespace model { resultCount = update.execute(); } catch (Poco::Exception& ex) { - lock(); addError(new ParamError(getTableName(), "mysql error by update 3", ex.displayText())); for (int i = 0; i < 3; i++) { addError(new ParamError(getTableName(), "field name for update: ", fieldNames[i])); } - unlock(); } return resultCount; } diff --git a/src/cpp/model/table/PendingTask.cpp b/src/cpp/model/table/PendingTask.cpp index 9203b20e8..472e403df 100644 --- a/src/cpp/model/table/PendingTask.cpp +++ b/src/cpp/model/table/PendingTask.cpp @@ -84,13 +84,30 @@ namespace model } return ""; } + /*enum TaskType { + TASK_TYPE_NONE = 0, + TASK_TYPE_GROUP_CREATE = 1, + TASK_TYPE_GROUP_ADD_MEMBER = 2, + TASK_TYPE_CREATION = 10, + TASK_TYPE_TRANSFER = 11, + TASK_TYPE_HEDERA_TOPIC_CREATE = 20, + TASK_TYPE_HEDERA_TOPIC_MESSAGE = 21, + TASK_TYPE_HEDERA_ACCOUNT_CREATE = 25, + };*/ bool PendingTask::isGradidoTransaction(TaskType type) { if (type && type < TASK_TYPE_HEDERA_TOPIC_CREATE) return true; return false; } + + bool PendingTask::isHederaTransaction(TaskType type) + { + if (type && type >= TASK_TYPE_HEDERA_TOPIC_CREATE) + return true; + return false; + } Poco::Data::Statement PendingTask::_loadFromDB(Poco::Data::Session session, const std::string& fieldName) { @@ -119,9 +136,9 @@ namespace model lock(); select << "SELECT id FROM " << getTableName() << " WHERE user_id = ? " - //<< " AND created LIKE ? " + << " AND TIMESTAMPDIFF(SECOND, created, ?) = 0 " << " AND task_type_id = ? " - , into(mID), use(mUserId), /*use(mCreated),*/ use(mTaskTypeId); + , into(mID), use(mUserId), use(mCreated), use(mTaskTypeId); unlock(); return select; } diff --git a/src/cpp/model/table/PendingTask.h b/src/cpp/model/table/PendingTask.h index 85a876ae7..afafafb33 100644 --- a/src/cpp/model/table/PendingTask.h +++ b/src/cpp/model/table/PendingTask.h @@ -56,6 +56,8 @@ namespace model { inline bool isGradidoTransaction() { SHARED_LOCK; return isGradidoTransaction((TaskType)mTaskTypeId); } static bool isGradidoTransaction(TaskType type); + inline bool isHederaTransaction() { SHARED_LOCK; return isHederaTransaction((TaskType)mTaskTypeId); } + static bool isHederaTransaction(TaskType type); static const char* typeToString(TaskType type); protected: