From 58198eaf4892c96028c67af3417fd9de0916bbb7 Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 20 Mar 2007 05:22:30 +0000 Subject: [PATCH] robustification suggested by Scott McKellar -- early exit on transactional errors, minor memory leak plugging, casting bug that affects portability git-svn-id: svn://svn.open-ils.org/ILS/trunk@7084 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/c-apps/oils_dataloader.c | 48 ++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/Open-ILS/src/c-apps/oils_dataloader.c b/Open-ILS/src/c-apps/oils_dataloader.c index 7a647dcb87..f44a10a2cb 100644 --- a/Open-ILS/src/c-apps/oils_dataloader.c +++ b/Open-ILS/src/c-apps/oils_dataloader.c @@ -12,9 +12,15 @@ #define CSTORE "open-ils.cstore" #define APPNAME "oils_dataloader" +#define ESUCCESS 0 +#define ECOMMITERROR -1 +#define ECOMMANDERROR -2 +#define EROLLBACKERROR -3 + int sendCommand ( char* ); int startTransaction ( ); -int endTransaction ( ); +int commitTransaction ( ); +int rollbackTransaction ( ); osrfHash* mnames = NULL; @@ -97,9 +103,9 @@ int main (int argc, char **argv) { growing_buffer* json = buffer_init(128); char* json_string; - char c; + int c; int counter = 0; - while ((c = (char)getchar())) { + while ((c = getchar())) { switch(c) { case '\n': case EOF: @@ -114,6 +120,15 @@ int main (int argc, char **argv) { method, json_string ); + + if (!rollbackTransaction()) { + osrfAppSessionFree(session); + osrfLogError(OSRF_LOG_MARK, "An error occured while attempting to complete a transaction"); + return EROLLBACKERROR; + } + + osrfAppSessionFree(session); + return ECOMMANDERROR; } counter++; @@ -129,16 +144,19 @@ int main (int argc, char **argv) { } // clean up, commit, go away - if (!endTransaction()) { + if (!commitTransaction()) { osrfLogError(OSRF_LOG_MARK, "An error occured while attempting to complete a transaction"); + osrfAppSessionFree(session); + return ECOMMITERROR; } osrfAppSessionFree(session); + free(method); - return 0; + return ESUCCESS; } -int endTransaction () { +int commitTransaction () { int ret = 1; jsonObject* data; int req_id = osrfAppSessionMakeRequest( session, NULL, "open-ils.cstore.transaction.commit", 1, NULL ); @@ -156,6 +174,24 @@ int endTransaction () { return ret; } +int rollbackTransaction () { + int ret = 1; + jsonObject* data; + int req_id = osrfAppSessionMakeRequest( session, NULL, "open-ils.cstore.transaction.rollback", 1, NULL ); + osrf_message* res = osrfAppSessionRequestRecv( session, req_id, 5 ); + if ( (data = jsonObjectClone(osrfMessageGetResult(res))) ) { + if(!(trans_id = jsonObjectGetString(data))) { + ret = 0; + } + jsonObjectFree(data); + } else { + ret = 0; + } + osrfMessageFree(res); + + return ret; +} + int startTransaction () { int ret = 1; jsonObject* data; -- 2.11.0