~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/information_engine/information_engine.cc

  • Committer: Brian Aker
  • Date: 2009-10-15 00:22:33 UTC
  • mto: (1183.1.11 merge)
  • mto: This revision was merged to the branch mainline in revision 1198.
  • Revision ID: brian@gaz-20091015002233-fa4ao2mbc67wls91
First pass of information engine. OMG, ponies... is it so much easier to
deal with creating and engine.

The list table iterator though... its ass, needs to go. We should also
abstract out share. Very few engines need a custom one. Just say'in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2005 MySQL AB
 
2
 
 
3
  This program is free software; you can redistribute it and/or modify
 
4
  it under the terms of the GNU General Public License as published by
 
5
  the Free Software Foundation; version 2 of the License.
 
6
 
 
7
  This program is distributed in the hope that it will be useful,
 
8
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
  GNU General Public License for more details.
 
11
 
 
12
  You should have received a copy of the GNU General Public License
 
13
  along with this program; if not, write to the Free Software
 
14
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include "information_engine.h"
 
17
#include <drizzled/table.h>
 
18
 
 
19
#include <string>
 
20
 
 
21
using namespace std;
 
22
 
 
23
static const string engine_name("INFORMATION_ENGINE");
 
24
 
 
25
/*****************************************************************************
 
26
** INFORMATION_ENGINE tables
 
27
*****************************************************************************/
 
28
 
 
29
InformationCursor::InformationCursor(drizzled::plugin::StorageEngine *engine_arg,
 
30
                                     TableShare *table_arg) :
 
31
  handler(engine_arg, table_arg)
 
32
{}
 
33
 
 
34
uint32_t InformationCursor::index_flags(uint32_t, uint32_t, bool) const
 
35
{
 
36
  return 0;
 
37
}
 
38
 
 
39
int InformationCursor::open(const char *name, int, uint32_t)
 
40
{
 
41
  InformationShare *shareable;
 
42
 
 
43
  if (!(shareable= InformationShare::get(name)))
 
44
    return(HA_ERR_OUT_OF_MEM);
 
45
 
 
46
  thr_lock_data_init(&shareable->lock, &lock, NULL);
 
47
 
 
48
  return 0;
 
49
}
 
50
 
 
51
int InformationCursor::close(void)
 
52
{
 
53
  InformationShare::free(share);
 
54
 
 
55
  return 0;
 
56
}
 
57
 
 
58
int InformationEngine::createTableImplementation(Session*, const char *,
 
59
                                                 Table *, HA_CREATE_INFO *,
 
60
                                                 drizzled::message::Table*)
 
61
{
 
62
  return 1;
 
63
}
 
64
 
 
65
int InformationEngine::deleteTableImplementation(Session*, const string)
 
66
{
 
67
  return 0;
 
68
}
 
69
 
 
70
int InformationCursor::write_row(unsigned char *)
 
71
{
 
72
  return(table->next_number_field ? update_auto_increment() : 0);
 
73
}
 
74
 
 
75
int InformationCursor::rnd_init(bool)
 
76
{
 
77
  return 0;
 
78
}
 
79
 
 
80
 
 
81
int InformationCursor::rnd_next(unsigned char *)
 
82
{
 
83
  return HA_ERR_END_OF_FILE;
 
84
}
 
85
 
 
86
 
 
87
int InformationCursor::rnd_pos(unsigned char *, unsigned char *)
 
88
{
 
89
  assert(1);
 
90
 
 
91
  return 0;
 
92
}
 
93
 
 
94
 
 
95
void InformationCursor::position(const unsigned char *)
 
96
{
 
97
  assert(1);
 
98
}
 
99
 
 
100
 
 
101
int InformationCursor::info(uint32_t flag)
 
102
{
 
103
  memset(&stats, 0, sizeof(stats));
 
104
  if (flag & HA_STATUS_AUTO)
 
105
    stats.auto_increment_value= 1;
 
106
  return(0);
 
107
}
 
108
 
 
109
int InformationCursor::external_lock(Session *, int)
 
110
{
 
111
  return 0;
 
112
}
 
113
 
 
114
 
 
115
THR_LOCK_DATA **InformationCursor::store_lock(Session *session,
 
116
                                         THR_LOCK_DATA **to,
 
117
                                         enum thr_lock_type lock_type)
 
118
{
 
119
  if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK)
 
120
  {
 
121
    /*
 
122
      Here is where we get into the guts of a row level lock.
 
123
      If TL_UNLOCK is set
 
124
      If we are not doing a LOCK Table or DISCARD/IMPORT
 
125
      TABLESPACE, then allow multiple writers
 
126
    */
 
127
 
 
128
    if ((lock_type >= TL_WRITE_CONCURRENT_INSERT &&
 
129
         lock_type <= TL_WRITE) && !session_tablespace_op(session))
 
130
      lock_type = TL_WRITE_ALLOW_WRITE;
 
131
 
 
132
    /*
 
133
      In queries of type INSERT INTO t1 SELECT ... FROM t2 ...
 
134
      MySQL would use the lock TL_READ_NO_INSERT on t2, and that
 
135
      would conflict with TL_WRITE_ALLOW_WRITE, blocking all inserts
 
136
      to t2. Convert the lock to a normal read lock to allow
 
137
      concurrent inserts to t2.
 
138
    */
 
139
 
 
140
    if (lock_type == TL_READ_NO_INSERT)
 
141
      lock_type = TL_READ;
 
142
 
 
143
    lock.type= lock_type;
 
144
  }
 
145
  *to++= &lock;
 
146
 
 
147
  return to;
 
148
}
 
149
 
 
150
static drizzled::plugin::StorageEngine *information_engine= NULL;
 
151
 
 
152
static int init(drizzled::plugin::Registry &registry)
 
153
{
 
154
 
 
155
  information_engine= new InformationEngine(engine_name);
 
156
  registry.add(information_engine);
 
157
  
 
158
  InformationShare::start();
 
159
 
 
160
  return 0;
 
161
}
 
162
 
 
163
static int finalize(drizzled::plugin::Registry &registry)
 
164
{
 
165
  registry.remove(information_engine);
 
166
  delete information_engine;
 
167
 
 
168
  InformationShare::stop();
 
169
 
 
170
  return 0;
 
171
}
 
172
 
 
173
drizzle_declare_plugin(information_engine)
 
174
{
 
175
  "INFORMATION_ENGINE",
 
176
  "1.0",
 
177
  "Sun Microsystems ala Brian Aker",
 
178
  "Engine which provides information schema tables",
 
179
  PLUGIN_LICENSE_GPL,
 
180
  init,     /* Plugin Init */
 
181
  finalize,     /* Plugin Deinit */
 
182
  NULL,               /* status variables */
 
183
  NULL,               /* system variables */
 
184
  NULL                /* config options   */
 
185
}
 
186
drizzle_declare_plugin_end;