transaction.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #ifndef TRANSACTION_INCLUDED
  18. #define TRANSACTION_INCLUDED
  19. #include <kopano/zcdefs.h>
  20. #include "transaction_fwd.h"
  21. #include "ArchiverSessionPtr.h" // For ArchiverSessionPtr
  22. #include <kopano/archiver-common.h>
  23. #include "postsaveaction.h"
  24. #include <kopano/mapi_ptr.h>
  25. namespace KC { namespace operations {
  26. class Transaction _kc_final {
  27. public:
  28. Transaction(const SObjectEntry &objectEntry);
  29. HRESULT SaveChanges(ArchiverSessionPtr ptrSession, RollbackPtr *lpptrRollback);
  30. HRESULT PurgeDeletes(ArchiverSessionPtr ptrSession, TransactionPtr ptrDeferredTransaction = TransactionPtr());
  31. const SObjectEntry& GetObjectEntry() const;
  32. HRESULT Save(IMessage *lpMessage, bool bDeleteOnFailure, const PostSaveActionPtr &ptrPSAction = PostSaveActionPtr());
  33. HRESULT Delete(const SObjectEntry &objectEntry, bool bDeferredDelete = false);
  34. private:
  35. struct SaveEntry {
  36. MessagePtr ptrMessage;
  37. bool bDeleteOnFailure;
  38. PostSaveActionPtr ptrPSAction;
  39. };
  40. typedef std::list<SaveEntry> MessageList;
  41. struct DelEntry {
  42. SObjectEntry objectEntry;
  43. bool bDeferredDelete;
  44. };
  45. typedef std::list<DelEntry> ObjectList;
  46. const SObjectEntry m_objectEntry;
  47. MessageList m_lstSave;
  48. ObjectList m_lstDelete;
  49. };
  50. inline const SObjectEntry& Transaction::GetObjectEntry() const
  51. {
  52. return m_objectEntry;
  53. }
  54. class Rollback _kc_final {
  55. public:
  56. HRESULT Delete(ArchiverSessionPtr ptrSession, IMessage *lpMessage);
  57. HRESULT Execute(ArchiverSessionPtr ptrSession);
  58. private:
  59. struct DelEntry {
  60. MAPIFolderPtr ptrFolder;
  61. entryid_t eidMessage;
  62. };
  63. typedef std::list<DelEntry> MessageList;
  64. MessageList m_lstDelete;
  65. };
  66. }} /* namespace */
  67. #endif // !defined TRANSACTION_INCLUDED