Project

General

Profile

Support #4352 ยป example ressource.cpp

Thibault Lapassade, 07/28/2015 01:55 PM

 
Ressource::Ressource(Wt::WObject* parent_p_p, Session* session_p):
Wt::WResource(parent_p_p),
mutex_m(),
session_m(session_p)
{
}

void Ressource::handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response)
{
mutex_m.lock();
Wt::log("info") << "[PUBLIC API] Identifying";
// Setting the session
if (!session_m)
{
session_m = new Session("db");
Session::configureAuth();
}

// transaction
{
try
{
Wt::Dbo::Transaction transaction(*session_m);

// check whether the user exists
Wt::Dbo::ptr<Object> objectToFind_l = session_m->query<Wt::Dbo::ptr<Object> >("select o from object o").where("o.data LIKE \"data\"");

if (objectToFind_l)
{
//Do some stuff
}
else
{
//Send error
}
mutex_m.unlock();
std::cout << "Mutex unlocked" << std::endl;
}
catch (Wt::Dbo::Exception const& e)
{
//Send error
mutex_m.unlock();
std::cout << "Mutex unlocked" << std::endl;
}
}
}
    (1-1/1)