~drizzle-trunk/drizzle/development

851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
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; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
20
21
#ifndef DRIZZLED_OPEN_TABLES_STATE_H
22
#define DRIZZLED_OPEN_TABLES_STATE_H
23
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
24
#include "drizzled/lock.h"
25
26
namespace drizzled
27
{
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
28
29
/**
30
  Class that holds information about tables which were opened and locked
31
  by the thread. It is also used to save/restore this information in
32
  push_open_tables_state()/pop_open_tables_state().
33
*/
34
35
class Open_tables_state
36
{
37
public:
38
  /**
39
    List of regular tables in use by this thread. Contains temporary and
40
    base tables that were opened with @see open_tables().
41
  */
42
  Table *open_tables;
1877.2.16 by Brian Aker
Fix dangling headers.
43
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
44
  /**
45
    List of temporary tables used by this thread. Contains user-level
46
    temporary tables, created with CREATE TEMPORARY TABLE, and
47
    internal temporary tables, created, e.g., to resolve a SELECT,
48
    or for an intermediate table used in ALTER.
49
    XXX Why are internal temporary tables added to this list?
50
  */
1923.1.2 by Brian Aker
Encapsulate temporary tables.
51
private:
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
52
  Table *temporary_tables;
1923.1.2 by Brian Aker
Encapsulate temporary tables.
53
public:
54
55
  Table *getTemporaryTables()
56
  {
57
    return temporary_tables;
58
  }
1046.1.6 by Brian Aker
Formatting/style cleanup.
59
1922.1.1 by Brian Aker
Move temp tables down to open_table class. (first pass)
60
  /**
61
    Mark all temporary tables which were used by the current statement or
62
    substatement as free for reuse, but only if the query_id can be cleared.
63
64
    @param session thread context
65
66
    @remark For temp tables associated with a open SQL HANDLER the query_id
67
            is not reset until the HANDLER is closed.
68
  */
69
  void mark_temp_tables_as_free_for_reuse();
70
71
protected:
72
  void close_temporary_tables();
73
public:
74
  void close_temporary_table(Table *table);
75
  // The method below just handles the de-allocation of the table. In
76
  // a better memory type world, this would not be needed.
77
private:
78
  void nukeTable(Table *table);
79
public:
80
81
  /* Work with temporary tables */
82
  Table *find_temporary_table(const TableIdentifier &identifier);
83
84
  void dumpTemporaryTableNames(const char *id);
85
  int drop_temporary_table(const drizzled::TableIdentifier &identifier);
1954.2.3 by Brian Aker
Update tableidentifier so that it is const in many callers.
86
  bool rm_temporary_table(plugin::StorageEngine *base, const TableIdentifier &identifier);
87
  bool rm_temporary_table(const drizzled::TableIdentifier &identifier, bool best_effort= false);
88
  Table *open_temporary_table(const drizzled::TableIdentifier &identifier,
1922.1.1 by Brian Aker
Move temp tables down to open_table class. (first pass)
89
                              bool link_in_list= true);
90
91
  virtual query_id_t getQueryId()  const= 0;
92
1923.1.3 by Brian Aker
Encapsulate derived tables
93
private:
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
94
  Table *derived_tables;
1923.1.3 by Brian Aker
Encapsulate derived tables
95
public:
96
97
98
  Table *getDerivedTables()
99
  {
100
    return derived_tables;
101
  }
102
103
  void setDerivedTables(Table *arg)
104
  {
105
    derived_tables= arg;
106
  }
107
108
  void clearDerivedTables()
109
  {
110
    if (derived_tables)
111
      derived_tables= NULL; // They should all be invalid by this point
112
  }
113
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
114
  /*
115
    During a MySQL session, one can lock tables in two modes: automatic
116
    or manual. In automatic mode all necessary tables are locked just before
117
    statement execution, and all acquired locks are stored in 'lock'
118
    member. Unlocking takes place automatically as well, when the
119
    statement ends.
120
    Manual mode comes into play when a user issues a 'LOCK TABLES'
121
    statement. In this mode the user can only use the locked tables.
122
    Trying to use any other tables will give an error. The locked tables are
123
    stored in 'locked_tables' member.  Manual locking is described in
124
    the 'LOCK_TABLES' chapter of the MySQL manual.
125
    See also lock_tables() for details.
126
  */
1711.6.1 by Brian Aker
Style on structure cleanup
127
  DrizzleLock *lock;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
128
129
  /*
130
    CREATE-SELECT keeps an extra lock for the table being
131
    created. This field is used to keep the extra lock available for
132
    lower level routines, which would otherwise miss that lock.
133
   */
1711.6.1 by Brian Aker
Style on structure cleanup
134
  DrizzleLock *extra_lock;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
135
1223.2.1 by Trond Norbye
Bug #485658: Compile failure on 32 bit system due to mixing ulong, uint64_t and uint32_t
136
  uint64_t version;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
137
  uint32_t current_tablenr;
138
139
  /*
140
    This constructor serves for creation of Open_tables_state instances
141
    which are used as backup storage.
142
  */
1889.1.4 by Brian Aker
C++ warning fixes.
143
  Open_tables_state() :
144
    open_tables(0),
145
    temporary_tables(0),
146
    derived_tables(0),
147
    lock(0),
148
    extra_lock(0),
149
    version(0),
150
    current_tablenr(0)
151
  { }
1240.9.4 by Monty Taylor
destructor for base class "Open_tables_state" (declared at line 31 of "../drizzled/open_tables_state.h") is not virtual
152
  virtual ~Open_tables_state() {}
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
153
1923.1.2 by Brian Aker
Encapsulate temporary tables.
154
  void doGetTableNames(CachedDirectory &directory,
155
                       const SchemaIdentifier &schema_identifier,
156
                       std::set<std::string>& set_of_names);
157
  void doGetTableNames(const SchemaIdentifier &schema_identifier,
158
                       std::set<std::string>& set_of_names);
159
160
  void doGetTableIdentifiers(CachedDirectory &directory,
161
                             const SchemaIdentifier &schema_identifier,
1966.2.4 by Brian Aker
Style cleanup.
162
                             TableIdentifier::vector &set_of_identifiers);
1923.1.2 by Brian Aker
Encapsulate temporary tables.
163
  void doGetTableIdentifiers(const SchemaIdentifier &schema_identifier,
1966.2.4 by Brian Aker
Style cleanup.
164
                             TableIdentifier::vector &set_of_identifiers);
1923.1.2 by Brian Aker
Encapsulate temporary tables.
165
166
  int doGetTableDefinition(const drizzled::TableIdentifier &identifier,
167
                           message::Table &table_proto);
168
  bool doDoesTableExist(const drizzled::TableIdentifier &identifier);
169
170
1223.2.1 by Trond Norbye
Bug #485658: Compile failure on 32 bit system due to mixing ulong, uint64_t and uint32_t
171
  Open_tables_state(uint64_t version_arg);
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
172
};
173
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
174
} /* namespace drizzled */
175
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
176
#endif /* DRIZZLED_OPEN_TABLES_STATE_H */