XTA: API Reference for C language

xta_mysql_xa_resource.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2019, 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 #include "config.h"
20 
21 
22 
23 #ifdef HAVE_ERRNO_H
24 # include <errno.h>
25 #endif
26 #ifdef HAVE_GLIB_H
27 # include <glib.h>
28 #endif
29 
30 
31 
32 /* LIXA includes */
33 #include "lixa_errors.h"
34 #include "lixa_trace.h"
35 #include "liblixamy.h" /* LIXA wrapper for MySQL */
36 /* XTA includes */
37 #include "xta_mysql_xa_resource.h"
38 
39 
40 
41 /* set module trace flag */
42 #ifdef LIXA_TRACE_MODULE
43 # undef LIXA_TRACE_MODULE
44 #endif /* LIXA_TRACE_MODULE */
45 #define LIXA_TRACE_MODULE LIXA_TRACE_MOD_XTA
46 
47 
48 
52 const static struct xta_iface_s xta_mysql_iface = {
53  "XTA MySQL",
54  TMNOFLAGS,
55  0,
65 };
66 
67 
68 
70  const char *name,
71  const char *open_info)
72 {
73  enum Exception { G_TRY_MALLOC_ERROR
74  , XTA_MYSQL_XA_RESOURCE_INIT_ERROR
75  , NONE } excp;
76  int ret_cod = LIXA_RC_INTERNAL_ERROR;
77  xta_mysql_xa_resource_t *this = NULL;
78 
79  LIXA_TRACE(("xta_mysql_xa_resource_new\n"));
80  TRY {
81  /* allocate sufficient memory for the object */
82  if (NULL == (this = (xta_mysql_xa_resource_t *)g_try_malloc0(
83  sizeof(xta_mysql_xa_resource_t))))
84  THROW(G_TRY_MALLOC_ERROR);
85  /* initialize "class" properties */
86  if (LIXA_RC_OK != (ret_cod = xta_mysql_xa_resource_init(
87  this, connection, name, open_info)))
88  THROW(XTA_MYSQL_XA_RESOURCE_INIT_ERROR);
89 
90  THROW(NONE);
91  } CATCH {
92  switch (excp) {
93  case G_TRY_MALLOC_ERROR:
95  break;
96  case XTA_MYSQL_XA_RESOURCE_INIT_ERROR:
97  break;
98  case NONE:
99  ret_cod = LIXA_RC_OK;
100  break;
101  default:
102  ret_cod = LIXA_RC_INTERNAL_ERROR;
103  } /* switch (excp) */
104  } /* TRY-CATCH */
105  LIXA_TRACE(("xta_mysql_xa_resource_new/excp=%d/"
106  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
107  return this;
108 }
109 
110 
111 
113 {
114  enum Exception { NONE } excp;
115  int ret_cod = LIXA_RC_INTERNAL_ERROR;
116 
117  LIXA_TRACE(("xta_mysql_xa_resource_delete\n"));
118  TRY {
119  /* clean the object before releasing */
120  xta_mysql_xa_resource_clean(xa_resource);
121  /* release memory allocated for the object */
122  g_free(xa_resource);
123 
124  THROW(NONE);
125  } CATCH {
126  switch (excp) {
127  case NONE:
128  ret_cod = LIXA_RC_OK;
129  break;
130  default:
131  ret_cod = LIXA_RC_INTERNAL_ERROR;
132  } /* switch (excp) */
133  } /* TRY-CATCH */
134  LIXA_TRACE(("xta_mysql_xa_resource_delete/excp=%d/"
135  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
136  return;
137 }
138 
139 
140 
142  MYSQL *connection,
143  const char *name, const char *open_info)
144 {
145  enum Exception { NULL_OBJECT
146  , XTA_ACQUIRED_XA_RESOURCE_INIT_ERROR
147  , NONE } excp;
148  int ret_cod = LIXA_RC_INTERNAL_ERROR;
149 
150  LIXA_TRACE(("xta_mysql_xa_resource_init\n"));
151  TRY {
152  if (NULL == connection)
153  THROW(NULL_OBJECT);
154  /* initialize "base class" (xta_acquired_xa_resource_t) properties */
155  if (LIXA_RC_OK != (ret_cod = xta_acquired_xa_resource_init(
156  (xta_acquired_xa_resource_t *)xa_resource,
157  &xta_mysql_iface,
158  name, open_info)))
159  THROW(XTA_ACQUIRED_XA_RESOURCE_INIT_ERROR);
160  /* set connection */
161  xa_resource->connection = connection;
162  /* set resource interface */
164  &xa_resource->xa_resource.act_rsrmgr_config.lixa_iface,
165  &xta_mysql_iface, (xta_xa_resource_t *)xa_resource);
166  /* reset status */
167  memset(&xa_resource->lssr, 0, sizeof(struct lixa_sw_status_rm_s));
168 
169  THROW(NONE);
170  } CATCH {
171  switch (excp) {
172  case NULL_OBJECT:
173  ret_cod = LIXA_RC_NULL_OBJECT;
174  break;
175  case XTA_ACQUIRED_XA_RESOURCE_INIT_ERROR:
176  break;
177  case NONE:
178  ret_cod = LIXA_RC_OK;
179  break;
180  default:
181  ret_cod = LIXA_RC_INTERNAL_ERROR;
182  } /* switch (excp) */
183  } /* TRY-CATCH */
184  LIXA_TRACE(("xta_mysql_xa_resource_init/excp=%d/"
185  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
186  return ret_cod;
187 }
188 
189 
190 
192 {
193  enum Exception { NONE } excp;
194  int ret_cod = LIXA_RC_INTERNAL_ERROR;
195 
196  LIXA_TRACE(("xta_mysql_xa_resource_clean\n"));
197  TRY {
198  /* clean MySQL XA function pointers */
199  xa_resource->xa_resource.act_rsrmgr_config.lixa_iface.std = NULL;
200  /* clean "base class" (xta_acquired_xa_resource_t) properties */
202  (xta_acquired_xa_resource_t *)xa_resource);
203 
204  THROW(NONE);
205  } CATCH {
206  switch (excp) {
207  case NONE:
208  ret_cod = LIXA_RC_OK;
209  break;
210  default:
211  ret_cod = LIXA_RC_INTERNAL_ERROR;
212  } /* switch (excp) */
213  } /* TRY-CATCH */
214  LIXA_TRACE(("xta_mysql_xa_resource_clean/excp=%d/"
215  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
216  return;
217 }
218 
219 
220 
221 int xta_mysql_xa_open(xta_xa_resource_t *context, char *xa_info,
222  int rmid, long flags)
223 {
224  enum Exception { OBJ_CORRUPTED
225  , NONE } excp;
226  int ret_cod = XAER_RMERR;
227 
228  LIXA_TRACE(("xta_mysql_xa_open\n"));
229  TRY {
230  xta_mysql_xa_resource_t *xa_resource =
231  (xta_mysql_xa_resource_t *)context;
232  if (NULL != xa_resource->connection) {
233  LIXA_TRACE(("xta_mysql_xa_open: MySQL connection is already open "
234  "(%p)\n", xa_resource->connection));
235  } else {
236  LIXA_TRACE(("xta_mysql_xa_open: MySQL connection is NULL!\n"));
237  THROW(OBJ_CORRUPTED);
238  }
239  /* save the connection state: backward compatibility with switch
240  * file based implemetation */
241  xa_resource->lssr.rmid = rmid;
242  xa_resource->lssr.rm_type = LIXA_SW_STATUS_RM_TYPE_MYSQL;
243  xa_resource->lssr.state.R = 1;
244  xa_resource->lssr.conn = (gpointer)xa_resource->connection;
245 
246  THROW(NONE);
247  } CATCH {
248  switch (excp) {
249  case OBJ_CORRUPTED:
250  break;
251  case NONE:
252  ret_cod = XA_OK;
253  break;
254  default:
255  ret_cod = XAER_RMERR;
256  } /* switch (excp) */
257  } /* TRY-CATCH */
258  LIXA_TRACE(("xta_mysql_xa_open/excp=%d/"
259  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
260  return ret_cod;
261 }
262 
263 
264 
265 int xta_mysql_xa_close(xta_xa_resource_t *context, char *xa_info,
266  int rmid, long flags)
267 {
268  enum Exception { OBJ_CORRUPTED
269  , NONE } excp;
270  int ret_cod = XAER_RMERR;
271 
272  LIXA_TRACE(("xta_mysql_xa_close\n"));
273  TRY {
275  if (NULL != this->connection) {
276  LIXA_TRACE(("xta_mysql_xa_close: MySQL connection (%p) must be "
277  "closed by the Application Program\n",
278  this->connection));
279  } else {
280  LIXA_TRACE(("xta_mysql_xa_close: MySQL connection is NULL!\n"));
281  THROW(OBJ_CORRUPTED);
282  }
283 
284  THROW(NONE);
285  } CATCH {
286  switch (excp) {
287  case OBJ_CORRUPTED:
288  break;
289  case NONE:
290  ret_cod = XA_OK;
291  break;
292  default:
293  ret_cod = XAER_RMERR;
294  } /* switch (excp) */
295  } /* TRY-CATCH */
296  LIXA_TRACE(("xta_mysql_xa_close/excp=%d/"
297  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
298  return ret_cod;
299 }
300 
301 
302 
304  const XID *xid, int rmid, long flags)
305 {
306  enum Exception { OBJ_CORRUPTED
307  , NONE } excp;
308  int ret_cod = XAER_RMERR;
309 
310  LIXA_TRACE(("xta_mysql_xa_start\n"));
311  TRY {
313  if (NULL == this->connection) {
314  LIXA_TRACE(("xta_mysql_xa_start: MySQL connection is NULL!\n"));
315  THROW(OBJ_CORRUPTED);
316  }
317  /* call legacy switch file based code */
318  ret_cod = lixa_my_start_core(&this->lssr, xid, rmid, flags);
319 
320  THROW(NONE);
321  } CATCH {
322  switch (excp) {
323  case OBJ_CORRUPTED:
324  break;
325  case NONE:
326  break;
327  default:
328  ret_cod = XAER_RMERR;
329  } /* switch (excp) */
330  } /* TRY-CATCH */
331  LIXA_TRACE(("xta_mysql_xa_start/excp=%d/"
332  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
333  return ret_cod;
334 }
335 
336 
337 
338 int xta_mysql_xa_end(xta_xa_resource_t *context, const XID *xid,
339  int rmid, long flags)
340 {
341  enum Exception { OBJ_CORRUPTED
342  , NONE } excp;
343  int ret_cod = XAER_RMERR;
344 
345  LIXA_TRACE(("xta_mysql_xa_end\n"));
346  TRY {
348  if (NULL == this->connection) {
349  LIXA_TRACE(("xta_mysql_xa_end: MySQL connection is NULL!\n"));
350  THROW(OBJ_CORRUPTED);
351  }
352  /* call legacy switch file based code */
353  ret_cod = lixa_my_end_core(&this->lssr, xid, rmid, flags);
354 
355  THROW(NONE);
356  } CATCH {
357  switch (excp) {
358  case OBJ_CORRUPTED:
359  break;
360  case NONE:
361  break;
362  default:
363  ret_cod = XAER_RMERR;
364  } /* switch (excp) */
365  } /* TRY-CATCH */
366  LIXA_TRACE(("xta_mysql_xa_end/excp=%d/"
367  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
368  return ret_cod;
369 }
370 
371 
372 
373 
374 int xta_mysql_xa_rollback(xta_xa_resource_t *context, const XID *xid,
375  int rmid, long flags)
376 {
377  enum Exception { OBJ_CORRUPTED
378  , NONE } excp;
379  int ret_cod = XAER_RMERR;
380 
381  LIXA_TRACE(("xta_mysql_xa_rollback\n"));
382  TRY {
384  if (NULL == this->connection) {
385  LIXA_TRACE(("xta_mysql_xa_rollback: MySQL connection is NULL!\n"));
386  THROW(OBJ_CORRUPTED);
387  }
388  /* call legacy switch file based code */
389  ret_cod = lixa_my_rollback_core(&this->lssr, xid, rmid, flags);
390 
391  THROW(NONE);
392  } CATCH {
393  switch (excp) {
394  case OBJ_CORRUPTED:
395  break;
396  case NONE:
397  break;
398  default:
399  ret_cod = XAER_RMERR;
400  } /* switch (excp) */
401  } /* TRY-CATCH */
402  LIXA_TRACE(("xta_mysql_xa_rollback/excp=%d/"
403  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
404  return ret_cod;
405 }
406 
407 
408 
409 int xta_mysql_xa_prepare(xta_xa_resource_t *context, const XID *xid,
410  int rmid, long flags)
411 {
412  enum Exception { OBJ_CORRUPTED
413  , NONE } excp;
414  int ret_cod = XAER_RMERR;
415 
416  LIXA_TRACE(("xta_mysql_xa_prepare\n"));
417  TRY {
419  if (NULL == this->connection) {
420  LIXA_TRACE(("xta_mysql_xa_prepare: MySQL connection is NULL!\n"));
421  THROW(OBJ_CORRUPTED);
422  }
423  /* call legacy switch file based code */
424  ret_cod = lixa_my_prepare_core(&this->lssr, xid, rmid, flags);
425 
426  THROW(NONE);
427  } CATCH {
428  switch (excp) {
429  case OBJ_CORRUPTED:
430  break;
431  case NONE:
432  break;
433  default:
434  ret_cod = XAER_RMERR;
435  } /* switch (excp) */
436  } /* TRY-CATCH */
437  LIXA_TRACE(("xta_mysql_xa_prepare/excp=%d/"
438  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
439  return ret_cod;
440 }
441 
442 
443 
444 int xta_mysql_xa_commit(xta_xa_resource_t *context, const XID *xid,
445  int rmid, long flags)
446 {
447  enum Exception { OBJ_CORRUPTED
448  , NONE } excp;
449  int ret_cod = XAER_RMERR;
450 
451  LIXA_TRACE(("xta_mysql_xa_commit\n"));
452  TRY {
454  if (NULL == this->connection) {
455  LIXA_TRACE(("xta_mysql_xa_commit: MySQL connection is NULL!\n"));
456  THROW(OBJ_CORRUPTED);
457  }
458  /* call legacy switch file based code */
459  ret_cod = lixa_my_commit_core(&this->lssr, xid, rmid, flags);
460 
461  THROW(NONE);
462  } CATCH {
463  switch (excp) {
464  case OBJ_CORRUPTED:
465  break;
466  case NONE:
467  break;
468  default:
469  ret_cod = XAER_RMERR;
470  } /* switch (excp) */
471  } /* TRY-CATCH */
472  LIXA_TRACE(("xta_mysql_xa_commit/excp=%d/"
473  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
474  return ret_cod;
475 }
476 
477 
478 
480  XID *xids, long count, int rmid, long flags)
481 {
482  enum Exception { OBJ_CORRUPTED
483  , NONE } excp;
484  int ret_cod = XAER_RMERR;
485 
486  LIXA_TRACE(("xta_mysql_xa_recover\n"));
487  TRY {
489  if (NULL == this->connection) {
490  LIXA_TRACE(("xta_mysql_xa_recover: MySQL connection is NULL!\n"));
491  THROW(OBJ_CORRUPTED);
492  }
493  /* call legacy switch file based code */
494  ret_cod = lixa_my_recover_core(&this->lssr, xids, count, rmid, flags);
495 
496  THROW(NONE);
497  } CATCH {
498  switch (excp) {
499  case OBJ_CORRUPTED:
500  break;
501  case NONE:
502  break;
503  default:
504  ret_cod = XAER_RMERR;
505  } /* switch (excp) */
506  } /* TRY-CATCH */
507  LIXA_TRACE(("xta_mysql_xa_recover/excp=%d/"
508  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
509  return ret_cod;
510 }
511 
512 
513 
514 int xta_mysql_xa_forget(xta_xa_resource_t *context, const XID *xid,
515  int rmid, long flags)
516 {
517  enum Exception { OBJ_CORRUPTED
518  , NONE } excp;
519  int ret_cod = XAER_RMERR;
520 
521  LIXA_TRACE(("xta_mysql_xa_forget\n"));
522  TRY {
524  if (NULL == this->connection) {
525  LIXA_TRACE(("xta_mysql_xa_forget: MySQL connection is NULL!\n"));
526  THROW(OBJ_CORRUPTED);
527  }
528  /* call legacy switch file based code */
529  ret_cod = lixa_my_forget_core(&this->lssr, xid, rmid, flags);
530 
531  THROW(NONE);
532  } CATCH {
533  switch (excp) {
534  case OBJ_CORRUPTED:
535  break;
536  case NONE:
537  break;
538  default:
539  ret_cod = XAER_RMERR;
540  } /* switch (excp) */
541  } /* TRY-CATCH */
542  LIXA_TRACE(("xta_mysql_xa_forget/excp=%d/"
543  "ret_cod=%d/errno=%d\n", excp, ret_cod, errno));
544  return ret_cod;
545 }
#define XAER_RMERR
Definition: xa.h:332
void xta_mysql_xa_resource_clean(xta_mysql_xa_resource_t *xa_resource)
int xta_mysql_xa_close(xta_xa_resource_t *context, char *xa_info, int rmid, long flags)
int xta_mysql_xa_end(xta_xa_resource_t *context, const XID *xid, int rmid, long flags)
#define LIXA_RC_NULL_OBJECT
Definition: lixa_errors.h:139
#define LIXA_RC_INTERNAL_ERROR
Definition: lixa_errors.h:122
int xta_mysql_xa_open(xta_xa_resource_t *context, char *xa_info, int rmid, long flags)
#define LIXA_RC_OK
Definition: lixa_errors.h:115
void xta_acquired_xa_resource_clean(xta_acquired_xa_resource_t *xa_resource)
int xta_mysql_xa_commit(xta_xa_resource_t *context, const XID *xid, int rmid, long flags)
int xta_mysql_xa_start(xta_xa_resource_t *context, const XID *xid, int rmid, long flags)
int xta_mysql_xa_prepare(xta_xa_resource_t *context, const XID *xid, int rmid, long flags)
static const struct xta_iface_s xta_mysql_iface
#define LIXA_RC_G_TRY_MALLOC_ERROR
Definition: lixa_errors.h:563
void xta_mysql_xa_resource_delete(xta_mysql_xa_resource_t *xa_resource)
void lixa_iface_set_xta(lixa_iface_t *iface, const struct xta_iface_s *xta, xta_xa_resource_t *context)
int xta_mysql_xa_rollback(xta_xa_resource_t *context, const XID *xid, int rmid, long flags)
Definition: xa.h:28
struct lixa_sw_status_rm_s lssr
long flags
Definition: xta_iface.h:42
struct act_rsrmgr_config_s act_rsrmgr_config
int xta_mysql_xa_forget(xta_xa_resource_t *context, const XID *xid, int rmid, long flags)
int xta_acquired_xa_resource_init(xta_acquired_xa_resource_t *xa_resource, const struct xta_iface_s *iface, const char *name, const char *open_info)
char name[RMNAMESZ]
Definition: xta_iface.h:38
int xta_mysql_xa_resource_init(xta_mysql_xa_resource_t *xa_resource, MYSQL *connection, const char *name, const char *open_info)
#define XA_OK
Definition: xa.h:324
xta_mysql_xa_resource_t * xta_mysql_xa_resource_new(MYSQL *connection, const char *name, const char *open_info)
#define TMNOFLAGS
Definition: xa.h:141
int xta_mysql_xa_recover(xta_xa_resource_t *context, XID *xids, long count, int rmid, long flags)

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