~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/user_locks/get_lock.cc

  • Committer: Olaf van der Spek
  • Date: 2011-06-23 11:44:30 UTC
  • mto: This revision was merged to the branch mainline in revision 2348.
  • Revision ID: olafvdspek@gmail.com-20110623114430-no355yypk4y3icqb
Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
22
 
#include "plugin/user_locks/module.h"
23
 
#include "plugin/user_locks/lock_storage.h"
 
21
#include <config.h>
 
22
#include <plugin/user_locks/module.h>
 
23
#include <plugin/user_locks/lock_storage.h>
24
24
 
25
25
#include <string>
26
26
 
43
43
  }
44
44
  null_value= false;
45
45
 
46
 
  std::cerr << "Trying to create " << res->c_str() << "\n";
47
 
 
48
 
  user_locks::Storable *list= static_cast<user_locks::Storable *>(getSession().getProperty("user_locks"));
 
46
  user_locks::Storable *list= getSession().getProperty<user_locks::Storable>("user_locks");
49
47
  if (list) // To be compatible with MySQL, we will now release all other locks we might have.
50
48
    list->erase_all();
51
49
 
52
 
  bool result;
 
50
  drizzled::identifier::user::ptr user_identifier(getSession().user());
53
51
  {
54
52
    boost::this_thread::restore_interruption dl(getSession().getThreadInterupt());
55
53
 
56
 
    try {
57
 
      result= user_locks::Locks::getInstance().lock(getSession().getSessionId(), Key(getSession().getSecurityContext(), res->c_str()), wait_time);
 
54
    try 
 
55
    {
 
56
      if (not user_locks::Locks::getInstance().lock(getSession().getSessionId(), Key(*user_identifier, res->c_str()), wait_time))
 
57
        return 0;
58
58
    }
59
 
    catch(boost::thread_interrupted const& error)
 
59
    catch (boost::thread_interrupted const&)
60
60
    {
61
61
      my_error(drizzled::ER_QUERY_INTERRUPTED, MYF(0));
62
62
      null_value= true;
63
 
 
64
63
      return 0;
65
64
    }
66
65
  }
67
 
 
68
 
  if (boost::indeterminate(result))
69
 
    null_value= true;
70
 
 
71
 
  if (result)
72
 
  {
73
 
    if (not list)
74
 
    {
75
 
      list= new user_locks::Storable(getSession().getSessionId());
76
 
      getSession().setProperty("user_locks", list);
77
 
    }
78
 
 
79
 
    list->insert(Key(getSession().getSecurityContext(), res->c_str()));
80
 
 
81
 
    return 1;
82
 
  }
83
 
 
84
 
  return 0;
 
66
  if (not list)
 
67
    list= getSession().setProperty("user_locks", new user_locks::Storable(getSession().getSessionId()));
 
68
  list->insert(Key(*user_identifier, res->c_str()));
 
69
  return 1;
85
70
}
86
71
 
87
72
} /* namespace user_locks */