Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include "QueueReaderTask.h"
  2. #include "XMLNotification.h"
  3. #include "Poco/Data/MySQL/MySQLException.h"
  4. #include "Poco/Data/MySQL/Connector.h"
  5. #include "Poco/Data/StatementImpl.h"
  6. #include "Poco/Format.h"
  7. #include "Poco/NotificationQueue.h"
  8. #include "Poco/Task.h"
  9. #include "Poco/Util/Application.h"
  10.  
  11.  
  12. using namespace ENC;
  13. using namespace Poco::Data;
  14. using Poco::Data::MySQL::ConnectionException;
  15. using Poco::Data::MySQL::Connector;
  16. using Poco::format;
  17. using Poco::NotificationQueue;
  18. using Poco::Task;
  19.  
  20.  
  21. QueueReaderTask::QueueReaderTask(int id, NotificationQueue& incomingQueue):
  22. Task(format("QueueReaderTAsk#%02d", id)),
  23. _config(Application::instance().config()),
  24. _incomingQueue(incomingQueue),
  25. _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)))
  26. {
  27. registerConnector();
  28. try
  29. {
  30. _pSession = new Session(SessionFactory::instance().create(MySQL::Connector::KEY, _dbConnString));
  31. }
  32. catch (ConnectionException& ex)
  33. {
  34. std::cout << ex.displayText() << std::endl; //Para que haga algo
  35. }
  36.  
  37. }
  38.  
  39.  
  40. QueueReaderTask::~QueueReaderTask()
  41. {
  42. }
  43.  
  44.  
  45. void QueueReaderTask::runTask()
  46. {
  47. XMLNotification::Ptr xmlNotification = dynamic_cast<XMLNotification*>(_incomingQueue.waitDequeueNotification(SLEEP_MILLISECONDS));
  48.  
  49. if (xmlNotification)
  50. {
  51. const XML& notification = xmlNotification->getNotification();
  52. Statement stmt(*_pSession);
  53. stmt << format("INSERT INTO %s VALUES (?,?,?)", config().getString("Database.Table", ENC::DATABASE_TABLE_NAME)), use(notification.Name), use(notification.Message), use(notification.CreatedAt);
  54. stmt.execute();
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement