~drizzle-trunk/drizzle/development

1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2010 Brian Aker
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
21
#pragma once
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
22
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
23
#include <boost/thread/mutex.hpp>
1960.1.6 by Brian Aker
Adding in the engine interface. The filesystem catalog will now handle
24
#include <boost/make_shared.hpp>
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
25
2154.2.13 by Brian Aker
Another dead use of session.
26
#include <drizzled/message/catalog.h>
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
27
28
namespace drizzled {
29
namespace catalog {
30
31
class Instance
32
{
2017.3.1 by Brian Aker
Merge catalog with current trunk.
33
  Instance() :
34
    _locked(false),
35
    _lock_id(0)
36
  { };
37
38
  bool _locked;
39
  drizzled::session_id_t _lock_id;
1960.1.6 by Brian Aker
Adding in the engine interface. The filesystem catalog will now handle
40
  message::catalog::shared_ptr _message;
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
41
  mutable boost::mutex _schema_lock;
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
42
  mutable boost::mutex _system_variable_lock;
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
43
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
44
45
public:
46
  typedef boost::shared_ptr<Instance> shared_ptr;
47
  typedef std::vector<shared_ptr> vector;
2039.6.4 by Brian Aker
Merge in local_instance change.
48
  typedef const Instance* const_pointer;
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
49
  typedef const Instance& const_reference;
50
  typedef Instance& reference;
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
51
1960.1.6 by Brian Aker
Adding in the engine interface. The filesystem catalog will now handle
52
  Instance(message::catalog::shared_ptr &message_arg)
53
  {
54
    _message= message_arg;
55
  };
56
57
  Instance(const message::catalog::shared_ptr &message_arg)
58
  {
59
    _message= message_arg;
60
  };
61
2104.1.2 by Brian Aker
Update console to switch to different catalogs.
62
  static shared_ptr make_shared(message::catalog::shared_ptr &message_arg)
63
  {
64
    assert(not message_arg->name().empty());
65
    return boost::make_shared<Instance>(message_arg);
66
  };
67
2104.1.4 by Brian Aker
Small cleanup of creation methods.
68
  static shared_ptr make_shared(const identifier::Catalog &identifier)
1960.1.6 by Brian Aker
Adding in the engine interface. The filesystem catalog will now handle
69
  {
1960.1.12 by Brian Aker
Add in the schema and table make_shared methods.
70
    drizzled::message::catalog::shared_ptr new_message= drizzled::message::catalog::make_shared(identifier);
2039.6.4 by Brian Aker
Merge in local_instance change.
71
    assert(not new_message->name().empty());
1960.1.6 by Brian Aker
Adding in the engine interface. The filesystem catalog will now handle
72
    return boost::make_shared<Instance>(new_message);
73
  }
74
75
  const std::string &getName() const
76
  {
77
    assert(_message);
78
    return _message->name();
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
79
  }
1960.1.8 by Brian Aker
Big hunk of burning create/drop work.
80
2039.6.4 by Brian Aker
Merge in local_instance change.
81
  const std::string &name() const
82
  {
83
    assert(_message);
84
    return _message->name();
85
  }
86
1960.1.8 by Brian Aker
Big hunk of burning create/drop work.
87
  message::catalog::shared_ptr message() const
88
  {
89
    return _message;
90
  }
2017.3.1 by Brian Aker
Merge catalog with current trunk.
91
92
  bool locked() const
93
  {
94
    return _locked;
95
  }
96
97
  bool lock(drizzled::session_id_t id)
98
  {
99
    if (_locked and _lock_id == id)
100
    {
101
      assert(0); // We shouldn't support recursion
102
      return true;
103
    }
104
    else if (_locked)
105
    {
106
      return false;
107
    }
108
109
    _locked= true;
110
    _lock_id= id;
111
112
    return true;
113
  }
114
115
  bool unlock(drizzled::session_id_t id)
116
  {
117
    if (_locked and _lock_id == id)
118
    {
119
      _locked= false;
120
      _lock_id= 0;
121
122
      return true;
123
    }
124
125
    return false;
126
  }
2060.4.2 by Brian Aker
A few small fixes, plus move the schema lock to the actual catalog.
127
128
  boost::mutex &schemaLock()
129
  {
130
    return _schema_lock;
131
  }
2114.3.1 by Brian Aker
Move variable lock into the catalog that the variables belong too.
132
133
  boost::mutex &systemVariableLock()
134
  {
135
    return _system_variable_lock;
136
  }
1960.1.5 by Brian Aker
Merging in the first pass through the catalog work.
137
};
138
139
} /* namespace catalog */
140
} /* namespace drizzled */
141