--- parser3/src/classes/op.C 2001/12/19 16:17:26 1.65 +++ parser3/src/classes/op.C 2002/01/25 11:33:45 1.68 @@ -4,7 +4,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://paf.design.ru) - $Id: op.C,v 1.65 2001/12/19 16:17:26 paf Exp $ + $Id: op.C,v 1.68 2002/01/25 11:33:45 paf Exp $ */ #include "classes.h" @@ -124,7 +124,10 @@ static void _process(Request& r, const S // process source code, append processed methods to 'self' class // maybe-define new @main - r.use_buf(source.cstr(String::UL_UNSPECIFIED, r.connection), place, &self_class); + r.use_buf( + source.cstr(String::UL_UNSPECIFIED, r.connection(0)), + place, + &self_class); // maybe-execute @main[] if(const Method *method=self_class.get_method(*main_method_name)) { @@ -245,7 +248,7 @@ struct timeval mt[2]; gettimeofday(&mt[0],NULL); #endif // connect - SQL_Connection& connection=SQL_driver_manager->get_connection( + SQL_Connection_ptr connection=SQL_driver_manager->get_connection( url.as_string(), method_name, protocol2driver_and_client); #ifdef RESOURCES_DEBUG @@ -258,35 +261,15 @@ for(int i=0;i<2;i++) r.sql_connect_time+=t[1]-t[0]; #endif - // remember/set current connection - SQL_Connection *saved_connection=r.connection; - r.connection=&connection; + Temp_connection temp_connection(r, connection.get()); // execute body try { - try { - r.write_assign_lang(r.process(body_code)); - - connection.commit(); - } catch(...) { // process/commit problem - connection.rollback(); - - /*re*/throw; - } - - } catch(...) { - // close connection [cache it] - connection.close(); - // recall current connection from remembered - r.connection=saved_connection; - - /*re*/throw; + r.write_assign_lang(r.process(body_code)); + + } catch(...) { // process/commit problem + connection->mark_to_rollback(); + /*re*/throw; } - - // and anyway - // close connection [cache it] - connection.close(); - // recall current connection from remembered - r.connection=saved_connection; } #ifndef DOXYGEN @@ -355,10 +338,10 @@ struct Data_string_serialized_prolog { }; #endif -void cache_delete(Pool& pool, const String& file_spec) { - file_delete(pool, file_spec, false/*fail_on_read_problem*/); +void cache_delete(const String& file_spec) { + file_delete(file_spec, false/*fail_on_read_problem*/); } -void cache_put(Pool& pool, const String& file_spec, const String& data_string) { +void cache_put(const String& file_spec, const String& data_string) { void *data; size_t data_size; data_string.serialize( sizeof(Data_string_serialized_prolog), @@ -368,7 +351,7 @@ void cache_put(Pool& pool, const String& prolog.version=DATA_STRING_SERIALIZED_VERSION; - file_write(pool, + file_write( file_spec, data, data_size, false/*as_text*/); @@ -396,12 +379,9 @@ String *cache_get(Pool& pool, const Stri prolog.version, DATA_STRING_SERIALIZED_VERSION); String& result=*new(pool) String(pool); - if(data_size) { - result.deserialize( - sizeof(Data_string_serialized_prolog), - data, data_size, file_spec.cstr()); - } - + result.deserialize( + sizeof(Data_string_serialized_prolog), + data, data_size, file_spec.cstr()); return &result; } static void _cache(Request& r, const String& method_name, MethodParams *params) { @@ -410,7 +390,7 @@ static void _cache(Request& r, const Str // file_spec, expires, body code const String &file_spec=r.absolute(params->as_string(0, "filespec must be string")); if(params->size()==1) { // delete - cache_delete(pool, file_spec); + cache_delete(file_spec); return; } @@ -423,7 +403,7 @@ static void _cache(Request& r, const Str // {file_spec} modification time if(!file_stat(file_spec, size, atime, mtime, ctime, false/*no exception on error*/) || (time(0)-mtime) > lifespan) // cached file expired - cache_delete(pool, file_spec); + cache_delete(file_spec); else if(String *cached_body=cache_get(pool, file_spec)) { // have cached copy? // write it out @@ -432,14 +412,14 @@ static void _cache(Request& r, const Str return; } } else // 'lifespan'=0, forget cached copy - cache_delete(pool, file_spec); + cache_delete(file_spec); // process Value& processed_body=r.process(body_code); // put it to cache if 'lifespan' specified if(lifespan) - cache_put(pool, file_spec, processed_body.as_string()); + cache_put(file_spec, processed_body.as_string()); // write it out r.write_assign_lang(processed_body);