~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/schema_engine/schema.cc

  • Committer: Mark Atwood
  • Date: 2011-08-12 04:08:33 UTC
  • mfrom: (2385.2.17 refactor5)
  • Revision ID: me@mark.atwood.name-20110812040833-u6j85nc6ahuc0dtz
mergeĀ lp:~olafvdspek/drizzle/refactor5

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include <config.h>
22
22
 
 
23
#include <drizzled/error.h>
23
24
#include <plugin/schema_engine/schema.h>
24
25
#include <drizzled/schema.h>
25
26
#include <drizzled/sql_table.h>
26
 
#include <drizzled/global_charset_info.h>
27
27
#include <drizzled/charset.h>
28
 
#include <drizzled/charset_info.h>
29
28
#include <drizzled/cursor.h>
30
29
#include <drizzled/data_home.h>
31
30
 
34
33
#include <drizzled/execute.h>
35
34
 
36
35
#include <drizzled/internal/my_sys.h>
 
36
#include <drizzled/cached_directory.h>
37
37
 
38
38
#include <fcntl.h>
39
39
#include <sys/stat.h>
40
40
#include <sys/types.h>
41
41
 
 
42
#include <boost/foreach.hpp>
42
43
#include <google/protobuf/io/zero_copy_stream.h>
43
44
#include <google/protobuf/io/zero_copy_stream_impl.h>
44
45
 
49
50
using namespace std;
50
51
using namespace drizzled;
51
52
 
52
 
 
53
 
#define MY_DB_OPT_FILE "db.opt"
54
 
#define DEFAULT_FILE_EXTENSION ".dfe" // Deep Fried Elephant
55
 
 
56
 
Schema::Schema():
 
53
const char* MY_DB_OPT_FILE= "db.opt";
 
54
const char* DEFAULT_FILE_EXTENSION= ".dfe"; // Deep Fried Elephant
 
55
 
 
56
static const char* g_schema_exts[] = 
 
57
{
 
58
  NULL
 
59
};
 
60
 
 
61
Schema::Schema() :
57
62
  drizzled::plugin::StorageEngine("schema",
58
63
                                  HTON_ALTER_NOT_SUPPORTED |
59
64
                                  HTON_HAS_SCHEMA_DICTIONARY |
64
69
  table_definition_ext= DEFAULT_FILE_EXTENSION;
65
70
}
66
71
 
67
 
Schema::~Schema()
68
 
{
69
 
}
70
 
 
71
72
void Schema::prime()
72
73
{
73
74
  CachedDirectory directory(getDataHomeCatalog().file_string(), CachedDirectory::DIRECTORY);
74
75
  CachedDirectory::Entries files= directory.getEntries();
75
76
  boost::unique_lock<boost::shared_mutex> scopedLock(mutex);
76
77
 
77
 
  for (CachedDirectory::Entries::iterator fileIter= files.begin();
78
 
       fileIter != files.end(); fileIter++)
 
78
  BOOST_FOREACH(CachedDirectory::Entries::reference entry, files)
79
79
  {
80
 
    CachedDirectory::Entry *entry= *fileIter;
81
 
    message::Schema schema_message;
82
 
 
83
80
    if (not entry->filename.compare(GLOBAL_TEMPORARY_EXT))
84
81
      continue;
85
 
 
 
82
    message::Schema schema_message;
86
83
    if (readSchemaFile(entry->filename, schema_message))
87
84
    {
88
85
      identifier::Schema schema_identifier(schema_message.name());
90
87
      pair<SchemaCache::iterator, bool> ret=
91
88
        schema_cache.insert(make_pair(schema_identifier.getPath(), new message::Schema(schema_message)));
92
89
 
93
 
      if (ret.second == false)
94
 
      {
95
 
        abort(); // If this has happened, something really bad is going down.
96
 
      }
 
90
      assert(ret.second); // If this has happened, something really bad is going down.
97
91
    }
98
92
  }
99
93
}
100
94
 
101
 
void Schema::startup(drizzled::Session &)
102
 
{
103
 
}
104
 
 
105
 
void Schema::doGetSchemaIdentifiers(identifier::Schema::vector &set_of_names)
 
95
void Schema::doGetSchemaIdentifiers(identifier::schema::vector &set_of_names)
106
96
{
107
97
  mutex.lock_shared();
108
 
  {
109
 
    for (SchemaCache::iterator iter= schema_cache.begin();
110
 
         iter != schema_cache.end();
111
 
         iter++)
112
 
    {
113
 
      set_of_names.push_back(identifier::Schema((*iter).second->name()));
114
 
    }
115
 
  }
 
98
  BOOST_FOREACH(SchemaCache::reference iter, schema_cache)
 
99
    set_of_names.push_back(iter.second->name());
116
100
  mutex.unlock_shared();
117
101
}
118
102
 
120
104
{
121
105
  mutex.lock_shared();
122
106
  SchemaCache::iterator iter= schema_cache.find(schema_identifier.getPath());
123
 
 
124
107
  if (iter != schema_cache.end())
125
108
  {
126
 
    drizzled::message::schema::shared_ptr schema_message;
127
 
    schema_message= (*iter).second;
 
109
    drizzled::message::schema::shared_ptr schema_message= iter->second;
128
110
    mutex.unlock_shared();
129
 
 
130
111
    return schema_message;
131
112
  }
132
113
  mutex.unlock_shared();
133
 
 
134
114
  return drizzled::message::schema::shared_ptr();
135
115
}
136
116
 
152
132
    return false;
153
133
  }
154
134
 
155
 
  {
156
 
    boost::unique_lock<boost::shared_mutex> scopedLock(mutex);
157
 
    pair<SchemaCache::iterator, bool> ret=
158
 
      schema_cache.insert(make_pair(schema_identifier.getPath(), new message::Schema(schema_message)));
159
 
 
160
 
 
161
 
    if (ret.second == false)
162
 
    {
163
 
      abort(); // If this has happened, something really bad is going down.
164
 
    }
165
 
  }
166
 
 
 
135
  boost::unique_lock<boost::shared_mutex> scopedLock(mutex);
 
136
  pair<SchemaCache::iterator, bool> ret= 
 
137
    schema_cache.insert(make_pair(schema_identifier.getPath(), new message::Schema(schema_message)));
 
138
 
 
139
  assert(ret.second); // If this has happened, something really bad is going down.
167
140
  return true;
168
141
}
169
142
 
219
192
    pair<SchemaCache::iterator, bool> ret=
220
193
      schema_cache.insert(make_pair(schema_identifier.getPath(), new message::Schema(schema_message)));
221
194
 
222
 
    if (ret.second == false)
223
 
    {
224
 
      abort(); // If this has happened, something really bad is going down.
225
 
    }
 
195
    assert(ret.second); // If this has happened, something really bad is going down.
226
196
  }
227
197
 
228
198
  return true;
340
310
 
341
311
void Schema::doGetTableIdentifiers(drizzled::CachedDirectory&,
342
312
                                   const drizzled::identifier::Schema&,
343
 
                                   drizzled::identifier::Table::vector&)
344
 
{
 
313
                                   drizzled::identifier::table::vector&)
 
314
{
 
315
}
 
316
 
 
317
const char** Schema::bas_ext() const
 
318
{
 
319
  return g_schema_exts;
345
320
}