XTA: API Reference for C++ language

Transaction.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2018, Christian Ferrari <tiian@users.sourceforge.net>
3  * All rights reserved.
4  *
5  * This file is part of LIXA.
6  *
7  * LIXA is free software: you can redistribute this file and/or modify
8  * it under the terms of the GNU Lesser General Public License version 2.1 as
9  * published by the Free Software Foundation.
10  *
11  * LIXA is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with LIXA. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 
21 
22 /* set module trace flag */
23 #ifdef LIXA_TRACE_MODULE
24 # undef LIXA_TRACE_MODULE
25 #endif /* LIXA_TRACE_MODULE */
26 #define LIXA_TRACE_MODULE LIXA_TRACE_MOD_XTA
27 
28 
29 
30 #include "Exception.hpp"
31 #include "Transaction.hpp"
32 
33 
34 
35 namespace xta {
36 
37  Transaction::Transaction(xta_transaction_t *tx)
38  {
39  this->tx = tx;
40  config = Config(xta_transaction_get_config(tx));
41  };
42 
44  {
45  /* this->tx is just a reference to an object created/destroyed by
46  TransactionManager */
47  this->tx = NULL;
48  };
49 
51  {
52  int rc;
53  if (LIXA_RC_OK != (rc = xta_transaction_enlist_resource(
54  tx, xaRes->getCBaseXaResource())))
55  throw Exception(rc, "xta_transaction_enlist_resource");
56  }
57 
58  void Transaction::start(bool MultipleBranches)
59  {
60  int rc;
61  if (LIXA_RC_OK != (rc = xta_transaction_start(
62  tx, (int)MultipleBranches)))
63  throw Exception(rc, "xta_transaction_start");
64  }
65 
66  void Transaction::commit(bool NonBlocking)
67  {
68  int rc = xta_transaction_commit(tx, NonBlocking);
69  if ((NonBlocking && LIXA_RC_WOULD_BLOCK != rc) ||
70  (!NonBlocking && LIXA_RC_OK != rc))
71  throw Exception(rc, "xta_transaction_commit");
72  }
73 
75  {
76  int rc;
77  if (LIXA_RC_OK != (rc = xta_transaction_rollback(tx)))
78  throw Exception(rc, "xta_transaction_rollback");
79  }
80 
81  void Transaction::suspend(long Flags)
82  {
83  int rc;
84  if (LIXA_RC_OK != (rc = xta_transaction_suspend(tx, Flags)))
85  throw Exception(rc, "xta_transaction_suspend");
86  }
87 
88  void Transaction::resume(const string& XidString, long Flags)
89  {
90  int rc;
91  if (LIXA_RC_OK != (rc = xta_transaction_resume(
92  tx, XidString.c_str(), Flags)))
93  throw Exception(rc, "xta_transaction_resume");
94  }
95 
97  {
98  int rc;
99  if (LIXA_RC_OK != (rc = xta_transaction_recover(tx)))
100  throw Exception(rc, "xta_transaction_recover");
101  }
102 
103  void Transaction::branch(const string& XidString)
104  {
105  int rc;
106  if (LIXA_RC_OK != (rc = xta_transaction_branch(tx, XidString.c_str())))
107  throw Exception(rc, "xta_transaction_branch");
108  }
109 
111  {
112  const xta_xid_t *xid = NULL;
113  if (NULL == (xid = xta_transaction_get_xid(tx)))
114  throw Exception(LIXA_RC_NULL_OBJECT, "xta_transaction_get_xid");
115  return Xid(xid);
116  }
117 
119  {
120  return config;
121  }
122 }
xta_transaction_t * tx
virtual xta_xa_resource_t * getCBaseXaResource()=0
Definition: Xid.hpp:25
Transaction(xta_transaction_t *tx)
Definition: Transaction.cpp:37
void resume(const string &XidString, long Flags=TMRESUME)
Definition: Transaction.cpp:88
void rollback(void)
Definition: Transaction.cpp:74
void branch(const string &XidString)
void start(bool MultipleBranches=false)
Definition: Transaction.cpp:58
Config & getConfig()
void recover(void)
Definition: Transaction.cpp:96
void enlistResource(XaResource *xaRes)
Definition: Transaction.cpp:50
void commit(bool NonBlocking=false)
Definition: Transaction.cpp:66
void suspend(long Flags=TMMIGRATE)
Definition: Transaction.cpp:81

Copyright © 2009-2019, Christian Ferrari tiian@users.sourceforge.net http://www.tiian.org/