--- parser3/src/classes/op.C 2001/12/15 21:28:17 1.64 +++ parser3/src/classes/op.C 2002/01/16 10:28:33 1.67 @@ -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.64 2001/12/15 21:28:17 paf Exp $ + $Id: op.C,v 1.67 2002/01/16 10:28:33 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 @@ -396,20 +379,21 @@ 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) { - // ^cache[file_spec](lifespan){code} time=0 no cache Pool& pool=r.pool(); // file_spec, expires, body code - const String &file_spec=params->as_string(0, "key must be string"); + const String &file_spec=r.absolute(params->as_string(0, "filespec must be string")); + if(params->size()==1) { // delete + cache_delete(pool, file_spec); + return; + } + time_t lifespan=(time_t)params->as_double(1, "lifespan must be number", r); Value& body_code=params->as_junction(2, "body must be code"); @@ -486,8 +470,9 @@ MOP::MOP(Pool& apool) : Methoded(apool), add_native_method("connect", Method::CT_ANY, _connect, 2, 2); + // ^cache[file_spec] delete cache // ^cache[file_spec](time){code} time=0 no cache - add_native_method("cache", Method::CT_ANY, _cache, 3, 3); + add_native_method("cache", Method::CT_ANY, _cache, 1, 3); // switch