Dear All,XTA (XA Transaction API, http://www.tiian.org/lixa/XTA.html) is a new 
API that has been developed inside the LIXA project to support two phase commit 
transactions in the context of FaaS (Function as a Service) and microservice 
oriented, polyglot applications.
The API already supports C and C++ languages; it aims to support many more, at 
the bare minimum Python, PHP and Java.I'm currently working on supporting 
Python with PostgreSQL and MySQL, this mail thread is related to 
Python/PostgreSQL.
XTA is implemented in C language and XTA for Python is generated using SWIG: I 
would like to repeat the approach for all the languages that provides drivers 
derived from libpq-fe.h
Now the request for help: XTA needs to enlist all the resource managers (here 
PostgreSQL) to manage them using 2 phase commit, basically it requires a 
pointer (PGconn *) that must be passed to PostgresqlXaResource constructor 
(http://www.tiian.org/lixa/manuals/xta/CPP/classxta_1_1PostgresqlXaResource.html)
 to create an XTA object associated to an already opened PostgreSQL connection.
Here are the basic steps of a Python example program 
(https://github.com/tiian/lixa/blob/master/doc/examples/xta/python/example_xta_sa21.py):
# initialize XTA environment
Xta_Init()

# create a new PostgreSQL connection
# Note: using PostgreSQL Psycopg2 functions
rm1 = psycopg2.connect("dbname=testdb")

# create a new MySQL connection
# Note: using MySQLdb functions
rm2 = MySQLdb.connect("localhost", "lixa", "", "lixa")

# create a new XTA Transaction Manager object
tm = TransactionManager()

# create an XA resource for PostgreSQL
# second parameter "PostgreSQL" is descriptive
# third parameter "dbname=testdb" identifies the specific database
#
# how to retrieve PGconn * from rm1?!
xar1 = PostgresqlXaResource(rm1.conn, "PostgreSQL", "dbname=testdb")

Looking at the last statement, the stack is:- XTA native C library expects 
"PGconn *" to register the connection handler- XTA C++ wrapper expects "PGconn 
*" as the first parameter to construct the object- XTA Python (SWIG generated) 
wrapper expects a "SWIG generated" PGconn * pointer- psycopg2.connect does not 
provide me something equivalent to PGconn *, at least it seems so to me.
Stated that replacing "PGconn *" with "void *" in the API stack would not be an 
issue, the question is: what's the best way to retrieve something that can be 
transformed in a C pointer that could be passed to XTA constructor?

>From my point of view, this new API layout should solve most of the issues 
>presented by the old style TX API that I explored some years ago: 
>https://grokbase.com/t/postgresql/psycopg/122b1re71w/psycopg2-and-lixa
 Thanks in advance for your help.
Regards,
Ch.F.


Reply via email to