/* * * ProLinga-Data * * Copyright (C) 2002-2008 Xobas Software. * All rights reserved. * * This file is part of ProLinga-Data. * * ProLinga-Data is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ProLinga-Data is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ProLinga-Data. If not, see . * * More information is available at the following addresses: * * Website : http://www.prolinga.org * * Email : prolinga-list@prolinga.org * * */ #include "DatCommon.h" #include #include #include #include #include "DatMain.hpp" #include "DCTransaction.hpp" #include "DCSession.hpp" #include "DatConfig.hpp" extern DCSessionPtr sesPtr; int DCTransaction(const xmlDocPtr docObj, const char *sessionId, char **externalError, xmlDocPtr *docReturn) { xmlNodePtr curReturn; xmlXPathContextPtr ctxObj; xmlXPathObjectPtr resObj; GdaConnection *connection; char *objDataSource, *transMode, *transId, *isolationLevel; int dbStatus = 0; /* Create XPath Environment */ ctxObj = xmlXPathNewContext(docObj); /* Get DataSource name */ resObj = xmlXPathEval((const xmlChar *)"/ProLinga/Object/@DataSource", ctxObj); objDataSource = (char *)xmlXPathCastToString(resObj); /* Get Connection Object to Data Source */ connection = sesPtr->getGdaConnection(sesPtr, sessionId, objDataSource); if (connection == NULL) return 70002; /* Get Transaction Mode */ resObj = xmlXPathEval((const xmlChar *)"/ProLinga/Object/Transaction/@Mode", ctxObj); transMode = (char *)xmlXPathCastToString(resObj); if (strcmp(transMode, "Begin") == 0) { /* Check if there is no transaction in progress */ transId = sesPtr->getTransactionId(sesPtr, sessionId); if (transId != NULL) return 70006; /* Create new transaction */ //trans = gda_transaction_status_new(sessionId); /* Get Isolation Level */ resObj = xmlXPathEval((const xmlChar *)"/ProLinga/Object/Transaction/IsolationLevel", ctxObj); isolationLevel = (char *)xmlXPathCastToString(resObj); /* Begin transaction */ if (strcmp(isolationLevel, "Unknown") == 0) gda_connection_begin_transaction(connection, sessionId, GDA_TRANSACTION_ISOLATION_UNKNOWN, NULL); else if (strcmp(isolationLevel, "ReadCommitted") == 0) gda_connection_begin_transaction(connection, sessionId, GDA_TRANSACTION_ISOLATION_READ_COMMITTED, NULL); else if (strcmp(isolationLevel, "ReadUncommitted") == 0) gda_connection_begin_transaction(connection, sessionId, GDA_TRANSACTION_ISOLATION_READ_UNCOMMITTED, NULL); else if (strcmp(isolationLevel, "RepeatableRead") == 0) gda_connection_begin_transaction(connection, sessionId, GDA_TRANSACTION_ISOLATION_REPEATABLE_READ, NULL); else if (strcmp(isolationLevel, "Serializable") == 0) gda_connection_begin_transaction(connection, sessionId, GDA_TRANSACTION_ISOLATION_SERIALIZABLE, NULL); /* Begin transaction */ //gda_connection_begin_transaction(connection, trans); /* Store transaction */ sesPtr->putTransactionId(sesPtr, sessionId, sessionId); } else if (strcmp(transMode, "Commit") == 0) { /* Get Transaction */ transId = sesPtr->getTransactionId(sesPtr, sessionId); if (transId == NULL) return 70007; /* Commit */ gda_connection_commit_transaction(connection, sessionId, NULL); /* Clear memory */ sesPtr->clearTransactionId(sesPtr, sessionId); } else if (strcmp(transMode, "Rollback") == 0) { /* Get Transaction */ transId = sesPtr->getTransactionId(sesPtr, sessionId); if (transId == NULL) return 70007; /* Rollback */ gda_connection_rollback_transaction(connection, sessionId, NULL); /* Clear memory */ sesPtr->clearTransactionId(sesPtr, sessionId); } /* Create return document */ *docReturn = xmlNewDoc((const xmlChar *)XML_VERSION); (*docReturn)->children = xmlNewDocNode(*docReturn, NULL, (const xmlChar *)ROOT_ELEM, NULL); curReturn = xmlDocGetRootElement(*docReturn); curReturn = xmlNewTextChild(curReturn, NULL, (const xmlChar *)"Object", (const xmlChar *)""); xmlNewProp(curReturn, (const xmlChar *)"DataSource", (const xmlChar *)objDataSource); /* Return */ return dbStatus; }