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 |
|
23 |
#include <boost/bind.hpp> |
|
24 |
||
2241.3.15
by Olaf van der Spek
Refactor |
25 |
#include <drizzled/identifier.h> |
2073.2.1
by Brian Aker
Remove custom error. |
26 |
#include <drizzled/error.h> |
27 |
#include <drizzled/catalog.h> |
|
28 |
#include <drizzled/plugin/catalog.h> |
|
1960.1.5
by Brian Aker
Merging in the first pass through the catalog work. |
29 |
|
1960.1.8
by Brian Aker
Big hunk of burning create/drop work. |
30 |
#include <boost/unordered_map.hpp> |
31 |
#include <boost/thread/mutex.hpp> |
|
32 |
||
1960.1.5
by Brian Aker
Merging in the first pass through the catalog work. |
33 |
namespace drizzled { |
2252.1.20
by Olaf van der Spek
Common fwd |
34 |
namespace catalog { |
2039.6.3
by Brian Aker
Update for session to have a catalog object. |
35 |
|
1960.1.5
by Brian Aker
Merging in the first pass through the catalog work. |
36 |
class Cache |
37 |
{
|
|
2278.2.2
by Olaf van der Spek
Catalog Cache |
38 |
public: |
2278.2.1
by Olaf van der Spek
Catalog Cache |
39 |
static size_t size() |
1960.1.5
by Brian Aker
Merging in the first pass through the catalog work. |
40 |
{
|
41 |
return cache.size(); |
|
42 |
}
|
|
43 |
||
2278.2.2
by Olaf van der Spek
Catalog Cache |
44 |
static Instance::shared_ptr find(const identifier::Catalog&, error_t&); |
45 |
static bool exist(const identifier::Catalog&); |
|
46 |
static bool erase(const identifier::Catalog&, error_t&); |
|
47 |
static bool insert(const identifier::Catalog&, Instance::shared_ptr, error_t&); |
|
48 |
static bool lock(const identifier::Catalog&, error_t&); |
|
49 |
static bool unlock(const identifier::Catalog&, error_t&); |
|
50 |
static void copy(catalog::Instance::vector&); |
|
51 |
||
52 |
typedef boost::unordered_map<identifier::Catalog, catalog::Instance::shared_ptr> unordered_map; |
|
1960.1.5
by Brian Aker
Merging in the first pass through the catalog work. |
53 |
|
2278.2.1
by Olaf van der Spek
Catalog Cache |
54 |
static unordered_map cache; |
55 |
static boost::mutex _mutex; |
|
1960.1.5
by Brian Aker
Merging in the first pass through the catalog work. |
56 |
};
|
57 |
||
2039.6.3
by Brian Aker
Update for session to have a catalog object. |
58 |
|
59 |
namespace lock { |
|
60 |
||
61 |
class Erase |
|
62 |
{
|
|
63 |
bool _locked; |
|
64 |
const identifier::Catalog &identifier; |
|
2278.2.2
by Olaf van der Spek
Catalog Cache |
65 |
error_t error; |
2039.6.3
by Brian Aker
Update for session to have a catalog object. |
66 |
|
67 |
public: |
|
68 |
Erase(const identifier::Catalog &identifier_arg) : |
|
69 |
_locked(false), |
|
70 |
identifier(identifier_arg) |
|
71 |
{
|
|
72 |
init(); |
|
73 |
}
|
|
74 |
||
75 |
bool locked () const |
|
76 |
{
|
|
77 |
return _locked; |
|
78 |
}
|
|
79 |
||
80 |
~Erase() |
|
81 |
{
|
|
82 |
if (_locked) |
|
83 |
{
|
|
2278.2.1
by Olaf van der Spek
Catalog Cache |
84 |
if (not catalog::Cache::unlock(identifier, error)) |
2039.6.3
by Brian Aker
Update for session to have a catalog object. |
85 |
{
|
2073.2.1
by Brian Aker
Remove custom error. |
86 |
my_error(error, identifier); |
2039.6.3
by Brian Aker
Update for session to have a catalog object. |
87 |
assert(0); |
88 |
}
|
|
89 |
}
|
|
90 |
}
|
|
91 |
||
92 |
private: |
|
93 |
void init() |
|
94 |
{
|
|
95 |
// We insert a lock into the cache, if this fails we bail.
|
|
2278.2.1
by Olaf van der Spek
Catalog Cache |
96 |
if (not catalog::Cache::lock(identifier, error)) |
2039.6.3
by Brian Aker
Update for session to have a catalog object. |
97 |
{
|
98 |
assert(0); |
|
99 |
return; |
|
100 |
}
|
|
101 |
||
102 |
_locked= true; |
|
103 |
}
|
|
104 |
};
|
|
105 |
||
106 |
||
107 |
class Create |
|
108 |
{
|
|
109 |
bool _locked; |
|
110 |
const identifier::Catalog &identifier; |
|
2278.2.2
by Olaf van der Spek
Catalog Cache |
111 |
error_t error; |
2039.6.3
by Brian Aker
Update for session to have a catalog object. |
112 |
|
113 |
public: |
|
114 |
Create(const identifier::Catalog &identifier_arg) : |
|
115 |
_locked(false), |
|
116 |
identifier(identifier_arg) |
|
117 |
{
|
|
118 |
init(); |
|
119 |
}
|
|
120 |
||
121 |
bool locked () const |
|
122 |
{
|
|
123 |
return _locked; |
|
124 |
}
|
|
125 |
||
126 |
~Create() |
|
127 |
{
|
|
128 |
if (_locked) |
|
129 |
{
|
|
2278.2.1
by Olaf van der Spek
Catalog Cache |
130 |
if (not catalog::Cache::unlock(identifier, error)) |
2039.6.3
by Brian Aker
Update for session to have a catalog object. |
131 |
{
|
2073.2.1
by Brian Aker
Remove custom error. |
132 |
my_error(error, identifier); |
2039.6.3
by Brian Aker
Update for session to have a catalog object. |
133 |
assert(0); |
134 |
}
|
|
135 |
}
|
|
136 |
}
|
|
137 |
||
138 |
||
139 |
private: |
|
140 |
void init() |
|
141 |
{
|
|
142 |
// We insert a lock into the cache, if this fails we bail.
|
|
2278.2.1
by Olaf van der Spek
Catalog Cache |
143 |
if (not catalog::Cache::lock(identifier, error)) |
2039.6.3
by Brian Aker
Update for session to have a catalog object. |
144 |
{
|
2073.2.1
by Brian Aker
Remove custom error. |
145 |
my_error(error, identifier); |
2039.6.3
by Brian Aker
Update for session to have a catalog object. |
146 |
return; |
147 |
}
|
|
148 |
||
149 |
_locked= true; |
|
150 |
}
|
|
151 |
};
|
|
152 |
||
153 |
} /* namespace lock */ |
|
1960.1.5
by Brian Aker
Merging in the first pass through the catalog work. |
154 |
} /* namespace catalog */ |
155 |
} /* namespace drizzled */ |
|
156 |