~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;
2041.3.2 by Brian Aker
Improve on drop schema temp tables.
53
1923.1.2 by Brian Aker
Encapsulate temporary tables.
54
public:
55
56
  Table *getTemporaryTables()
57
  {
58
    return temporary_tables;
59
  }
1046.1.6 by Brian Aker
Formatting/style cleanup.
60
1922.1.1 by Brian Aker
Move temp tables down to open_table class. (first pass)
61
  /**
62
    Mark all temporary tables which were used by the current statement or
63
    substatement as free for reuse, but only if the query_id can be cleared.
64
65
    @param session thread context
66
67
    @remark For temp tables associated with a open SQL HANDLER the query_id
68
            is not reset until the HANDLER is closed.
69
  */
70
  void mark_temp_tables_as_free_for_reuse();
71
72
protected:
73
  void close_temporary_tables();
2041.3.2 by Brian Aker
Improve on drop schema temp tables.
74
1922.1.1 by Brian Aker
Move temp tables down to open_table class. (first pass)
75
public:
76
  void close_temporary_table(Table *table);
2041.3.2 by Brian Aker
Improve on drop schema temp tables.
77
  
78
private:
1922.1.1 by Brian Aker
Move temp tables down to open_table class. (first pass)
79
  // The method below just handles the de-allocation of the table. In
80
  // a better memory type world, this would not be needed.
81
  void nukeTable(Table *table);
2041.3.2 by Brian Aker
Improve on drop schema temp tables.
82
1922.1.1 by Brian Aker
Move temp tables down to open_table class. (first pass)
83
public:
84
  /* Work with temporary tables */
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
85
  Table *find_temporary_table(const identifier::Table &identifier);
1922.1.1 by Brian Aker
Move temp tables down to open_table class. (first pass)
86
87
  void dumpTemporaryTableNames(const char *id);
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
88
  int drop_temporary_table(const drizzled::identifier::Table &identifier);
89
  bool rm_temporary_table(plugin::StorageEngine *base, const identifier::Table &identifier);
90
  bool rm_temporary_table(const drizzled::identifier::Table &identifier, bool best_effort= false);
91
  Table *open_temporary_table(const drizzled::identifier::Table &identifier,
1922.1.1 by Brian Aker
Move temp tables down to open_table class. (first pass)
92
                              bool link_in_list= true);
93
94
  virtual query_id_t getQueryId()  const= 0;
95
1923.1.3 by Brian Aker
Encapsulate derived tables
96
private:
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
97
  Table *derived_tables;
1923.1.3 by Brian Aker
Encapsulate derived tables
98
public:
99
100
101
  Table *getDerivedTables()
102
  {
103
    return derived_tables;
104
  }
105
106
  void setDerivedTables(Table *arg)
107
  {
108
    derived_tables= arg;
109
  }
110
111
  void clearDerivedTables()
112
  {
113
    if (derived_tables)
114
      derived_tables= NULL; // They should all be invalid by this point
115
  }
116
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
117
  /*
118
    During a MySQL session, one can lock tables in two modes: automatic
119
    or manual. In automatic mode all necessary tables are locked just before
120
    statement execution, and all acquired locks are stored in 'lock'
121
    member. Unlocking takes place automatically as well, when the
122
    statement ends.
123
    Manual mode comes into play when a user issues a 'LOCK TABLES'
124
    statement. In this mode the user can only use the locked tables.
125
    Trying to use any other tables will give an error. The locked tables are
126
    stored in 'locked_tables' member.  Manual locking is described in
127
    the 'LOCK_TABLES' chapter of the MySQL manual.
128
    See also lock_tables() for details.
129
  */
1711.6.1 by Brian Aker
Style on structure cleanup
130
  DrizzleLock *lock;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
131
132
  /*
133
    CREATE-SELECT keeps an extra lock for the table being
134
    created. This field is used to keep the extra lock available for
135
    lower level routines, which would otherwise miss that lock.
136
   */
1711.6.1 by Brian Aker
Style on structure cleanup
137
  DrizzleLock *extra_lock;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
138
1223.2.1 by Trond Norbye
Bug #485658: Compile failure on 32 bit system due to mixing ulong, uint64_t and uint32_t
139
  uint64_t version;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
140
  uint32_t current_tablenr;
141
142
  /*
143
    This constructor serves for creation of Open_tables_state instances
144
    which are used as backup storage.
145
  */
1889.1.4 by Brian Aker
C++ warning fixes.
146
  Open_tables_state() :
147
    open_tables(0),
148
    temporary_tables(0),
149
    derived_tables(0),
150
    lock(0),
151
    extra_lock(0),
152
    version(0),
153
    current_tablenr(0)
154
  { }
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
155
  virtual ~Open_tables_state() {}
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
156
1923.1.2 by Brian Aker
Encapsulate temporary tables.
157
  void doGetTableNames(CachedDirectory &directory,
2087.4.1 by Brian Aker
Merge in schema identifier.
158
                       const identifier::Schema &schema_identifier,
1923.1.2 by Brian Aker
Encapsulate temporary tables.
159
                       std::set<std::string>& set_of_names);
2087.4.1 by Brian Aker
Merge in schema identifier.
160
  void doGetTableNames(const identifier::Schema &schema_identifier,
1923.1.2 by Brian Aker
Encapsulate temporary tables.
161
                       std::set<std::string>& set_of_names);
162
163
  void doGetTableIdentifiers(CachedDirectory &directory,
2087.4.1 by Brian Aker
Merge in schema identifier.
164
                             const identifier::Schema &schema_identifier,
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
165
                             identifier::Table::vector &set_of_identifiers);
2087.4.1 by Brian Aker
Merge in schema identifier.
166
  void doGetTableIdentifiers(const identifier::Schema &schema_identifier,
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
167
                             identifier::Table::vector &set_of_identifiers);
1923.1.2 by Brian Aker
Encapsulate temporary tables.
168
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
169
  int doGetTableDefinition(const drizzled::identifier::Table &identifier,
1923.1.2 by Brian Aker
Encapsulate temporary tables.
170
                           message::Table &table_proto);
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
171
  bool doDoesTableExist(const drizzled::identifier::Table &identifier);
1923.1.2 by Brian Aker
Encapsulate temporary tables.
172
173
1223.2.1 by Trond Norbye
Bug #485658: Compile failure on 32 bit system due to mixing ulong, uint64_t and uint32_t
174
  Open_tables_state(uint64_t version_arg);
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
175
};
176
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
177
} /* namespace drizzled */
178
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
179
#endif /* DRIZZLED_OPEN_TABLES_STATE_H */