~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/catalog/cache.cc

  • Committer: Brian Aker
  • Date: 2011-01-12 06:45:23 UTC
  • mto: (2073.1.4 catalogs)
  • mto: This revision was merged to the branch mainline in revision 2080.
  • Revision ID: brian@tangent.org-20110112064523-rqhptaqbph22qmj1
RemoveĀ customĀ error.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include "config.h"
22
 
#include "drizzled/catalog.h"
23
 
#include "drizzled/catalog/cache.h"
 
22
 
 
23
#include <drizzled/catalog/cache.h>
24
24
 
25
25
namespace drizzled {
26
26
namespace catalog {
27
27
 
28
 
Instance::shared_ptr Cache::find(const identifier::Catalog &identifier, catalog::error_t &error)
 
28
Instance::shared_ptr Cache::find(const identifier::Catalog &identifier, drizzled::error_t &error)
29
29
{
30
30
  boost::mutex::scoped_lock scopedLock(_mutex);
31
31
  unordered_map::iterator iter= cache.find(identifier);
32
32
  if (iter != cache.end())
33
33
  {
34
34
    if (not (*iter).second)
35
 
      error= LOCKED;
 
35
    {
 
36
      error= ER_CATALOG_NO_LOCK;
 
37
    }
 
38
    else
 
39
    {
 
40
      error= EE_OK;
 
41
    }
36
42
 
37
43
    return (*iter).second;
38
44
  }
39
45
 
40
 
  error= NOT_FOUND;
 
46
  error= ER_CATALOG_DOES_NOT_EXIST;
41
47
  return catalog::Instance::shared_ptr();
42
48
}
43
49
 
53
59
  return false;
54
60
}
55
61
 
56
 
bool Cache::erase(const identifier::Catalog &identifier, catalog::error_t &error)
 
62
bool Cache::erase(const identifier::Catalog &identifier, drizzled::error_t &error)
57
63
{
58
64
  boost::mutex::scoped_lock scopedLock(_mutex);
59
65
 
67
73
 
68
74
    assert(0); // This should be imposssible
69
75
  }
70
 
  error= NOT_FOUND;
 
76
  error= ER_CATALOG_DOES_NOT_EXIST;
71
77
 
72
78
  return false;
73
79
}
74
80
 
75
 
bool Cache::unlock(const identifier::Catalog &identifier, catalog::error_t &error)
 
81
bool Cache::unlock(const identifier::Catalog &identifier, drizzled::error_t &error)
76
82
{
77
83
  boost::mutex::scoped_lock scopedLock(_mutex);
78
84
 
88
94
 
89
95
      assert(0); // This should be imposssible
90
96
    }
91
 
    error= FOUND;
 
97
    error= EE_OK;
92
98
  }
93
99
  else
94
100
  {
95
 
    error= NOT_FOUND;
 
101
    error= ER_CATALOG_DOES_NOT_EXIST;
96
102
  }
97
103
 
98
104
  return false;
99
105
}
100
106
 
101
 
bool Cache::lock(const identifier::Catalog &identifier, catalog::error_t &error)
 
107
bool Cache::lock(const identifier::Catalog &identifier, drizzled::error_t &error)
102
108
{
103
109
  boost::mutex::scoped_lock scopedLock(_mutex);
104
110
  std::pair<unordered_map::iterator, bool> ret= cache.insert(std::make_pair(identifier, catalog::Instance::shared_ptr()));
107
113
  {
108
114
    if (ret.first->second)
109
115
    {
110
 
      error= FOUND;
 
116
      error= EE_OK;
111
117
    }
112
118
    else
113
119
    {
114
 
      error= LOCKED;
 
120
      error= ER_CATALOG_NO_LOCK;
115
121
    }
116
122
  }
117
123
 
118
124
  return ret.second;
119
125
}
120
126
 
121
 
bool Cache::insert(const identifier::Catalog &identifier, catalog::Instance::shared_ptr instance, catalog::error_t &error)
 
127
bool Cache::insert(const identifier::Catalog &identifier, catalog::Instance::shared_ptr instance, drizzled::error_t &error)
122
128
{
123
129
  boost::mutex::scoped_lock scopedLock(_mutex);
124
130
  std::pair<unordered_map::iterator, bool> ret= cache.insert(std::make_pair(identifier, instance));
127
133
  {
128
134
    if (ret.first->second)
129
135
    {
130
 
      error= FOUND;
 
136
      error= EE_OK;
131
137
    }
132
138
    else
133
139
    {
134
 
      error= LOCKED;
 
140
      error= ER_CATALOG_NO_LOCK;
135
141
    }
136
142
  }
137
143