Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // localtxn.h
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file declares the class LocalTransaction.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 03/14/1998 Original version.
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #ifndef _LOCALTXN_H_
  19. #define _LOCALTXN_H_
  20. #if _MSC_VER >= 1000
  21. #pragma once
  22. #endif
  23. #include <nocopy.h>
  24. #include <oledb.h>
  25. ///////////////////////////////////////////////////////////////////////////////
  26. //
  27. // CLASS
  28. //
  29. // LocalTransaction
  30. //
  31. // DESCRIPTION
  32. //
  33. // This class creates a scoped transaction on an OLE-DB session. If the
  34. // transaction is not committed before the object goes out of scope, it
  35. // will be aborted.
  36. //
  37. ///////////////////////////////////////////////////////////////////////////////
  38. class LocalTransaction
  39. : NonCopyable
  40. {
  41. public:
  42. explicit LocalTransaction(IUnknown* session,
  43. ISOLEVEL isoLevel = ISOLATIONLEVEL_READCOMMITTED)
  44. {
  45. using _com_util::CheckError;
  46. CheckError(session->QueryInterface(__uuidof(ITransactionLocal),
  47. (PVOID*)&txn));
  48. CheckError(txn->StartTransaction(isoLevel, 0, NULL, NULL));
  49. }
  50. ~LocalTransaction() throw ()
  51. {
  52. if (txn != NULL)
  53. {
  54. txn->Abort(NULL, FALSE, FALSE);
  55. }
  56. }
  57. void commit()
  58. {
  59. _com_util::CheckError(txn->Commit(FALSE, XACTTC_SYNC, 0));
  60. txn.Release();
  61. }
  62. protected:
  63. CComPtr<ITransactionLocal> txn;
  64. };
  65. #endif // _LOCALTXN_H_