Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "QueueReaderTask.h"
- #include "XMLNotification.h"
- #include "Poco/Data/MySQL/MySQLException.h"
- #include "Poco/Data/MySQL/Connector.h"
- #include "Poco/Data/StatementImpl.h"
- #include "Poco/Format.h"
- #include "Poco/NotificationQueue.h"
- #include "Poco/Task.h"
- #include "Poco/Util/Application.h"
- using namespace ENC;
- using namespace Poco::Data;
- using Poco::Data::MySQL::ConnectionException;
- using Poco::Data::MySQL::Connector;
- using Poco::format;
- using Poco::NotificationQueue;
- using Poco::Task;
- QueueReaderTask::QueueReaderTask(int id, NotificationQueue& incomingQueue):
- Task(format("QueueReaderTAsk#%02d", id)),
- _config(Application::instance().config()),
- _incomingQueue(incomingQueue),
- _dbConnString(format("user=%s;password=%s;db=%s;compress=%s;auto-reconnect=%s", _config().getString("Reader.User", ENC::USER), _config().getString("Reader.User", ENC::PASSWORD), _config().getString("Reader.DB", ENC::DB), _config().getString("Reader.Compress", ENC::COMPRESS), _config().getString("Reader.Reconnect", ENC::RECONNECT)))
- {
- registerConnector();
- try
- {
- _pSession = new Session(SessionFactory::instance().create(MySQL::Connector::KEY, _dbConnString));
- }
- catch (ConnectionException& ex)
- {
- std::cout << ex.displayText() << std::endl; //Para que haga algo
- }
- }
- QueueReaderTask::~QueueReaderTask()
- {
- }
- void QueueReaderTask::runTask()
- {
- XMLNotification::Ptr xmlNotification = dynamic_cast<XMLNotification*>(_incomingQueue.waitDequeueNotification(SLEEP_MILLISECONDS));
- if (xmlNotification)
- {
- const XML& notification = xmlNotification->getNotification();
- Statement stmt(*_pSession);
- stmt << format("INSERT INTO %s VALUES (?,?,?)", config().getString("Database.Table", ENC::DATABASE_TABLE_NAME)), use(notification.Name), use(notification.Message), use(notification.CreatedAt);
- stmt.execute();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement